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

filter: Statementstmt 0.0% 0 / 7144 Branchbran 0.0% 0 / 3256 Conditioncond 0.0% 0 / 2955 MC/DCmcdc 0.0% 0 / 1498 Subroutinesub 0.0% 0 / 643 Podpod 0.0% 0 / 574 totaltotal 0.0% 0 / 16070 CC 1629 SCAR 53.4
CC
1629
Cov
0%
modifyInterface
1892.0
setProfile
1406.0
addInterface
1406.0
CRAP 208.1
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::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 -s pattern -p instruction'
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 -s pattern -p instruction'
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 # Check that the specified interface exists
4509 if (
4510 ! $session->ivExists('interfaceHash', $interface)
4511 && ! $session->ivExists('interfaceNumHash', $interface)
4512 ) {
4513 return $self->error(
4514 $session, $inputString,
4515 'Unrecognised active ' . $category . ' interface \'' . $interface . '\'',
4516 );
4517 }
4518  
4519 # If $interface is a number, convert it into an interface name
4520 if ($session->ivExists('interfaceNumHash', $interface)) {
4521  
4522 $interface = $session->ivShow('interfaceNumHash', $interface)->name;
4523 }
4524  
4525 $interfaceObj = $session->ivShow('interfaceHash', $interface);
4526  
4527 # Modify the interface
4528 $result = $interfaceObj->modifyAttribs($session, %attribHash);
4529 if (! $result) {
4530  
4531 return $self->error(
4532 $session, $inputString,
4533 'General error modifying active ' . $category . ' interface \''
4534 . $interface . '\'',
4535 );
4536  
4537 } else {
4538  
4539 return $self->complete(
4540 $session, $standardCmd,
4541 'Active ' . $category . ' interface \'' . $interface . '\' modified (but'
4542 . ' the corresponding cage interface, if any, was not modified)',
4543 );
4544 }
4545  
4546 # Otherwise, if a group 1 switch was specified, modify the specified interface stored in the
4547 # cage. If there's a corresponding active interface, modify that, too
4548 } else {
4549  
4550 # 0 or 1 associated profiles can be specified, but no more
4551 if ($profCount > 1) {
4552  
4553 return $self->error(
4554 $session, $inputString,
4555 'Can\'t modify an interface associated with multiple profiles - choose one from'
4556 . ' -w, -g, -r, -c, -x, -d (or a named profile)',
4557 );
4558  
4559 # If no associated profile specified, and the -i switch wasn't used, use the current
4560 # world as the associated profile
4561 } elsif ($profCount == 0) {
4562  
4563 $profCount++;
4564 $profCategory = 'world';
4565 $profName = $session->currentWorld->name;
4566 }
4567  
4568 # @args should now contain a single element, <name>. Check it exists
4569 if (@args > 1) {
4570  
4571 return $self->improper($session, $inputString);
4572  
4573 } elsif (! @args) {
4574  
4575 return $self->error(
4576 $session, $inputString,
4577 'Please specify the name of the ' . $category . ' interface to modify (or'
4578 . ' use \'-i <name>\' or \'-i <number>\'',
4579 );
4580  
4581 } else {
4582  
4583 $currentObjName = $args[0];
4584 }
4585  
4586 # Find the cage matching the specified profile
4587 $cage = $session->findCage($category, $profName);
4588 if (! $cage) {
4589  
4590 return $self->error(
4591 $inputString,
4592 'Can\'t modify ' . $category . ' interface because the ' . $category
4593 . ' cage for \'' . $profName . '\' is missing',
4594 );
4595 }
4596  
4597 # Check that the cage has a trigger with this name
4598 if (! $cage->ivExists('interfaceHash', $currentObjName)) {
4599  
4600 if ($category eq 'alias') {
4601  
4602 return $self->error(
4603 $session, $inputString,
4604 'Can\'t modify alias interface because the alias cage doesn\'t'
4605 . 'have an alias with the name \'' . $currentObjName
4606 . '\'',
4607 );
4608  
4609 } else {
4610  
4611 return $self->error(
4612 $session, $inputString,
4613 'Can\'t modify ' . $category . ' interface because the ' . $category
4614 . ' cage doesn\'t have a ' . $category . ' with the name \''
4615 . $currentObjName .'\'',
4616 );
4617 }
4618  
4619 } else {
4620  
4621 # Get the blessed reference of the trigger object (but don't consult inferior cages)
4622 $currentObj = $cage->ivShow('interfaceHash', $currentObjName);
4623 if (! $currentObj) {
4624  
4625 return $self->error(
4626 $session, $inputString,
4627 'General error modifying the ' . $category . ' interface object \''
4628 . $currentObjName . '\'',
4629 );
4630 }
4631 }
4632  
4633 # Modify any of the attributes that were specified
4634 if (%attribHash) {
4635  
4636 $result = $currentObj->modifyAttribs($session, %attribHash);
4637 if (! $result) {
4638  
4639 return $self->complete(
4640 $session, $inputString,
4641 'Failed to modify the ' . $category . ' interface \''
4642 . $currentObj->name . '\'',
4643 );
4644 }
4645 }
4646  
4647 # Modify the before/after hashes, if specified
4648 if (%beforeHash || %afterHash || %beforeRemoveHash || %afterRemoveHash) {
4649  
4650 $result = $currentObj->set_beforeAfterHashes(
4651 $session,
4652 \%beforeHash, \%afterHash,
4653 \%beforeRemoveHash, \%afterRemoveHash,
4654 );
4655  
4656 if (! $result) {
4657  
4658 return $self->error(
4659 $session, $inputString,
4660 'Failed to modify the ' . $category . ' interface \''
4661 . $currentObj->name . '\'',
4662 );
4663 }
4664 }
4665  
4666 # If there's an active interface based upon this interface object, we need to update the
4667 # active interface, too. We must do this in every session that shares the same world
4668  
4669 # Do the update in every affected session, except this one
4670 foreach my $otherSession ($axmud::CLIENT->listSessions()) {
4671  
4672 if (
4673 $otherSession->currentWorld eq $session->currentWorld
4674 && $otherSession ne $self
4675 ) {
4676 $otherSession->updateInterfaces($currentObj, %attribHash);
4677 }
4678 }
4679  
4680 # Now apply to this session
4681 if (! $session->updateInterfaces($currentObj, %attribHash)) {
4682  
4683 return $self->complete(
4684 $session, $standardCmd,
4685 ucfirst($category) . ' interface \'' . $currentObj->name . '\' modified, but'
4686 . ' but general error while modifying the corresponding active interface(s)',
4687 );
4688  
4689 } else {
4690  
4691 # There is no active interface based on this trigger (etc)
4692 return $self->complete(
4693 $session, $standardCmd,
4694 'Inactive ' . $category . ' interface \'' . $currentObjName . '\' modified',
4695 );
4696 }
4697 }
4698 }
4699  
4700 sub exportInterface {
4701  
4702 # Called by GA::Cmd::ExportTrigger->do, ExportAlias->do, ExportMacro->do,
4703 # ExportTimer->do and ExportHook->do
4704 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
4705 # 'macro', 'timer' or 'hook')
4706 #
4707 # This function adds an inactive trigger, stored in a trigger cage, to Axmud's interface
4708 # clipboard, from where it can 'imported' to a different cage (perhaps in a different
4709 # world, in a different session)
4710 # This function can also be called to export an active interface directly, without
4711 # exporting the corresponding inactive trigger stored in a trigger cage (if any)
4712 #
4713 # Expected arguments
4714 # $session - The calling function's GA::Session
4715 # $inputString - The command actually typed, e.g. 'etr mytrigger'
4716 # $standardCmd - Standard version of the client command, e.g. 'exporttrigger'
4717 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
4718 # $categoryPlural - e.g. 'triggers'
4719 # $modelObj - The interface model object corresponding to $category
4720 # @args - The arguments specified by the user in the ';exporttrigger' command
4721 #
4722 # Return values
4723 # 'undef' on improper arguments or if there's an error
4724 # 1 on success
4725  
4726 my (
4727 $self, $session, $inputString, $standardCmd, $category, $categoryPlural, $modelObj,
4728 @args,
4729 ) = @_;
4730  
4731 # Local variables
4732 my (
4733 $profCount, $profCategory, $profName, $switch, $interface, $interfaceObj,
4734 $currentObjName, $cage, $currentObj,
4735 );
4736  
4737 # Check for improper arguments
4738 if (
4739 ! defined $session || ! defined $inputString || ! defined $standardCmd
4740 || ! defined $category || ! defined $categoryPlural || ! defined $modelObj || ! @args
4741 ) {
4742 return $axmud::CLIENT->writeImproper($self->_objClass . '->exportInterface', @_);
4743 }
4744  
4745 # Extract profile (group 1) switch options
4746 ($profCount, $profCategory, $profName, @args) = $self->extractProfileSwitches(
4747 $session,
4748 $inputString,
4749 $category,
4750 'export',
4751 @args,
4752 );
4753  
4754 if (! defined $profCount) {
4755  
4756 # Error in ->extractProfileSwitches - error message already displayed
4757 return undef;
4758 }
4759  
4760 # Extract active interface (group 0) switch options
4761 ($switch, $interface, @args) = $self->extract('i', 1, @args);
4762 if (defined $switch) {
4763  
4764 if (! defined $interface) {
4765  
4766 return $self->error(
4767 $session, $inputString,
4768 'Missing switch arguments - use \'-i <name>\' or \'-i <number>\'',
4769 );
4770 }
4771 }
4772  
4773 # Now, if the group 0 '-i' switch was specified, export the active interface
4774 if (defined $interface) {
4775  
4776 # @args should now be empty. If not, return an error message
4777 if (@args) {
4778  
4779 return $self->improper($session, $inputString);
4780 }
4781  
4782 # Group 0 and 1 switches can't be combined
4783 if ($profCount) {
4784  
4785 return $self->error(
4786 $session, $inputString,
4787 'Can\'t export active ' . $category . ' interface - can\'t combine the -i'
4788 . ' switch with -w, -g, -r, -c, -x or -d',
4789 );
4790 }
4791  
4792 # Check that the specified interface exists
4793 if (
4794 ! $session->ivExists('interfaceHash', $interface)
4795 && ! $session->ivExists('interfaceNumHash', $interface)
4796 ) {
4797 return $self->error(
4798 $session, $inputString,
4799 'Unrecognised active ' . $category . ' interface \'' . $interface . '\'',
4800 );
4801 }
4802  
4803 # If $interface is a number, convert it into an interface name
4804 if ($session->ivExists('interfaceNumHash', $interface)) {
4805  
4806 $interface = $session->ivShow('interfaceNumHash', $interface)->name;
4807 }
4808  
4809 $interfaceObj = $session->ivShow('interfaceHash', $interface);
4810  
4811 # Export the interface
4812 $axmud::CLIENT->add_interfaceClipboardList($interfaceObj);
4813  
4814 return $self->complete(
4815 $session, $standardCmd,
4816 'Active ' . $category . ' interface \'' . $interface . '\' exported to the'
4817 . ' interface clipboard',
4818 );
4819  
4820 # Otherwise, if a group 1 switch was specified, export the specified interface stored in the
4821 # cage
4822 } else {
4823  
4824 # 0 or 1 associated profiles can be specified, but no more
4825 if ($profCount > 1) {
4826  
4827 return $self->error(
4828 $session, $inputString,
4829 'Can\'t export an interface from multiple profiles - choose one from'
4830 . ' -w, -g, -r, -c, -x, -d (or a named profile)',
4831 );
4832  
4833 # If no associated profile specified, and the -i switch wasn't used, use the current
4834 # world as the associated profile
4835 } elsif ($profCount == 0) {
4836  
4837 $profCount++;
4838 $profCategory = 'world';
4839 $profName = $session->currentWorld->name;
4840 }
4841  
4842 # @args should now contain a single element, <name>. Check it exists
4843 if (@args > 1) {
4844  
4845 return $self->improper($session, $inputString);
4846  
4847 } elsif (! @args) {
4848  
4849 return $self->error(
4850 $session, $inputString,
4851 'Please specify the name of the ' . $category . ' interface to export (or'
4852 . ' use \'-i <name>\' or \'-i <number>\'',
4853 );
4854  
4855 } else {
4856  
4857 $currentObjName = $args[0];
4858 }
4859  
4860 # Find the cage matching the specified profile
4861 $cage = $session->findCage($category, $profName);
4862 if (! $cage) {
4863  
4864 return $self->error(
4865 $inputString,
4866 'Can\'t export ' . $category . ' interface because the ' . $category
4867 . ' cage for \'' . $profName . '\' is missing',
4868 );
4869 }
4870  
4871 # Check that the cage has a trigger with this name
4872 if (! $cage->ivExists('interfaceHash', $currentObjName)) {
4873  
4874 if ($category eq 'alias') {
4875  
4876 return $self->error(
4877 $session, $inputString,
4878 'Can\'t export alias interface because the alias cage doesn\'t'
4879 . 'have an alias with the name \'' . $currentObjName
4880 . '\'',
4881 );
4882  
4883 } else {
4884  
4885 return $self->error(
4886 $session, $inputString,
4887 'Can\'t export ' . $category . ' interface because the ' . $category
4888 . ' cage doesn\'t have a ' . $category . ' with the name \''
4889 . $currentObjName .'\'',
4890 );
4891 }
4892  
4893 } else {
4894  
4895 # Get the blessed reference of the trigger object (but don't consult inferior cages)
4896 $currentObj = $cage->ivShow('interfaceHash', $currentObjName);
4897 if (! $currentObj) {
4898  
4899 return $self->error(
4900 $session, $inputString,
4901 'General error exporting the ' . $category . ' interface object \''
4902 . $currentObjName . '\'',
4903 );
4904 }
4905 }
4906  
4907 # Export the interface
4908 $axmud::CLIENT->add_interfaceClipboardList($currentObj);
4909  
4910 return $self->complete(
4911 $session, $standardCmd,
4912 'Inactive ' . $category . ' interface \'' . $currentObjName . '\' exported to the'
4913 . ' interface clipboard',
4914 );
4915 }
4916 }
4917  
4918 sub importInterface {
4919  
4920 # Called by GA::Cmd::ImportTrigger->do, ImportAlias->do, ImportMacro->do,
4921 # ImportTimer->do and ImportHook->do
4922 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
4923 # 'macro', 'timer' or 'hook')
4924 #
4925 # This function clones all triggers in Axmud's interface clipboard, moving the copies into
4926 # the specified cage.
4927 #
4928 # Expected arguments
4929 # $session - The calling function's GA::Session
4930 # $inputString - The command actually typed, e.g. 'itr mytrigger'
4931 # $standardCmd - Standard version of the client command, e.g. 'importtrigger'
4932 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
4933 # $categoryPlural - e.g. 'triggers'
4934 # $modelObj - The interface model object corresponding to $category
4935 #
4936 # Optional arguments
4937 # @args - The arguments specified by the user in the ';importtrigger' command
4938 #
4939 # Return values
4940 # 'undef' on improper arguments or if there's an error
4941 # 1 on success
4942  
4943 my (
4944 $self, $session, $inputString, $standardCmd, $category, $categoryPlural, $modelObj,
4945 @args,
4946 ) = @_;
4947  
4948 # Local variables
4949 my (
4950 $profCount, $profCategory, $profName, $cage, $failCount, $successCount, $newObj,
4951 $result,
4952 @interfaceList, @superiorList, @inferiorList,
4953 );
4954  
4955 # Check for improper arguments
4956 if (
4957 ! defined $session || ! defined $inputString || ! defined $standardCmd
4958 || ! defined $category || ! defined $categoryPlural || ! defined $modelObj
4959 ) {
4960 return $axmud::CLIENT->writeImproper($self->_objClass . '->importInterface', @_);
4961 }
4962  
4963 # Extract profile (group 1) switch options
4964 ($profCount, $profCategory, $profName, @args) = $self->extractProfileSwitches(
4965 $session,
4966 $inputString,
4967 $category,
4968 'import',
4969 @args,
4970 );
4971  
4972 if (! defined $profCount) {
4973  
4974 # Error in ->extractProfileSwitches - error message already displayed
4975 return undef;
4976 }
4977  
4978 # 0 or 1 associated profiles can be specified, but no more
4979 if ($profCount > 1) {
4980  
4981 return $self->error(
4982 $session, $inputString,
4983 'Can\'t import an interface to multiple profiles - choose one from'
4984 . ' -w, -g, -r, -c, -x, -d (or a named profile)',
4985 );
4986  
4987 # If no associated profile specified, and the -i switch wasn't used, use the current
4988 # world as the associated profile
4989 } elsif ($profCount == 0) {
4990  
4991 $profCount++;
4992 $profCategory = 'world';
4993 $profName = $session->currentWorld->name;
4994 }
4995  
4996 # @args should now contain 0 or 1 arguments
4997 if (! @args) {
4998  
4999 @interfaceList = $axmud::CLIENT->interfaceClipboardList;
5000  
5001 } elsif (@args > 1) {
5002  
5003 return $self->improper($session, $inputString);
5004  
5005 } else {
5006  
5007 # Find all matching named interfaces
5008 foreach my $interfaceObj ($axmud::CLIENT->interfaceClipboardList) {
5009  
5010 if ($interfaceObj->name eq $args[0]) {
5011  
5012 push (@interfaceList, $interfaceObj);
5013 }
5014 }
5015  
5016 if (! @interfaceList) {
5017  
5018 return $self->error(
5019 $inputString,
5020 'No interface named \'' . $args[0] . '\' found in the interface clipboard',
5021 );
5022 }
5023 }
5024  
5025 # Find the cage matching the specified profile
5026 $cage = $session->findCage($category, $profName);
5027 if (! $cage) {
5028  
5029 return $self->error(
5030 $inputString,
5031 'Can\'t import ' . $category . ' interface because the ' . $category
5032 . ' cage for \'' . $profName . '\' is missing',
5033 );
5034 }
5035  
5036 # Handle each interface in turn
5037 $failCount = 0;
5038 $successCount = 0;
5039 OUTER: foreach my $interfaceObj (@interfaceList) {
5040  
5041 # Ignore any interfaces of the wrong category (e.g. just import triggers, etc)
5042 if ($interfaceObj->category ne $category) {
5043  
5044 next OUTER;
5045 }
5046  
5047 # Check that the cage doesn't already have a trigger with the same name
5048 if ($cage->ivExists('interfaceHash', $interfaceObj->name)) {
5049  
5050 $failCount++;
5051 next OUTER;
5052 }
5053  
5054 # Clone the interface
5055 if ($interfaceObj->isa('Games::Axmud::Interface::Active')) {
5056 $newObj = $interfaceObj->cloneToInactiveInterface($category);
5057 } else {
5058 $newObj = $interfaceObj->clone($profName);
5059 }
5060  
5061 if (! $newObj) {
5062  
5063 $failCount++;
5064 next OUTER;
5065 }
5066  
5067 # Tell the trigger cage that it has received a new trigger
5068 $cage->ivAdd('interfaceHash', $newObj->name, $newObj);
5069  
5070 # Get a list of profiles with higher priority than this one
5071 @superiorList = $session->findSuperiorList($profCategory);
5072 # Get a list of profiles with lower priority than this one
5073 @inferiorList = $session->findInferiorList($profCategory);
5074  
5075 # Check whether there are any triggers with the same name, belonging to a cage
5076 # associated with a superior profile to this cage's profile. If none, create an
5077 # interface for the trigger
5078 # Also, if there is a trigger, with the same name but belonging to a cage associated
5079 # with an inferior profile to this cage's profile, destroy its interface
5080 # As a result, there should be exactly one interface for a trigger with this name, no
5081 # matter how many triggers with that name exist
5082 $result = $session->injectInterface(
5083 $newObj,
5084 $newObj->name,
5085 $profName,
5086 \@superiorList,
5087 \@inferiorList,
5088 );
5089 if (! defined $result) {
5090 $failCount++;
5091 } else {
5092 $successCount++;
5093 }
5094 }
5095  
5096 return $self->complete(
5097 $session, $standardCmd,
5098 'Import complete, ' . $categoryPlural . ' imported: ' . $successCount . ', failures: '
5099 . $failCount,
5100 );
5101 }
5102  
5103 sub deleteInterface {
5104  
5105 # Called by GA::Cmd::DeleteTrigger->do, DeleteAlias->do, DeleteMacro->do,
5106 # DeleteTimer->do and DeleteHook->do
5107 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
5108 # 'macro', 'timer' or 'hook')
5109 #
5110 # This function deletes an independent trigger stored in a trigger cage. If there's a
5111 # corresponding active interface, it is also deleted
5112 #
5113 # This function can also be called to delete an active interface directly, without
5114 # deleting the corresponding independent trigger stored in a trigger cage (if any)
5115 #
5116 # Expected arguments
5117 # $session - The calling function's GA::Session
5118 # $inputString - The command actually typed, e.g. 'dtr mytrig'
5119 # $standardCmd - Standard version of the client command, e.g. 'deletetrigger'
5120 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
5121 # $categoryPlural - e.g. 'triggers'
5122 # @args - The arguments specified by the user in the ';deletetrigger' command
5123 #
5124 # Return values
5125 # 'undef' on improper arguments or if there's an error
5126 # 1 on success
5127  
5128 my (
5129 $self, $session, $inputString, $standardCmd, $category, $categoryPlural,
5130 @args,
5131 ) = @_;
5132  
5133 # Local variables
5134 my (
5135 $profCount, $profCategory, $profName, $currentObj, $currentObjName, $cage, $result,
5136 @inferiorList
5137 );
5138  
5139 # Check for improper arguments
5140 if (
5141 ! defined $session || ! defined $inputString || ! defined $standardCmd
5142 || ! defined $category || ! defined $categoryPlural || ! @args
5143 ) {
5144 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteInterface', @_);
5145 }
5146  
5147 # Extract profile (group 1) switch option
5148 ($profCount, $profCategory, $profName, @args) = $self->extractProfileSwitches(
5149 $session,
5150 $inputString,
5151 $category,
5152 'delete',
5153 @args,
5154 );
5155  
5156 if (! defined $profCount) {
5157  
5158 # Error in ->extractProfileSwitches()
5159 return undef;
5160  
5161 # 0 or 1 associated profiles can be specified, but no more
5162 } elsif ($profCount > 1) {
5163  
5164 return $self->error(
5165 $session, $inputString,
5166 'Can\'t delete an interface associated with multiple profiles - choose one from'
5167 . ' -w, -g, -r, -c, -x, -d (or a named profile)',
5168 );
5169  
5170 # If no associated profile specified, use the current world as the associated profile
5171 } elsif ($profCount == 0) {
5172  
5173 $profCount++;
5174 $profCategory = 'world';
5175 $profName = $session->currentWorld->name;
5176 }
5177  
5178 # @args should now contain a single element, <name>. Check it exists
5179 if (@args > 1) {
5180  
5181 return $self->improper($session, $inputString);
5182  
5183 } elsif (! @args) {
5184  
5185 return $self->error(
5186 $session, $inputString,
5187 'Please specify the name of the ' . $category . ' interface to delete',
5188 );
5189  
5190 } else {
5191  
5192 $currentObjName = $args[0];
5193 }
5194  
5195 # Find the cage matching the specified profile
5196 $cage = $session->findCage($category, $profName);
5197 if (! $cage) {
5198  
5199 return $self->error(
5200 $inputString,
5201 'Can\'t delete ' . $category . ' interface because the ' . $category
5202 . ' cage for \'' . $profName . '\' is missing',
5203 );
5204 }
5205  
5206 # Check that the cage has a trigger with this name
5207 if (! $cage->ivExists('interfaceHash', $currentObjName)) {
5208  
5209 if ($category eq 'alias') {
5210  
5211 return $self->error(
5212 $session, $inputString,
5213 'Can\'t delete alias interface because the alias cage doesn\'t have an alias'
5214 . ' with the name \'' . $currentObjName . '\'',
5215 );
5216  
5217 } else {
5218  
5219 return $self->error(
5220 $session, $inputString,
5221 'Can\'t delete ' . $category . ' interface because the ' . $category
5222 . ' cage doesn\'t have a ' . $category . ' with the name \'' . $currentObjName
5223 . '\'',
5224 );
5225 }
5226  
5227 } else {
5228  
5229 # Get the blessed reference of the trigger object (but don't consult inferior cages)
5230 $currentObj = $cage->ivShow('interfaceHash', $currentObjName);
5231 if (! $currentObj) {
5232  
5233 return $self->error(
5234 $session, $inputString,
5235 'General error deleting the ' . $category . ' interface object \''
5236 . $currentObjName . '\'',
5237 );
5238 }
5239 }
5240  
5241 # Delete the interface object
5242 $cage->ivDelete('interfaceHash', $currentObjName);
5243  
5244 # Get a list of profiles with lower priority than this one
5245 @inferiorList = $session->findInferiorList($profCategory);
5246  
5247 # If there's an active interface based on this trigger object, delete it also. At the
5248 # same time, if there's a trigger with the same name, belonging to an inferior
5249 # cage, create an interface for it to make it active
5250 $result = $session->recallInterface($currentObj, $currentObjName, \@inferiorList);
5251  
5252 if (! $result || $result == 1) {
5253  
5254 return $self->error(
5255 $session, $inputString,
5256 'General error deleting ' . $category . ' interface',
5257 );
5258  
5259 } elsif ($result == 2) {
5260  
5261 return $self->error(
5262 $session, $inputString,
5263 'Deleted ' . $category . ' interface, but couldn\'t create interface for a '
5264 . $category . ' belonging to an inferior profile',
5265 );
5266  
5267 } elsif ($result == 3) {
5268  
5269 return $self->complete(
5270 $session, $standardCmd,
5271 'Active ' . $category . ' interface \'' . $currentObjName . '\' deleted and'
5272 . ' interface created for a ' . $category . ' belonging to an inferior profile',
5273 );
5274  
5275 } elsif ($result == 4) {
5276  
5277 return $self->complete(
5278 $session, $standardCmd,
5279 'Active ' . $category . ' interface \'' . $currentObjName . '\' deleted (and'
5280 . ' no other interface created to replace it)',
5281 );
5282 }
5283 }
5284  
5285 sub listInterface {
5286  
5287 # Called by GA::Cmd::ListTrigger->do, ListAlias->do, ListMacro->do, ListTimer->do and
5288 # ListHook->do
5289 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
5290 # 'macro', 'timer' or 'hook')
5291 #
5292 # Lists triggers stored in a trigger cage, or lists active triggers
5293 #
5294 # Expected arguments
5295 # $session - The calling function's GA::Session
5296 # $inputString - The command actually typed, e.g. 'ltr -w'
5297 # $standardCmd - Standard version of the client command, e.g. 'listtrigger'
5298 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
5299 # $categoryPlural - e.g. 'triggers'
5300 #
5301 # Optional arguments
5302 # @args - The arguments specified by the user in the ';listtrigger' command
5303 # (an empty list if none specified)
5304 #
5305 # Return values
5306 # 'undef' on improper arguments or if there's an error
5307 # 1 on success
5308  
5309 my (
5310 $self, $session, $inputString, $standardCmd, $category, $categoryPlural,
5311 @args,
5312 ) = @_;
5313  
5314 # Local variables
5315 my (
5316 $switch, $arg, $profObj, $owner, $cage, $string,
5317 @list,
5318 %hash, %modifiedHash,
5319 );
5320  
5321 # Check for improper arguments
5322 if (
5323 ! defined $session || ! defined $inputString || ! defined $standardCmd
5324 || ! defined $category || ! defined $categoryPlural
5325 ) {
5326 return $axmud::CLIENT->writeImproper($self->_objClass . '->listInterface', @_);
5327 }
5328  
5329 # Extract the optional switch and argument
5330 $switch = shift @args;
5331 $arg = shift @args;
5332 # There should be no arguments left
5333 if (
5334 @args
5335 || (
5336 defined $switch && $switch ne '-w' && $switch ne '-g' && $switch ne '-r'
5337 && $switch ne '-c' && $switch ne '-x' && $switch ne '-d' && $switch ne '-i'
5338 )
5339 ) {
5340 return $self->improper($session, $inputString);
5341 }
5342  
5343 # ;ltr
5344 # ;ltr -w , ;ltr -g , ;ltr -r , ;ltr -c
5345 # ;ltr -x <category>
5346 # ;ltr -d <profile>
5347 # (etc)
5348 if (! defined $switch || $switch ne '-i') {
5349  
5350 # ;ltr
5351 # ;ltr -w
5352 if (! $switch || $switch eq '-w') {
5353  
5354 $owner = $session->currentWorld->name;
5355 $cage = $session->findCurrentCage($category, 'world');
5356  
5357 } elsif ($switch eq '-g') {
5358  
5359 if (! defined $session->currentGuild) {
5360  
5361 return $self->error(
5362 $session, $inputString,
5363 'Can\'t list ' . $categoryPlural . ' for the current guild - no current'
5364 . ' guild set',
5365 );
5366  
5367 } else {
5368  
5369 $owner = $session->currentGuild->name;
5370 $cage = $session->findCurrentCage($category, 'guild');
5371 }
5372  
5373 } elsif ($switch eq '-r') {
5374  
5375 if (! defined $session->currentRace) {
5376  
5377 return $self->error(
5378 $session, $inputString,
5379 'Can\'t list ' . $categoryPlural . ' for the current race - no current'
5380 . ' race set',
5381 );
5382  
5383 } else {
5384  
5385 $owner = $session->currentRace->name;
5386 $cage = $session->findCurrentCage($category, 'race');
5387 }
5388  
5389 } elsif ($switch eq '-c') {
5390  
5391 if (! defined $session->currentChar) {
5392  
5393 return $self->error(
5394 $session, $inputString,
5395 'Can\'t list ' . $categoryPlural . ' for the current character - no current'
5396 . ' character set',
5397 );
5398  
5399 } else {
5400  
5401 $owner = $session->currentChar->name;
5402 $cage = $session->findCurrentCage($category, 'char');
5403 }
5404  
5405 } elsif ($switch eq '-x') {
5406  
5407 if (! defined $arg) {
5408  
5409 return $self->error(
5410 $session, $inputString,
5411 'List ' . $categoryPlural . ' for which category of custom profile?',
5412 );
5413  
5414 } elsif (! $session->ivExists('templateHash', $arg)) {
5415  
5416 return $self->error(
5417 $session, $inputString,
5418 'Unrecognised custom profile category \'' . $arg . '\'',
5419 );
5420  
5421 } elsif (! $session->ivExists('currentProfHash', $arg)) {
5422  
5423 return $self->error(
5424 $session, $inputString,
5425 'Can\'t list ' . $categoryPlural . ' for the current ' . $arg
5426 . ' custom profile - no current profile set',
5427 );
5428  
5429 } else {
5430  
5431 $profObj = $session->ivShow('currentProfHash', $arg);
5432 $owner = $profObj->name;
5433 $cage = $session->findCurrentCage($category, $owner);
5434 }
5435  
5436 } elsif ($switch eq '-d') {
5437  
5438 if (! defined $arg) {
5439  
5440 return $self->error(
5441 $session, $inputString,
5442 'List ' . $categoryPlural . ' for which profile?',
5443 );
5444  
5445 } elsif (! $session->ivExists('profHash', $arg)) {
5446  
5447 return $self->error(
5448 $session, $inputString,
5449 'Unrecognised profile \'' . $arg . '\'',
5450 );
5451  
5452 } else {
5453  
5454 $owner = $arg;
5455 $cage = $session->findCage($category, $owner);
5456 }
5457 }
5458  
5459 if ($cage) {
5460  
5461 # Import the cage's hash of interface objects
5462 %hash = $cage->interfaceHash;
5463 }
5464  
5465 # Check there is something to display
5466 @list = sort {lc($hash{$a}) cmp lc($hash{$b})} (keys %hash);
5467 if (! @list) {
5468  
5469 return $self->complete($session, $standardCmd, 'The specified list is empty');
5470 }
5471  
5472 # Display header
5473 $session->writeText(
5474 'Independent ' . $category . ' list for \'' . $owner . '\' (* = Active'
5475 . ' E = Enabled)',
5476 );
5477  
5478 $string = 'Stimulus (pattern) Response (action)';
5479  
5480  
5481 if ($category eq 'trigger') {
5482 $string = 'Stimulus (pattern) Response (instruction, rewriter: substitution)';
5483 } elsif ($category eq 'alias') {
5484 $string = 'Stimulus (pattern) Response (substitution)';
5485 } elsif ($category eq 'macro') {
5486 $string = 'Stimulus (key) Response (instruction)';
5487 } elsif ($category eq 'timer') {
5488 $string = 'Stimulus (interval) Response (instruction)';
5489 } elsif ($category eq 'hook') {
5490 $string = 'Stimulus (hook event) Response (instruction)';
5491 }
5492  
5493 $session->writeText(' Name ' . $string);
5494  
5495 # Display list
5496 foreach my $name (@list) {
5497  
5498 my ($obj, $column);
5499  
5500 $obj = $hash{$name};
5501  
5502 if (
5503 $session->ivExists('interfaceHash', $name)
5504 && $session->ivShow('interfaceHash', $name) eq $obj
5505 ) {
5506 $column = '*'; # Active trigger (etc)
5507 } else {
5508 $column = '*'; # Inactive trigger (etc)
5509 }
5510  
5511 if ($obj->enabledFlag) {
5512 $column .= 'E '; # Enabled
5513 } else {
5514 $column .= ' '; # Disabled
5515 }
5516  
5517 $session->writeText(
5518 $column . sprintf(
5519 '%-32.32s %-24.24s %-24.24s',
5520 $name,
5521 $obj->stimulus, # Shortened to fit
5522 $obj->response, # Shortened to fit
5523 )
5524 );
5525 }
5526  
5527 # ;ltr -i
5528 # (etc)
5529 } else {
5530  
5531 # Import the interface registry for the session
5532 %hash = $session->interfaceHash;
5533  
5534 # Compile a hash of active trigger (etc) interfaces
5535 foreach my $name (keys %hash) {
5536  
5537 my $obj = $hash{$name};
5538  
5539 if ($obj->category eq $category) {
5540  
5541 $modifiedHash{$name} = $obj;
5542 }
5543 }
5544  
5545 # Display header
5546 $session->writeText(
5547 'Active ' . $category . ' interface list (I = independent, D = dependent)',
5548 );
5549  
5550 # Display list
5551 @list = sort {lc($modifiedHash{$a}) cmp lc($modifiedHash{$b})} (keys %modifiedHash);
5552 foreach my $name (@list) {
5553  
5554 my ($obj, $column);
5555  
5556 $obj = $modifiedHash{$name};
5557  
5558 if ($obj->indepFlag) {
5559 $column = ' I '; # Independent trigger (etc)
5560 } else {
5561 $column = ' D '; # Dependent trigger (etc)
5562 }
5563  
5564 $session->writeText(
5565 $column . sprintf('Name: %-32.32s', $name) . ' (# ' . $obj->number . ')',
5566 );
5567  
5568 if (length ($obj->stimulus) > 64) {
5569 $session->writeText(sprintf (' Stimulus: %-64.64s...', $obj->stimulus));
5570 } else {
5571 $session->writeText(' Stimulus: ' . $obj->stimulus);
5572 }
5573  
5574 if (length ($obj->response) > 64) {
5575 $session->writeText(sprintf (' Response: %-64.64s...', $obj->response));
5576 } else {
5577 $session->writeText(' Response: ' . $obj->response);
5578 }
5579  
5580 if (! $obj->indepFlag) {
5581  
5582 $string = ref($obj->callClass) . '->' . $obj->callMethod;
5583 if (length $string > 64) {
5584 $session->writeText(sprintf (' Method: %-64.64s...', $string));
5585 } else {
5586 $session->writeText(' Method: ' . $string);
5587 }
5588 }
5589 }
5590 }
5591  
5592 # Display footer
5593 if (@list == 1) {
5594  
5595 return $self->complete(
5596 $session, $standardCmd,
5597 'End of list (1 ' . $category . ' interface found)',
5598 );
5599  
5600 } else {
5601  
5602 return $self->complete(
5603 $session, $standardCmd,
5604 'End of list (' . scalar @list . ' ' . $category . ' interfaces found)',
5605 );
5606 }
5607 }
5608  
5609 sub addRecordingString {
5610  
5611 # Called by GA::Cmd::WorldCommand->do, ClientCommand->do, Comment->do, Break->do
5612 # Adds a new string to the current recording
5613 #
5614 # Expected arguments
5615 # $session - The calling function's GA::Session
5616 # $string - The string to add
5617 #
5618 # Return values
5619 # 'undef' on improper arguments or if there is no current recording for the specified
5620 # session
5621 # 1 otherwise
5622  
5623 my ($self, $session, $string, $check) = @_;
5624  
5625 # Check for improper arguments
5626 if (! defined $session || ! defined $string || defined $check) {
5627  
5628 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRecordingString', @_);
5629 }
5630  
5631 # Check there is a current recording (should already have been checked, but let's be
5632 # thorough)
5633 if (! $session->recordingFlag) {
5634  
5635 return undef;
5636 }
5637  
5638 # If there's a defined insertion point, insert the string there
5639 if (
5640 defined $session->recordingPosn
5641 && $session->recordingPosn <= scalar $session->recordingList
5642 ) {
5643 # Insert the command at the insertion point
5644 $session->ivSplice(
5645 'recordingList',
5646 $session->recordingPosn,
5647 0,
5648 $string,
5649 );
5650  
5651 # The new insertion point is the line after this one
5652 $session->ivIncrement('recordingPosn');
5653  
5654 } else {
5655  
5656 # No insertion point specified, or the insertion point is at a line number that's bigger
5657 # than the size of the recording, so $string must be added to the end of the
5658 # recording
5659 $session->ivPush('recordingList', $string);
5660 # In case $self->recordingPosn was outside the list, make sure future commands are
5661 # just added to the end of the list
5662 $session->ivUndef('recordingPosn');
5663 }
5664  
5665 return 1;
5666 }
5667  
5668 sub useRoute {
5669  
5670 # Called by GA::Cmd::Drive->do, Road->do and Quick->do
5671 # Moves between one tagged room and another using pre-defined routes
5672 #
5673 # Expected arguments
5674 # $session - The calling function's GA::Session
5675 # $inputString, $standardCmd
5676 # - Standard arguments for a call to a GA::Cmd::XXX->do
5677 # $start - The room tag of the initial room
5678 # $stop - The room tag of the target room
5679 # $routeType - Which kind of routes to use - 'road', 'quick' or 'both'
5680 #
5681 # Return values
5682 # 'undef' on improper arguments or if there's an error
5683 # 1 otherwise
5684  
5685 my ($self, $session, $inputString, $standardCmd, $start, $stop, $routeType, $check) = @_;
5686  
5687 # Local variables
5688 my (
5689 $routeString, $routeObj, $cmdListRef, $cmdSequence, $cmdCount,
5690 @list,
5691 );
5692  
5693 # Check for improper arguments
5694 if (
5695 ! defined $session || ! defined $inputString || ! defined $standardCmd
5696 || ! defined $start || ! defined $stop || ! defined $routeType || defined $check
5697 ) {
5698 return $axmud::CLIENT->writeImproper($self->_objClass . '->useRoute', @_);
5699 }
5700  
5701 # Use this string for messages including the route type
5702 if ($routeType eq 'road' || $routeType eq 'quick') {
5703 $routeString = ' ' . $routeType;
5704 } else {
5705 $routeString = '';
5706 }
5707  
5708 # Look for a route object between the two tagged rooms. Start searching in the highest-
5709 # priority route cage
5710 OUTER: foreach my $category ($session->profPriorityList) {
5711  
5712 my $cage = $session->findCurrentCage('route', $category);
5713 if ($cage) {
5714  
5715 # Route objects are stored in the route cage's ->routeHash IV. Keys are in the form
5716 # r_start-room-tag@@@stop-room-tag (for road routes)
5717 # q_start-room-tag@@@stop-room-tag (for quick routes)
5718  
5719 # Find the route from this cage, or from inferior cages (if necessary). If the
5720 # calling function specified both road routes and quick routes, find road routes
5721 # first
5722 if ($routeType ne 'quick') {
5723  
5724 $routeObj = $cage->ivShow(
5725 'routeHash',
5726 'r_' . $start . '@@@' . $stop,
5727 $session, # Consult inferior cages
5728 );
5729 }
5730  
5731 if (! $routeObj) {
5732  
5733 $routeObj = $cage->ivShow(
5734 'routeHash',
5735 'q_' . $start . '@@@' . $stop,
5736 $session, # Consult inferior cages
5737 );
5738 }
5739  
5740 last OUTER;
5741 }
5742 }
5743  
5744 # If there is no pre-defined route between <start> and <stop>...
5745 if (! $routeObj) {
5746  
5747 # Try to work out the shortest path between the two rooms, using only the network of
5748 # interlinked GA::Obj::Route objects
5749 $cmdListRef = $session->worldModelObj->findRoutePath(
5750 $session,
5751 $start,
5752 $stop,
5753 $routeType,
5754 );
5755  
5756 if (! defined $cmdListRef || ! @$cmdListRef) {
5757  
5758 return $self->error(
5759 $session, $inputString,
5760 'No' . $routeString . ' route between \'' . $start . '\' and \'' . $stop
5761 . '\' found',
5762 );
5763  
5764 } else {
5765  
5766 # Use this route
5767 $cmdSequence = join($axmud::CLIENT->cmdSep, @$cmdListRef);
5768 $cmdCount = scalar @$cmdListRef;
5769 }
5770  
5771 } else {
5772  
5773 # Use the pre-defined route. If $routeObj->route is a speedwalk command, convert it into
5774 # a chain of world commands
5775 if (index($routeObj->route, $axmud::CLIENT->constSpeedSigil) == 0) {
5776  
5777 @list = $session->parseSpeedWalk($routeObj->route);
5778 $cmdSequence = join($axmud::CLIENT->cmdSep, @list);
5779 $cmdCount = scalar @list;
5780  
5781 } else {
5782  
5783 # $routeObj->route is already a single world command or a chain of world commands
5784 $cmdSequence = $routeObj->route;
5785 $cmdCount = $routeObj->stepCount;
5786 }
5787 }
5788  
5789 # Final check that we really have found a route
5790 if (! $cmdSequence) {
5791  
5792 return $self->error(
5793 $session, $inputString,
5794 'General error processing the route between \'' . $start . '\' and \'' . $stop
5795 . '\'',
5796 );
5797 }
5798  
5799 # If the Locator task is running, tell it about the target room's tag
5800 if ($session->locatorTask) {
5801  
5802 $session->locatorTask->set_arrivalTag($stop);
5803 }
5804  
5805 # Take the route
5806 $session->worldCmd($cmdSequence);
5807  
5808 if ($cmdCount == 1) {
5809  
5810 return $self->complete(
5811 $session, $standardCmd,
5812 'Taking' . $routeString . ' route from \'' . $start . '\' to \'' . $stop
5813 . '\' (in 1 step)',
5814 );
5815  
5816 } else {
5817  
5818 return $self->complete(
5819 $session, $standardCmd,
5820 'Taking' . $routeString . ' route from \'' . $start . '\' to \'' . $stop . '\' (in '
5821 . $cmdCount . ' steps)',
5822 );
5823 }
5824 }
5825  
5826 sub autoQuit {
5827  
5828 # Called by GA::Cmd::Quit->do, QQuit->do and QuitAll->do
5829 # Sends a standard 'quit' world command, sends a sequence of world commands, runs a task,
5830 # runs an Axbasic script or starts a mission, depending on the value of
5831 # GA::Profile::World->autoQuitMode
5832 #
5833 # Expected arguments
5834 # $session - The calling function's GA::Session
5835 # $inputString, $standardCmd
5836 # - Standard arguments for a call to a GA::Cmd::XXX->do
5837 # $simpleMsg - Success message to use in auto-quit mode 'normal'
5838 # $initiateMsg - Success message to use in all other auto-quit modes
5839 #
5840 # Return values
5841 # 'undef' on improper arguments or if there's an error
5842 # 1 otherwise
5843  
5844 my ($self, $session, $inputString, $standardCmd, $simpleMsg, $initiateMsg, $check) = @_;
5845  
5846 # Local variables
5847 my (
5848 $name, $initFailMsg, $result, $failMsg, $packageName, $rawScriptObj, $path, $taskObj,
5849 $missionObj, $scriptObj,
5850 );
5851  
5852 # Check for improper arguments
5853 if (
5854 ! defined $session || ! defined $inputString || ! defined $standardCmd
5855 || ! defined $simpleMsg || ! defined $initiateMsg || defined $check
5856 ) {
5857 return $axmud::CLIENT->writeImproper($self->_objClass . '->autoQuit', @_);
5858 }
5859  
5860 # Import one IV for convenience
5861 $name = $session->currentWorld->autoQuitObjName;
5862 # Standard failure message
5863 $initFailMsg = 'Could not initiate auto-quit sequence - ';
5864  
5865 # Mode 'world_cmd' - Send a sequence of world commands
5866 if (
5867 $session->currentWorld->autoQuitMode eq 'world_cmd'
5868 && $session->currentWorld->autoQuitCmdList
5869 ) {
5870 $result = $self->complete($session, $standardCmd, $initiateMsg);
5871  
5872 foreach my $cmd ($session->currentWorld->autoQuitCmdList) {
5873  
5874 $session->worldCmd($cmd);
5875 }
5876  
5877 return $result;
5878  
5879 # Mode 'task' - Run a task (the task is responsible for sending a 'quit' world command)
5880 } elsif ($session->currentWorld->autoQuitMode eq 'task' && $name) {
5881  
5882 # $self->findTaskPackageName recognises unique names of currently running tasks (e.g.
5883 # 'status_task_57'), so before we consult it, check that $name isn't already running
5884 if ($session->ivExists('currentTaskHash', $name)) {
5885  
5886 $failMsg
5887 = $initFailMsg . '\'' . $name . '\' isn\'t a valid task name or task label';
5888  
5889 } else {
5890  
5891 # Get the task's package name (e.g. 'Games::Axmud::Task::Status')
5892 $packageName = Games::Axmud::Generic::Cmd->findTaskPackageName($session, $name);
5893 if (! $packageName) {
5894  
5895 $failMsg = $initFailMsg . 'could not start the task \'' . $name . '\'';
5896  
5897 } else {
5898  
5899 # Create the task object
5900 $packageName->new($session, 'current');
5901 }
5902 }
5903  
5904 if ($failMsg) {
5905 return $self->error($session, $inputString, $failMsg);
5906 } else {
5907 return $self->complete($session, $standardCmd, $initiateMsg);
5908 }
5909  
5910 # Mode 'task_script' - Run an Axbasic script from within a task (the script is responsible
5911 # for sending a 'quit' world command)
5912 } elsif ($session->currentWorld->autoQuitMode eq 'task_script' && $name) {
5913  
5914 # We need to check that the file containing the script exists, because the Script task
5915 # won't pass us a convenient error return value. Create a dummy raw script to do it
5916 $rawScriptObj = Language::Axbasic::RawScript->new($session, $name);
5917 if (! $rawScriptObj) {
5918  
5919 $failMsg = $initFailMsg . 'could not run the ' . $axmud::BASIC_NAME . ' script \''
5920 . $name . '\'';
5921  
5922 } else {
5923  
5924 # Load the script into the raw script object
5925 $path = $axmud::DATA_DIR . '/scripts/' . $name . '.bas';
5926 if (! $rawScriptObj->loadFile($path)) {
5927  
5928 $failMsg = $initFailMsg . 'could not load the ' . $axmud::BASIC_NAME
5929 . ' script \'' . $name . '\'';
5930  
5931 } else {
5932  
5933 # Create the task object
5934 $taskObj = Games::Axmud::Task::Script->new($session, 'current');
5935 if (! $taskObj) {
5936  
5937 $failMsg = $initFailMsg . 'could not start a Script task running the'
5938 . ' ' . $axmud::BASIC_NAME . ' script \'' . $name . '\'';
5939  
5940 } else {
5941  
5942 # Tell it which script to execute
5943 $taskObj->ivPoke('scriptName', $name);
5944 }
5945 }
5946 }
5947  
5948 if ($failMsg) {
5949 return $self->error($session, $inputString, $failMsg);
5950 } else {
5951 return $self->complete($session, $standardCmd, $initiateMsg);
5952 }
5953  
5954 # Mode 'script' - Run an Axbasic script (the script is responsible for sending a 'quit'
5955 # world command)
5956 } elsif ($session->currentWorld->autoQuitMode eq 'script' && $name) {
5957  
5958 # Create the raw script object
5959 $rawScriptObj = Language::Axbasic::RawScript->new($session, $name);
5960 if (! $rawScriptObj) {
5961  
5962 $failMsg = $initFailMsg . 'could not run the ' . $axmud::BASIC_NAME . ' script \''
5963 . $name . '\'';
5964  
5965 } else {
5966  
5967 # Load the script into the raw script object
5968 $path = $axmud::DATA_DIR . '/scripts/' . $name . '.bas';
5969 if (! $rawScriptObj->loadFile($path)) {
5970  
5971 $failMsg = $initFailMsg . 'could not load the ' . $axmud::BASIC_NAME
5972 . ' script \'' . $name . '\'';
5973  
5974 } else {
5975  
5976 # Create a script object, which processes the raw script, removing extraneous
5977 # whitespace, empty lines, comments, etc
5978 $scriptObj = Language::Axbasic::Script->new($session, $rawScriptObj);
5979 if (! $scriptObj) {
5980  
5981 $failMsg = $initFailMsg . 'could not run the ' . $axmud::BASIC_NAME
5982 . ' script \'' . $name . '\'';
5983  
5984 } else {
5985  
5986 # Execute the script
5987 $scriptObj->implement();
5988 }
5989 }
5990 }
5991  
5992 if ($failMsg) {
5993 return $self->error($session, $inputString, $failMsg);
5994 } else {
5995 return $self->complete($session, $standardCmd, $initiateMsg);
5996 }
5997  
5998 # Mode 'mission' - Start a mission (the mission is responsible for sending a 'quit' world
5999 # command)
6000 } elsif ($session->currentWorld->autoQuitMode eq 'mission' && $name) {
6001  
6002 # If the mission exists...
6003 if (! $session->currentWorld->ivExists('missionHash', $name)) {
6004  
6005 $failMsg = $initFailMsg . 'the mission \'' . $name . '\' doesn\'t exist';
6006  
6007 } else {
6008  
6009 $missionObj = $session->currentWorld->ivShow('missionHash', $name);
6010  
6011 # If the world profile's ->loginSpecialList is set, make a local copy of the list
6012 $session->set_loginSpecialList($session->currentWorld->loginSpecialList);
6013  
6014 # Start the mission. The TRUE flag means to refrain from displaying confirmation
6015 # messages
6016 if (! $missionObj->startMission(TRUE)) {
6017  
6018 $failMsg = $initFailMsg . 'Could not start the mission \'' . $name . '\'';
6019  
6020 } else {
6021  
6022 # Automatically send the first group of commands (as if ';mission' had been
6023 # typed by the user
6024 $missionObj->continueMission($session);
6025 }
6026 }
6027  
6028 if ($failMsg) {
6029 return $self->error($session, $inputString, $failMsg);
6030 } else {
6031 return $self->complete($session, $standardCmd, $initiateMsg);
6032 }
6033  
6034 # Mode 0 - Send the standard 'quit' world command, as defined by the current
6035 # highest-priority command cage
6036 # Modes 1-5 (if ->autoQuitCmdList or ->autoQuitObjName are required, but not set)
6037 } else {
6038  
6039 # Send the 'quit' command for this world
6040 $session->sendModCmd('quit');
6041  
6042 return $self->complete($session, $standardCmd, $simpleMsg);
6043 }
6044 }
6045  
6046 sub sortAttributes {
6047  
6048 # Called by GA::Cmd::Read->do, Switch->do and Alert->do (and also PermRead->do,
6049 # PermSwitch->do, PermAlert->do
6050 # Returns a string containing a list of text-to-speech attributes, sorted by task
6051 #
6052 # Expected arguments
6053 # $iv - The GA::Client IV that stores the attributes to sort (e.g. ->ttsAttribHash)
6054 #
6055 # Return values
6056 # 'undef' on improper arguments
6057 # Otherwise returns the string
6058  
6059 my ($self, $iv, $check) = @_;
6060  
6061 # Local variables
6062 my (
6063 $string,
6064 %taskHash,
6065 );
6066  
6067 # Check for improper arguments
6068 if (! defined $iv || defined $check) {
6069  
6070 return $axmud::CLIENT->writeImproper($self->_objClass . '->sortAttributes', @_);
6071 }
6072  
6073 foreach my $attrib ($axmud::CLIENT->ivKeys($iv)) {
6074  
6075 my ($task, $listRef);
6076  
6077 $task = $axmud::CLIENT->ivShow($iv, $attrib);
6078  
6079 if (! exists $taskHash{$task}) {
6080  
6081 $taskHash{$task} = [$attrib];
6082  
6083 } else {
6084  
6085 $listRef = $taskHash{$task};
6086 push (@$listRef, $attrib);
6087 }
6088 }
6089  
6090 foreach my $task (sort {lc($a) cmp lc($b)} (keys %taskHash)) {
6091  
6092 my ($listRef, $prettyTask);
6093  
6094 $listRef = $taskHash{$task};
6095  
6096 # (Convert 'locator_task' to 'Locator task')
6097 $prettyTask = ucfirst($task);
6098 $prettyTask =~ s/\_/ /;
6099  
6100 $string .= $prettyTask . ': ' . join(', ', sort {lc($a) cmp lc($b)} (@$listRef)) . '. ';
6101 }
6102  
6103 return $string;
6104 }
6105  
6106 sub getKeypadHashes {
6107  
6108 # Called by GA::Cmd::Compass->do, PermCompass->do
6109 # Defines two hashes, one of keypad keycodes that the Compass task allows the user to
6110 # customise, and another of the keypad keycodes that the Compass task won't customise.
6111 # Returns the hashes as hash references
6112 #
6113 # Expected arguments
6114 # (none besides $self)
6115 #
6116 # Return values
6117 # 'undef' on improper arguments
6118 # Otherwise returns two hash references
6119  
6120 my ($self, $check) = @_;
6121  
6122 # Local variables
6123 my (%hash, %otherHash);
6124  
6125 # Check for improper arguments
6126 if (defined $check) {
6127  
6128 return $axmud::CLIENT->writeImproper($self->_objClass . '->getKeypadHashes', @_);
6129 }
6130  
6131 # Hash to convert all the <key>s that the Compass task allows us to customise
6132 %hash = (
6133 0 => 'kp_0',
6134 'zero' => 'kp_0',
6135 'kp_0' => 'kp_0',
6136  
6137 5 => 'kp_5',
6138 'five' => 'kp_5',
6139 'kp_5' => 'kp_5',
6140  
6141 '*' => 'kp_multiply',
6142 'times' => 'kp_multiply',
6143 'multiply' => 'kp_multiply',
6144 'kp_multiply' => 'kp_multiply',
6145  
6146 '/' => 'kp_divide',
6147 'slash' => 'kp_divide',
6148 'divide' => 'kp_divide',
6149 'kp_divide' => 'kp_divide',
6150  
6151 '.' => 'kp_full_stop',
6152 'dot' => 'kp_full_stop',
6153 'fullstop' => 'kp_full_stop',
6154 'period' => 'kp_full_stop',
6155 'kp_full_stop' => 'kp_full_stop',
6156  
6157 'enter' => 'kp_enter',
6158 'return' => 'kp_enter',
6159 'kp_enter' => 'kp_enter',
6160 );
6161  
6162 # Hash of other keypad <key>s that the Compass task doesn't allow us to customise
6163 %otherHash = (
6164 1 => '1',
6165 2 => '2',
6166 3 => '3',
6167 4 => '4',
6168 6 => '6',
6169 7 => '7',
6170 8 => '8',
6171 9 => '9',
6172  
6173 'one' => '1',
6174 'two' => '2',
6175 'three' => '3',
6176 'four' => '4',
6177 'six' => '6',
6178 'seven' => '7',
6179 'eight' => '8',
6180 'nine' => '9',
6181  
6182 'kp_1' => '1',
6183 'kp_2' => '2',
6184 'kp_3' => '3',
6185 'kp_4' => '4',
6186 'kp_6' => '6',
6187 'kp_7' => '7',
6188 'kp_8' => '8',
6189 'kp_9' => '9',
6190  
6191 '+' => 'add',
6192 'plus' => 'add',
6193 'add' => 'add',
6194 'kp_add' => 'add',
6195  
6196 '-' => 'subtract',
6197 'minus' => 'subtract',
6198 'subtract' => 'subtract',
6199 'kp_subtract' => 'subtract',
6200 );
6201  
6202 return (\%hash, \%otherHash);
6203 }
6204  
6205 sub updateCompass {
6206  
6207 # Called by GA::Cmd::PermCompass->do and WorldCompass->do
6208 # Applies changes to the IVs for a global initial task or the current world's initial task
6209 #
6210 # Expected arguments
6211 # $session, $inputString, $standardCmd
6212 # - Standard arguments to a command's ->do function
6213 # $argListRef - Reference to the list of arguments supplied to the client command
6214 # (unmodified). The calling function has already checked there is at
6215 # least one argument
6216 # $currentListRef - Reference to a list of current tasklist tasks (should contain 0 or 1
6217 # items)
6218 # $initListRef - Reference to a list of initial tasks (can contain any number of items,
6219 # including 0)
6220 #
6221 # Return values
6222 # 'undef' on improper arguments or failure
6223 # 1 on success
6224  
6225 my (
6226 $self, $session, $inputString, $standardCmd, $argListRef, $currentListRef, $initListRef,
6227 $check,
6228 ) = @_;
6229  
6230 # Local variables
6231 my (
6232 $hashRef, $otherHashRef, $count, $errorCount, $key, $keycode, $cmd,
6233 @args, @taskList, @initTaskList,
6234 %hash, %otherHash,
6235 );
6236  
6237 # Check for improper arguments
6238 if (
6239 ! defined $session || ! defined $inputString || ! defined $standardCmd
6240 || ! defined $argListRef || ! defined $currentListRef || ! defined $initListRef
6241 || defined $check
6242 ) {
6243 return $axmud::CLIENT->writeImproper(
6244 $self->_objClass . '->updateCompass',
6245 @_,
6246 );
6247 }
6248  
6249 # Dereference the args
6250 @args = @$argListRef;
6251 @taskList = @$currentListRef;
6252 @initTaskList = @$initListRef;
6253  
6254 # %hash to convert all the <key>s that the Compass task allows us to customise
6255 # %otherHash of other keypad <key>s that the Compass task doesn't allow us to customise
6256 ($hashRef, $otherHashRef) = $self->getKeypadHashes();
6257 %hash = %$hashRef;
6258 %otherHash = %$otherHashRef;
6259  
6260 # Count successes and errors, to show in confirmation messages
6261 $count = 0;
6262 $errorCount = 0;
6263  
6264 # ;pcm on
6265 # ;pcm -o
6266 if ($args[0] eq 'on' || $args[0] eq '-o') {
6267  
6268 # (For the benefit of visually-impaired users, ignore everything after the first
6269 # argument)
6270 foreach my $taskObj (@taskList) {
6271  
6272 if (! $taskObj->enable()) {
6273 $errorCount++;
6274 } else {
6275 $count++;
6276 }
6277 }
6278  
6279 foreach my $taskObj (@initTaskList) {
6280  
6281 $count++;
6282 $taskObj->set_enabledFlag(TRUE);
6283 }
6284  
6285 return $self->complete(
6286 $session, $standardCmd,
6287 'Compass tasks set to \'enabled\'. (Found tasks: ' . ($count + $errorCount)
6288 . ', errors: ' . $errorCount . ').',
6289 )
6290  
6291 # ;pcm off
6292 # ;pcm -f
6293 } elsif ($args[0] eq 'off' || $args[0] eq '-f') {
6294  
6295 foreach my $taskObj (@taskList) {
6296  
6297 if (! $taskObj->disable()) {
6298 $errorCount++;
6299 } else {
6300 $count++;
6301 }
6302 }
6303  
6304 foreach my $taskObj (@initTaskList) {
6305  
6306 $count++;
6307 $taskObj->set_enabledFlag(FALSE);
6308 }
6309  
6310 return $self->complete(
6311 $session, $standardCmd,
6312 'Compass tasks set to \'disabled\'. (Found tasks: ' . ($count + $errorCount)
6313 . ', errors: ' . $errorCount . ').',
6314 );
6315  
6316 # ;pcm <key> <command>
6317 # ;pcm <key>
6318 } elsif ($args[0]) {
6319  
6320 # Get the Axmud standard keycode
6321 $key = shift @args;
6322 if (! exists $hash{$key} && ! exists $otherHash{$key}) {
6323  
6324 return $self->error(
6325 $session, $inputString,
6326 'Unrecognised keypad key (try \';help compass\' for a list of recognised keys)',
6327 );
6328  
6329 } elsif (exists $otherHash{$key}) {
6330  
6331 return $self->error(
6332 $session, $inputString,
6333 'The Compass task doesn\'t allow us to customise the \'' . $otherHash{$key}
6334 . '\' key',
6335 );
6336  
6337 } else {
6338  
6339 $keycode = $hash{$key};
6340 }
6341  
6342 # Set the corresponding world <command> (if one was specified)
6343 if (@args) {
6344  
6345 $cmd = join (' ', @args);
6346 }
6347  
6348 # Update the task(s)
6349 foreach my $taskObj (@taskList, @initTaskList) {
6350  
6351 if (! $taskObj->set_key($keycode, $cmd)) {
6352 $errorCount++;
6353 } else {
6354 $count++;
6355 }
6356 }
6357  
6358 return $self->complete(
6359 $session, $standardCmd,
6360 'Set a world command for the keypad key \'' . $key . '\'. (Found tasks: '
6361 . ($count + $errorCount) . ', errors: ' . $errorCount . ').',
6362 );
6363 }
6364 }
6365  
6366 sub killLimitedTargets {
6367  
6368 # Called by GA::Cmd::Kill->do and Kkill->do
6369 # Attacks a list of targets limited to the given arguments, e.g. ('orc') or ('orcs',
6370 # 'troll', 'bears'), but doesn't attack players
6371 #
6372 # Expected arguments
6373 # $session - The calling function's GA::Session
6374 # $inputString - What the player actually typed (e.g. ';k orcs');
6375 # $standardCmd - The standard version of the command (i.e. 'kill')
6376 # $multipleFlag - Flag set to FALSE when called by ';kill' (e.g. attack a single orc),
6377 # set to TRUE when called by ';kkill' (e.g. attack all orcs at current
6378 # location)
6379 # @targetList - A list of target strings specified by the user, e.g. ('orcs', 'wolf')
6380 #
6381 # Return values
6382 # 'undef' on improper arguments or failure
6383 # 1 on success
6384  
6385 my ($self, $session, $inputString, $standardCmd, $multipleFlag, @targetList) = @_;
6386  
6387 # Local variables
6388 my @objList;
6389  
6390 # Check for improper arguments
6391 if (
6392 ! defined $session || ! defined $inputString || ! defined $standardCmd
6393 || ! defined $multipleFlag
6394 ) {
6395 return $axmud::CLIENT->writeImproper($self->_objClass . '->killLimitedTargets', @_);
6396 }
6397  
6398 # This command requires the Locator task to know the current location
6399 if (! $session->locatorTask) {
6400  
6401 return $self->error(
6402 $session, $inputString,
6403 'Cannot kill - Locator task isn\'t running',
6404 );
6405  
6406 } elsif (! $session->locatorTask->roomObj) {
6407  
6408 return $self->error(
6409 $session, $inputString,
6410 'Cannot kill - Locator task doesn\'t know the current location',
6411 );
6412 }
6413  
6414 if (! @targetList) {
6415  
6416 # Get the first target from the Locator's list of things in the current room
6417 @objList = $session->locatorTask->roomObj->tempObjList;
6418 if (! @objList) {
6419  
6420 return $self->complete(
6421 $session, $standardCmd,
6422 'Cannot kill - current location is empty',
6423 );
6424  
6425 } else {
6426  
6427 # Choose the first minion, sentient or creature in @objList
6428 OUTER: foreach my $obj (@objList) {
6429  
6430 if (
6431 $obj->aliveFlag
6432 && (
6433 ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6434 || $obj->category eq 'sentient'
6435 || $obj->category eq 'creature'
6436 )
6437 ) {
6438 push (@targetList, $obj->noun);
6439 last OUTER;
6440 }
6441 }
6442 }
6443  
6444 # If no suitable objects were found, don't attack
6445 if (! @targetList) {
6446  
6447 return $self->complete(
6448 $session, $standardCmd,
6449 'Cannot kill - no enemy minions, sentients or creatures at the current'
6450 . ' location',
6451 );
6452 }
6453 }
6454  
6455 # Attack the targets
6456 foreach my $target (@targetList) {
6457  
6458 $session->sendModCmd('kill', 'victim', $target);
6459 }
6460  
6461 if (scalar @targetList == 1) {
6462  
6463 return $self->complete($session, $standardCmd, 'Attacking 1 target');
6464  
6465 } else {
6466  
6467 return $self->complete(
6468 $session, $standardCmd,
6469 'Attacking ' . scalar @targetList . ' targets',
6470 );
6471 }
6472 }
6473  
6474 sub killUnlimitedTargets {
6475  
6476 # Called by GA::Cmd::KillAll->do and KillMall->do
6477 # Attacks all targets (or all non-player targets) at current location
6478 #
6479 # Expected arguments
6480 # $session - The calling function's GA::Session
6481 # $inputString - What the player actually typed (e.g. ';ka');
6482 # $standardCmd - The standard version of the command (i.e. 'killall')
6483 # $playerFlag - Set to TRUE if player targets should be attacked too; FALSE if only
6484 # non-player targets should be attacked
6485 #
6486 # Return values
6487 # 'undef' on improper arguments or failure
6488 # 1 on success
6489  
6490 my ($self, $session, $inputString, $standardCmd, $playerFlag, $check) = @_;
6491  
6492 # Local variables
6493 my (@objList, @targetList);
6494  
6495 # Check for improper arguments
6496 if (
6497 ! defined $session || ! defined $inputString || ! defined $standardCmd
6498 || ! defined $playerFlag || defined $check
6499 ) {
6500 return $axmud::CLIENT->writeImproper($self->_objClass . '->killUnlimitedTargets', @_);
6501 }
6502  
6503 # This command requires the Locator task to know the current location
6504 if (! $session->locatorTask) {
6505  
6506 return $self->error(
6507 $session, $inputString,
6508 'Cannot kill - Locator task isn\'t running',
6509 );
6510  
6511 } elsif (! $session->locatorTask->roomObj) {
6512  
6513 return $self->error(
6514 $session, $inputString,
6515 'Cannot kill - Locator task doesn\'t know the current location',
6516 );
6517 }
6518  
6519 # Get a list of attackable targets from the Locator's list of things in the current room
6520 @objList = $session->locatorTask->roomObj->tempObjList;
6521 if (! @objList) {
6522  
6523 return $self->complete(
6524 $session, $standardCmd,
6525 'Cannot kill - current location is empty',
6526 );
6527  
6528 } else {
6529  
6530 foreach my $obj (@objList) {
6531  
6532 if (
6533 $obj->aliveFlag
6534 && (
6535 ($playerFlag && $obj->category eq 'char')
6536 || ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6537 || $obj->category eq 'sentient'
6538 || $obj->category eq 'creature'
6539 )
6540 ) {
6541 push (@targetList, $obj->noun);
6542 }
6543 }
6544 }
6545  
6546 # Attack the targets
6547 foreach my $target (@targetList) {
6548  
6549 $session->sendModCmd('kill', 'victim', $target);
6550 }
6551  
6552 if (scalar @targetList == 1) {
6553  
6554 return $self->complete($session, $standardCmd, 'Attacking 1 target');
6555  
6556 } else {
6557  
6558 return $self->complete(
6559 $session, $standardCmd,
6560 'Attacking ' . scalar @targetList . ' targets',
6561 );
6562 }
6563 }
6564  
6565 sub interactLimitedTargets {
6566  
6567 # Called by GA::Cmd::Kill->do and Kkill->do
6568 # Attacks a list of targets limited to the given arguments, e.g. ('orc') or ('orcs',
6569 # 'troll', 'bears'), but doesn't attack players
6570 #
6571 # Expected arguments
6572 # $session - The calling function's GA::Session
6573 # $inputString - What the player actually typed (e.g. ';k orcs');
6574 # $standardCmd - The standard version of the command (i.e. 'kill')
6575 # $multipleFlag - Flag set to FALSE when called by ';interact' (e.g. attack a single
6576 # orc), set to TRUE when called by ';iinteract' (e.g. attack all orcs
6577 # at current location)
6578 # @targetList - A list of target strings specified by the user, e.g. ('orcs', 'wolf')
6579 #
6580 # Return values
6581 # 'undef' on improper arguments or failure
6582 # 1 on success
6583  
6584 my ($self, $session, $inputString, $standardCmd, $multipleFlag, @targetList) = @_;
6585  
6586 # Local variables
6587 my @objList;
6588  
6589 # Check for improper arguments
6590 if (
6591 ! defined $session || ! defined $inputString || ! defined $standardCmd
6592 || ! defined $multipleFlag
6593 ) {
6594 return $axmud::CLIENT->writeImproper($self->_objClass . '->interactLimitedTargets', @_);
6595 }
6596  
6597 # This command requires the Locator task to know the current location
6598 if (! $session->locatorTask) {
6599  
6600 return $self->error(
6601 $session, $inputString,
6602 'Cannot interact - Locator task isn\'t running',
6603 );
6604  
6605 } elsif (! $session->locatorTask->roomObj) {
6606  
6607 return $self->error(
6608 $session, $inputString,
6609 'Cannot interact - Locator task doesn\'t know the current location',
6610 );
6611 }
6612  
6613 if (! @targetList) {
6614  
6615 # Get the first target from the Locator's list of things in the current room
6616 @objList = $session->locatorTask->roomObj->tempObjList;
6617 if (! @objList) {
6618  
6619 return $self->complete(
6620 $session, $standardCmd,
6621 'Cannot interact - current location is empty',
6622 );
6623  
6624 } else {
6625  
6626 # Choose the first minion, sentient or creature in @objList
6627 OUTER: foreach my $obj (@objList) {
6628  
6629 if (
6630 $obj->aliveFlag
6631 && (
6632 ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6633 || $obj->category eq 'sentient'
6634 || $obj->category eq 'creature'
6635 )
6636 ) {
6637 push (@targetList, $obj->noun);
6638 last OUTER;
6639 }
6640 }
6641 }
6642  
6643 # If no suitable objects were found, don't attack
6644 if (! @targetList) {
6645  
6646 return $self->complete(
6647 $session, $standardCmd,
6648 'Cannot interact - no enemy minions, sentients or creatures at the current'
6649 . ' location',
6650 );
6651 }
6652 }
6653  
6654 # Attack the targets
6655 foreach my $target (@targetList) {
6656  
6657 $session->sendModCmd('interact', 'victim', $target);
6658 }
6659  
6660 if (scalar @targetList == 1) {
6661  
6662 return $self->complete($session, $standardCmd, 'Interacting with 1 target');
6663  
6664 } else {
6665  
6666 return $self->complete(
6667 $session, $standardCmd,
6668 'Interacting with ' . scalar @targetList . ' targets',
6669 );
6670 }
6671 }
6672  
6673 sub interactUnlimitedTargets {
6674  
6675 # Called by GA::Cmd::KillAll->do and KillMall->do
6676 # Attacks all targets (or all non-player targets) at current location
6677 #
6678 # Expected arguments
6679 # $session - The calling function's GA::Session
6680 # $inputString - What the player actually typed (e.g. ';ia');
6681 # $standardCmd - The standard version of the command (i.e. 'interactall')
6682 # $playerFlag - Set to TRUE if player targets should be attacked too; FALSE if only
6683 # non-player targets should be attacked
6684 #
6685 # Return values
6686 # 'undef' on improper arguments or failure
6687 # 1 on success
6688  
6689 my ($self, $session, $inputString, $standardCmd, $playerFlag, $check) = @_;
6690  
6691 # Local variables
6692 my (@objList, @targetList);
6693  
6694 # Check for improper arguments
6695 if (
6696 ! defined $session || ! defined $inputString || ! defined $standardCmd
6697 || ! defined $playerFlag || defined $check
6698 ) {
6699 return $axmud::CLIENT->writeImproper(
6700 $self->_objClass . '->interactUnlimitedTargets',
6701 @_,
6702 );
6703 }
6704  
6705 # This command requires the Locator task to know the current location
6706 if (! $session->locatorTask) {
6707  
6708 return $self->error(
6709 $session, $inputString,
6710 'Cannot kill - Locator task isn\'t running',
6711 );
6712  
6713 } elsif (! $session->locatorTask->roomObj) {
6714  
6715 return $self->error(
6716 $session, $inputString,
6717 'Cannot kill - Locator task doesn\'t know the current location',
6718 );
6719 }
6720  
6721 # Get a list of attackable targets from the Locator's list of things in the current room
6722 @objList = $session->locatorTask->roomObj->tempObjList;
6723 if (! @objList) {
6724  
6725 return $self->complete(
6726 $session, $standardCmd,
6727 'Cannot kill - current location is empty',
6728 );
6729  
6730 } else {
6731  
6732 foreach my $obj (@objList) {
6733  
6734 if (
6735 $obj->aliveFlag
6736 && (
6737 ($playerFlag && $obj->category eq 'char')
6738 || ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6739 || $obj->category eq 'sentient'
6740 || $obj->category eq 'creature'
6741 )
6742 ) {
6743 push (@targetList, $obj->noun);
6744 }
6745 }
6746 }
6747  
6748 # Attack the targets
6749 foreach my $target (@targetList) {
6750  
6751 $session->sendModCmd('interact', 'victim', $target);
6752 }
6753  
6754 if (scalar @targetList == 1) {
6755  
6756 return $self->complete($session, $standardCmd, 'Interacting 1 target');
6757  
6758 } else {
6759  
6760 return $self->complete(
6761 $session, $standardCmd,
6762 'Interacting with ' . scalar @targetList . ' targets',
6763 );
6764 }
6765 }
6766  
6767 # Extract switches
6768  
6769 sub extractProfileSwitches {
6770  
6771 # Called by $self->addInterface, ->modifyInterface, ->deleteInterface
6772 # Extracts the group 1 switch options for the commands ';addtrigger', ';modifytrigger' and
6773 # ';deletetrigger' (etc), namely -w, -r, -g, -c, -x <category>, -d <profile>
6774 #
6775 # Expected arguments
6776 # $session - The calling function's GA::Session
6777 # $inputString - What the user originally typed
6778 # $category - 'trigger', 'alias', 'macro', 'timer' or 'hook'
6779 # $action - What is to be done with the interface: 'add', 'modify', 'export',
6780 # 'import' or 'delete'. Used to set the error message, if any
6781 #
6782 # Optional arguments
6783 # @args - List of group 1 switch options arguments extracted from $inputString
6784 # (maybe be an empty list)
6785 #
6786 # Return values
6787 # Returns an empty list on improper arguments or on failure
6788 # Otherwise, returns a list in the form...
6789 # ($profCount, $profCategory, $profName, @args)
6790 # ...where $profCount is set to 0, if no profiles were found, and @args now contains fewer
6791 # (or the same arguments), depending on how many switch options were removed
6792  
6793 my ($self, $session, $inputString, $category, $action, @args) = @_;
6794  
6795 # Local variables
6796 my (
6797 $switch, $profCount, $profCategory, $profName, $tempCategory, $specificProf,
6798 $profObj,
6799 );
6800  
6801 # Check for improper arguments
6802 if (
6803 ! defined $session || ! defined $inputString || ! defined $category || ! defined $action
6804 ) {
6805 return $axmud::CLIENT->writeImproper(
6806 $self->_objClass . '->extractProfileSwitches',
6807 @_,
6808 );
6809 }
6810  
6811 # Extract group 1 switches
6812 $profCount = 0;
6813 ($switch, @args) = $self->extract('w', 0, @args);
6814 if (defined $switch) {
6815  
6816 $profCount++;
6817 $profCategory = 'world';
6818 $profName = $session->currentWorld->name;
6819 }
6820  
6821 ($switch, @args) = $self->extract('g', 0, @args);
6822 if (defined $switch) {
6823  
6824 if (! $session->currentGuild) {
6825  
6826 return $self->error(
6827 $session, $inputString,
6828 'Can\'t ' . $action . ' ' . $category . ' interface associated with current'
6829 . ' guild - no current guild set',
6830 );
6831  
6832 } else {
6833  
6834 $profCount++;
6835 $profCategory = 'guild';
6836 $profName = $session->currentGuild->name;
6837 }
6838 }
6839  
6840 ($switch, @args) = $self->extract('r', 0, @args);
6841 if (defined $switch) {
6842  
6843 if (! $session->currentRace) {
6844  
6845 return $self->error(
6846 $session, $inputString,
6847 'Can\'t ' . $action . ' ' . $category . ' interface associated with current'
6848 . ' race - no current race set',
6849 );
6850  
6851 } else {
6852  
6853 $profCount++;
6854 $profCategory = 'race';
6855 $profName = $session->currentRace->name;
6856 }
6857 }
6858  
6859 ($switch, @args) = $self->extract('c', 0, @args);
6860 if (defined $switch) {
6861  
6862 if (! $session->currentChar) {
6863  
6864 return $self->error(
6865 $session, $inputString,
6866 'Can\'t ' . $action . ' ' . $category . ' interface associated with current'
6867 . ' character - no current character set',
6868 );
6869  
6870 } else {
6871  
6872 $profCount++;
6873 $profCategory = 'char';
6874 $profName = $session->currentChar->name;
6875 }
6876 }
6877  
6878 ($switch, $tempCategory, @args) = $self->extract('x', 1, @args);
6879 if (defined $switch) {
6880  
6881 if (! $session->ivExists('templateHash', $profCategory)) {
6882  
6883 return $self->error(
6884 $session, $inputString,
6885 'Unrecognised custom profile category \'' . $profCategory . '\'',
6886 );
6887  
6888 } elsif (! $session->ivExists('currentProfHash', $profCategory)) {
6889  
6890 return $self->error(
6891 $session, $inputString,
6892 'Can\'t ' . $action . ' ' . $category . ' interface associated with '
6893 . 'current custom \'' . $profCategory . '\' profile - no '
6894 . 'current ' . $profCategory . ' profile set',
6895 );
6896  
6897 } else {
6898  
6899 $profObj = $session->ivShow('currentProfHash', $profCategory);
6900  
6901 $profCount++;
6902 $profCategory = $tempCategory;
6903 $profName = $profObj->name;
6904 }
6905 }
6906  
6907 ($switch, $specificProf, @args) = $self->extract('d', 1, @args);
6908 if (defined $switch) {
6909  
6910 if (! $session->ivExists('profHash', $specificProf)) {
6911  
6912 return $self->error(
6913 $session, $inputString,
6914 'Unrecognised profile \'' . $specificProf . '\'',
6915 );
6916  
6917 } else {
6918  
6919 $profObj = $session->ivShow('profHash', $specificProf);
6920  
6921 $profCount++;
6922 $profCategory = $profObj->category;
6923 $profName = $profObj->name;
6924 }
6925 }
6926  
6927 # Extraction complete
6928 return ($profCount, $profCategory, $profName, @args);
6929 }
6930  
6931 sub extractTaskSwitches {
6932  
6933 # Called by GA::Cmd::StartTask->do, AddInitTask->do and AddCustomTask->do
6934 # Also called by GA::Cmd::RunScriptTask->do
6935 # Extracts the switch options these commands have in common
6936 #
6937 # Expected arguments
6938 # $session - The calling function's GA::Session
6939 # $inputString - What the user actually typed (e.g. ';st status -i');
6940 # $standardCmd - The standard version of the user command, i.e. 'starttask'
6941 #
6942 # Return values
6943 # An empty list on improper arguments or on failure
6944 # Otherwise, returns a list of values in the form:
6945 # (TRUE, $groupCount, $otherTask, $minutes, $runMinutes, $timer, $immediateFlag,
6946 # $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag, $waitMinutesFlag,
6947 # $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag, @args)
6948 # The first argument, TRUE, is the flag to signal success of this function
6949 # The final argument, @args, contain any remaining arguments after the switch options
6950 # have been extracted
6951  
6952 my ($self, $session, $inputString, $standardCmd, @args) = @_;
6953  
6954 # Local variables
6955 my (
6956 $groupCount, $switch, $otherTask, $minutes, $runMinutes, $timer, $immediateFlag,
6957 $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag, $waitMinutesFlag,
6958 $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag, $string,
6959 @emptyList,
6960 );
6961  
6962 # Check for improper arguments
6963 if (! defined $session || ! defined $inputString || ! defined $standardCmd || ! @args) {
6964  
6965 $axmud::CLIENT->writeImproper($self->_objClass . '->extractTaskSwitches', @_);
6966 return @emptyList;
6967 }
6968  
6969 # Extract group 1 switches
6970 # -i - Start <task> immediately (default setting)
6971 # -e <other_task> - Wait for <other_task> to exist, before starting <task>
6972 # -n <other_task> - Wait for <other_task> to not exist, before starting <task>
6973 # -s <other_task> - Wait for <other_task> to start, then stop, before starting <task>
6974 # -t <minutes> - Start <task> <minutes> from now
6975 $groupCount = 0;
6976  
6977 ($switch, @args) = $self->extract('i', 0, @args);
6978 if (defined $switch) {
6979  
6980 $immediateFlag = TRUE;
6981 $groupCount++;
6982 }
6983  
6984 ($switch, $string, @args) = $self->extract('e', 1, @args);
6985 if (defined $switch) {
6986  
6987 $waitTaskExistFlag = TRUE;
6988 $otherTask = $string;
6989 $groupCount++;
6990 }
6991  
6992 ($switch, $string, @args) = $self->extract('n', 1, @args);
6993 if (defined $switch) {
6994  
6995 $waitTaskNoExistFlag = TRUE;
6996 $otherTask = $string;
6997 $groupCount++;
6998 }
6999  
7000 ($switch, $string, @args) = $self->extract('s', 1, @args);
7001 if (defined $switch) {
7002  
7003 $waitTaskStartStopFlag = TRUE;
7004 $otherTask = $string;
7005 $groupCount++;
7006 }
7007  
7008 ($switch, $string, @args) = $self->extract('t', 1, @args);
7009 if (defined $switch) {
7010  
7011 $waitMinutesFlag = TRUE;
7012 $minutes = $string;
7013 $groupCount++;
7014 }
7015  
7016 if ($groupCount > 1) {
7017  
7018 return $self->error(
7019 $session, $inputString,
7020 'Invalid switch arguments - switches -i/-e/-n/-s/-t can\'t be combined',
7021 );
7022 }
7023  
7024 # Extract group 2 switches
7025 # -d - Run <task> for an unlimited amount of time (default)
7026 # -f <minutes> - Run the task for <minutes>
7027 # -u <timer> - Run the task until the Axmud timer reaches <timer> (seconds since the
7028 # script began)
7029 $groupCount = 0;
7030 ($switch, @args) = $self->extract('d', 0, @args);
7031 if (defined $switch) {
7032  
7033 $unlimitedFlag = TRUE;
7034 $groupCount++;
7035 }
7036  
7037 ($switch, $runMinutes, @args) = $self->extract('f', 1, @args);
7038 if (defined $switch) {
7039  
7040 $runTaskForFlag = TRUE;
7041 $groupCount++;
7042 }
7043  
7044 ($switch, $timer, @args) = $self->extract('u', 1, @args);
7045 if (defined $switch) {
7046  
7047 $runTaskUntilFlag = TRUE;
7048 $groupCount++;
7049 }
7050  
7051 if ($groupCount > 1) {
7052  
7053 return $self->error(
7054 $session, $inputString,
7055 'Invalid switch arguments - switches -d/-f/-u can\'t be combined',
7056 );
7057 }
7058  
7059 # Extract group 3 switches
7060 # -w - Run the task without opening its own window (if it usually does)
7061 ($switch, @args) = $self->extract('w', 0, @args);
7062 if (defined $switch) {
7063  
7064 $noWindowFlag = TRUE;
7065 }
7066  
7067 # Return list of flags. The 1st argument is the flag to signal success
7068 return (
7069 TRUE,
7070 $groupCount, $otherTask, $minutes, $runMinutes, $timer, $immediateFlag,
7071 $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag, $waitMinutesFlag,
7072 $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag,
7073 @args
7074 );
7075 }
7076  
7077 sub extractWinzoneSwitches {
7078  
7079 # Called by GA::Cmd::AddWinzone->do and ModifyWinzone->do
7080 # Extracts the switch options these commands have in common
7081 # Checks that each pattern found is valid, and that the compulsory switch options are
7082 # present
7083 #
7084 # Expected arguments
7085 # $session - The calling function's GA::Session
7086 # $inputString - What the user actually typed (e.g.
7087 # ';awz -p 10 10 -s 10 10 -n MyPackage');
7088 # $standardCmd - The standard version of the command, i.e. 'addwinzone'
7089 # @args - A list of arguments specified by the calling command,
7090 # e.g. ('-p', 10, 10, '-s', 10, 10, '-n', 'MyPackage')
7091 #
7092 # Return values
7093 # Returns 'undef' on improper arguments or on failure
7094 # Otherwise returns a list of arguments in the form
7095 # (
7096 # TRUE,
7097 # $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
7098 # $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
7099 # \%initHash, \%removeHash,
7100 # @args,
7101 # )
7102 # The first argument, TRUE, is the flag to signal success of this function
7103 # The final argument, @args, contain any remaining arguments after the switch options
7104 # have been extracted
7105  
7106 my ($self, $session, $inputString, $standardCmd, @args) = @_;
7107  
7108 # Local variables
7109 my (
7110 $switch, $exitFlag,
7111 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
7112 $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
7113 %initHash, %removeHash,
7114 );
7115  
7116 # Check for improper arguments
7117 if (! defined $session || ! defined $inputString || ! defined $standardCmd) {
7118  
7119 return $self->improper($session, $inputString);
7120 }
7121  
7122 # Extract compulsory switches (optional for ;modifywinzone)
7123 ($switch, $xPosBlocks, $yPosBlocks, @args) = $self->extract('-p', 2, @args);
7124 if (defined $switch) {
7125  
7126 $positionFlag = TRUE;
7127 }
7128  
7129 ($switch, $widthBlocks, $heightBlocks, @args) = $self->extract('-s', 2, @args);
7130 if (defined $switch) {
7131  
7132 $sizeFlag = TRUE;
7133 }
7134  
7135 ($switch, $packageName, @args) = $self->extract('-n', 1, @args);
7136 if (defined $switch) {
7137  
7138 $packageNameFlag = TRUE;
7139  
7140 if (! ($packageName =~ m/\:\:/)) {
7141  
7142 $packageName = 'Games::Axmud::Strip::' . $packageName;
7143 }
7144 }
7145  
7146 # Extract optional switches
7147 ($switch, $objName, @args) = $self->extract('-o', 1, @args);
7148 if (defined $switch) {
7149  
7150 $objNameFlag = TRUE;
7151 }
7152  
7153 do {
7154  
7155 my ($key, $value, $key2);
7156  
7157 $exitFlag = TRUE;
7158  
7159 ($switch, $key, $value, @args) = $self->extract('-i', 2, @args);
7160 if (defined $switch) {
7161  
7162 $exitFlag = FALSE;
7163 $initHash{$key} = $value;
7164 }
7165  
7166 ($switch, $key2, @args) = $self->extract('-r', 1, @args);
7167 if (defined $switch) {
7168  
7169 $exitFlag = FALSE;
7170 $removeHash{$key} = undef;
7171 }
7172  
7173 } until ($exitFlag);
7174  
7175 # Check compulsory switch options (optional for ;modifywinzone)
7176 if (
7177 $standardCmd eq 'addwinzone'
7178 && (
7179 ! defined $positionFlag || ! defined $sizeFlag || ! $packageNameFlag
7180 || ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $widthBlocks
7181 || ! defined $heightBlocks || ! defined $packageName
7182 )
7183 ) {
7184 return $self->error(
7185 $session, $inputString,
7186 'Can\'t add/modify a winzone: missing compulsory switch options',
7187 );
7188  
7189 } elsif (
7190 $standardCmd eq 'modifywinzone'
7191 && (
7192 (
7193 $positionFlag && (! defined $xPosBlocks || ! defined $yPosBlocks)
7194 ) || (
7195 $sizeFlag && (! defined $widthBlocks || ! defined $heightBlocks)
7196 ) || (
7197 $packageNameFlag && ! defined $packageName
7198 ) || %removeHash
7199 )
7200 ) {
7201 return $self->error(
7202 $session, $inputString,
7203 'Can\'t add/modify a winzone: incomplete optional switch options',
7204 );
7205  
7206 }
7207  
7208 # Return list of arguments. The 1st argument is the flag to signal success
7209 return (
7210 TRUE,
7211 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
7212 $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
7213 \%initHash, \%removeHash,
7214 @args
7215 );
7216 }
7217  
7218 sub extractZoneModelSwitches {
7219  
7220 # Called by GA::Cmd::AddZoneModel->do and ModifyZoneModel->do
7221 # Extracts the switch options these commands have in common
7222 # Checks that each pattern found is valid, and that the compulsory switch options are
7223 # present
7224 #
7225 # Expected arguments
7226 # $session - The calling function's GA::Session
7227 # $inputString - What the user actually typed (e.g.
7228 # ';azl -p 10 10 -s 10 10');
7229 # $standardCmd - The standard version of the command, i.e. 'addzonemodel'
7230 # @args - A list of arguments specified by the calling command,
7231 # e.g. ('-p', 10, 10, '-s', 10, 10)
7232 #
7233 # Return values
7234 # Returns 'undef' on improper arguments or on failure
7235 # Otherwise returns a list of arguments in the form
7236 # (
7237 # TRUE,
7238 # $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner,
7239 # $orientation, $maxWindows, $maxVisibleWindows, $defaultWidthBlocks,
7240 # $defaultHeightBlocks, $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
7241 # $positionFlag, $sizeFlag, $singleLayerFlag, startCornerFlag,
7242 # $orientationFlag, $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag,
7243 # $defaultHeightFlag, $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag,
7244 # $gridWinmapFlag,
7245 # @args,
7246 # )
7247 # The first argument, TRUE, is the flag to signal success of this function
7248 # The final argument, @args, contain any remaining arguments after the switch options
7249 # have been extracted
7250  
7251 my ($self, $session, $inputString, $standardCmd, @args) = @_;
7252  
7253 # Local variables
7254 my (
7255 $switch, $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner,
7256 $orientation, $maxWindows, $maxVisibleWindows, $defaultWidthBlocks,
7257 $defaultHeightBlocks, $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
7258 $positionFlag, $sizeFlag, $singleLayerFlag, $startCornerFlag, $orientationFlag,
7259 $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag, $defaultHeightFlag,
7260 $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag, $gridWinmapFlag,
7261 );
7262  
7263 # Check for improper arguments
7264 if (! defined $session || ! defined $inputString || ! defined $standardCmd) {
7265  
7266 return $self->improper($session, $inputString);
7267 }
7268  
7269 # Extract compulsory switches (optional for ;modifyzonemodel)
7270 ($switch, $xPosBlocks, $yPosBlocks, @args) = $self->extract('-p', 2, @args);
7271 if (defined $switch) {
7272  
7273 $positionFlag = TRUE;
7274 }
7275  
7276 ($switch, $widthBlocks, $heightBlocks, @args) = $self->extract('-s', 2, @args);
7277 if (defined $switch) {
7278  
7279 $sizeFlag = TRUE;
7280 }
7281  
7282 # Extract optional switches
7283 ($switch, @args) = $self->extract('-l', 0, @args);
7284 if (defined $switch) {
7285  
7286 $singleLayerFlag = TRUE;
7287 }
7288  
7289 ($switch, $startCorner, @args) = $self->extract('-c', 1, @args);
7290 if (defined $switch) {
7291  
7292 $startCornerFlag = TRUE;
7293 }
7294  
7295 ($switch, $orientation, @args) = $self->extract('-o', 1, @args);
7296 if (defined $switch) {
7297  
7298 $orientationFlag = TRUE;
7299 }
7300  
7301 ($switch, $maxWindows, @args) = $self->extract('-m', 1, @args);
7302 if (defined $switch) {
7303  
7304 $maxWindowFlag = TRUE;
7305 }
7306  
7307 ($switch, $maxVisibleWindows, @args) = $self->extract('-v', 1, @args);
7308 if (defined $switch) {
7309  
7310 $maxVisibleWindowFlag = TRUE;
7311 }
7312  
7313 ($switch, $defaultWidthBlocks, @args) = $self->extract('-w', 1, @args);
7314 if (defined $switch) {
7315  
7316 $defaultWidthFlag = TRUE;
7317 }
7318  
7319 ($switch, $defaultHeightBlocks, @args) = $self->extract('-h', 1, @args);
7320 if (defined $switch) {
7321  
7322 $defaultHeightFlag = TRUE;
7323 }
7324  
7325 ($switch, $ownerID, @args) = $self->extract('-i', 1, @args);
7326 if (defined $switch) {
7327  
7328 $ownerIDFlag = TRUE;
7329 }
7330  
7331 ($switch, $enabledWinmap, @args) = $self->extract('-a', 1, @args);
7332 if (defined $switch) {
7333  
7334 $enabledWinmapFlag = TRUE;
7335 }
7336  
7337 ($switch, $disabledWinmap, @args) = $self->extract('-d', 1, @args);
7338 if (defined $switch) {
7339  
7340 $disabledWinmapFlag = TRUE;
7341 }
7342  
7343 ($switch, $gridWinmap, @args) = $self->extract('-g', 1, @args);
7344 if (defined $switch) {
7345  
7346 $gridWinmapFlag = TRUE;
7347 }
7348  
7349 # Check compulsory switch options (optional for ;modifyzonemodel)
7350 if (
7351 $standardCmd eq 'addzonemodel'
7352 && (
7353 ! $positionFlag || ! $sizeFlag || ! defined $xPosBlocks || ! defined $yPosBlocks
7354 || ! defined $widthBlocks || ! defined $heightBlocks
7355 )
7356 ) {
7357 return $self->error(
7358 $session, $inputString,
7359 'Can\'t add/modify a zone model: missing compulsory switch options',
7360 );
7361  
7362 } elsif (
7363 $standardCmd eq 'modifyzonemodel'
7364 && (
7365 (
7366 $positionFlag && (! defined $xPosBlocks || ! defined $yPosBlocks)
7367 ) || (
7368 $sizeFlag && (! defined $widthBlocks || ! defined $heightBlocks)
7369 )
7370 )
7371 ) {
7372 return $self->error(
7373 $session, $inputString,
7374 'Can\'t add/modify a zone model: incomplete optional switch options',
7375 );
7376  
7377 # Check optional switch options
7378 } elsif (
7379  
7380 $startCornerFlag
7381 && (
7382 ! defined $startCorner
7383 || (
7384 $startCorner ne 'top_left' && $startCorner ne 'top_right'
7385 && $startCorner ne 'bottom_left' && $startCorner ne 'bottom_right'
7386 )
7387 )
7388 ) {
7389 return $self->error(
7390 $session, $inputString,
7391 'Can\'t add/modify a zone model: invalid start corner settings',
7392 );
7393  
7394 } elsif (
7395  
7396 $orientationFlag
7397 && (
7398 ! defined $orientation
7399 || (
7400 $orientation ne 'horizontal' && $orientation ne 'vertical'
7401 )
7402 )
7403 ) {
7404 return $self->error(
7405 $session, $inputString,
7406 'Can\'t add/modify a zone model: invalid orientation settings',
7407 );
7408  
7409 } elsif (defined $maxWindowFlag && (!($maxWindows =~ /\D/) || $maxWindows < 0)) {
7410  
7411 return $self->error(
7412 $session, $inputString,
7413 'Can\'t add/modify a zone model: invalid max window settings',
7414 );
7415  
7416 } elsif (
7417  
7418 $maxVisibleWindowFlag
7419 && (! ($maxVisibleWindows =~ /\D/))
7420 ) {
7421 return $self->error(
7422 $session, $inputString,
7423 'Can\'t add/modify a zone model: invalid max visible window settings',
7424 );
7425  
7426 } elsif (
7427  
7428 $defaultWidthFlag
7429 && (
7430 ! ($defaultWidthBlocks =~ /\D/)
7431 || $defaultWidthBlocks > 60
7432 )
7433 ) {
7434 return $self->error(
7435 $session, $inputString,
7436 'Can\'t add/modify a zone model: invalid default width settings',
7437 );
7438  
7439 } elsif (
7440 $defaultHeightFlag
7441 && (
7442 ! ($defaultHeightBlocks =~ /\D/)
7443 || $defaultHeightBlocks > 60
7444 )
7445 ) {
7446 return $self->error(
7447 $session, $inputString,
7448 'Can\'t add/modify a zone model: invalid default height settings',
7449 );
7450 }
7451  
7452 # Return list of arguments. The 1st argument is the flag to signal success
7453 return (
7454 TRUE,
7455 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner, $orientation,
7456 $maxWindows, $maxVisibleWindows, $defaultWidthBlocks, $defaultHeightBlocks,
7457 $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
7458 $positionFlag, $sizeFlag, $singleLayerFlag, $startCornerFlag, $orientationFlag,
7459 $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag, $defaultHeightFlag,
7460 $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag, $gridWinmapFlag,
7461 @args
7462 );
7463 }
7464  
7465 ##################
7466 # Accessors - set
7467  
7468 sub add_userCmd {
7469  
7470 my ($self, $cmd, $check) = @_;
7471  
7472 # Local variables
7473 my @list;
7474  
7475 # Check for improper arguments
7476 if (! defined $cmd || defined $check) {
7477  
7478 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_userCmd', @_);
7479 }
7480  
7481 @list = ($self->userCmdList, $cmd);
7482  
7483 # Sort in order of size
7484 @list = sort {
7485 if (length($a) == length($b)) {
7486 return (lc($a) cmp lc($b));
7487 } else {
7488 return length($a) <=> length($b);
7489 }
7490 } (@list);
7491  
7492 $self->ivPoke('userCmdList', @list);
7493  
7494 return 1;
7495 }
7496  
7497 sub del_userCmd {
7498  
7499 my ($self, $cmd, $check) = @_;
7500  
7501 # Local variables
7502 my @list;
7503  
7504 # Check for improper arguments
7505 if (! defined $cmd || defined $check) {
7506  
7507 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_userCmd', @_);
7508 }
7509  
7510 if ($cmd eq $self->standardCmd) {
7511  
7512 # Can't delete the corresponding user command
7513 return undef;
7514  
7515 } else {
7516  
7517 foreach my $item ($self->userCmdList) {
7518  
7519 if ($item ne $cmd) {
7520  
7521 push (@list, $item);
7522 }
7523 }
7524  
7525 $self->ivPoke('userCmdList', @list);
7526  
7527 return 1;
7528 }
7529 }
7530  
7531 sub reset_userCmd {
7532  
7533 my ($self, $check) = @_;
7534  
7535 # Local variables
7536 my @list;
7537  
7538 # Check for improper arguments
7539 if (defined $check) {
7540  
7541 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_userCmd', @_);
7542 }
7543  
7544 # Reset the list
7545 $self->ivPoke('usrCmdList', $self->defaultUserCmdList);
7546  
7547 return 1;
7548 }
7549  
7550 ##################
7551 # Accessors - get
7552  
7553 sub standardCmd
7554 { $_[0]->{standardCmd} }
7555  
7556 sub defaultUserCmdList
7557 { my $self = shift; return @{$self->{defaultUserCmdList}}; }
7558 sub userCmdList
7559 { my $self = shift; return @{$self->{userCmdList}}; }
7560  
7561 sub descrip
7562 { $_[0]->{descrip} }
7563 sub builtInFlag
7564 { $_[0]->{builtInFlag} }
7565 sub disconnectFlag
7566 { $_[0]->{disconnectFlag} }
7567 sub noBracketFlag
7568 { $_[0]->{noBracketFlag} }
7569 }
7570  
7571 { package Games::Axmud::Generic::ConfigWin;
7572  
7573 use strict;
7574 use warnings;
7575 # use diagnostics;
7576  
7577 use Glib qw(TRUE FALSE);
7578  
7579 our @ISA = qw(
7580 Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud
7581 );
7582  
7583 ##################
7584 # Constructors
7585  
7586 sub new {
7587  
7588 # Called by GA::Generic::Win->createFreeWin
7589 # Creates a new instance of a 'config' window (any 'free' window object inheriting from this
7590 # object, namely 'edit' windows and 'pref' windows)
7591 #
7592 # Expected arguments
7593 # $number - Unique number for this window object
7594 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
7595 # should be created
7596 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
7597 # 'free' window object. When this window opens/closes, the owner is
7598 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
7599 # functions
7600 #
7601 # Optional arguments
7602 # $session - The GA::Session from which this function was called. 'undef' if the
7603 # calling function didn't specify a session and $owner's ->session IV
7604 # is also 'undef'
7605 # $title - A string to use as the window title. If 'undef', a generic title is
7606 # used
7607 # $editObj - The object to be edited in the window (for 'edit' windows only;
7608 # should be 'undef' for 'pref' windows)
7609 # $tempFlag - Flag set to TRUE if $editObj is either temporary, or has not yet been
7610 # added to any registry (usually because the user needs to name it
7611 # first). Set to FALSE (or 'undef') otherwise. Ignored if $editObj is
7612 # not specified
7613 # %configHash - Hash containing any number of key-value pairs needed for this
7614 # particular 'config' window; for example, for example,
7615 # GA::PrefWin::TaskStart uses it to specify a task name and type.
7616 # Set to an empty hash if not required
7617 # - This type of window object recognises these initialisation settings:
7618 #
7619 # ...
7620 #
7621 # Return values
7622 # 'undef' on improper arguments
7623 # Blessed reference to the newly-created object on success
7624  
7625 my (
7626 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
7627 %configHash,
7628 ) = @_;
7629  
7630 # Local variables
7631 my ($winType, $winName, $winWidth, $winHeight);
7632  
7633 # Check for improper arguments
7634 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
7635  
7636 return $axmud::CLIENT->writeImproper($class . '->new', @_);
7637 }
7638  
7639 # Set the values to use for some standard window IVs
7640 if ($editObj) {
7641  
7642 $winType = 'edit';
7643 $winName = 'edit';
7644 if (! defined $title) {
7645  
7646 $title = 'Edit window';
7647 }
7648  
7649 } else {
7650  
7651 $winType = 'pref';
7652 $winName = 'pref';
7653 if (! defined $title) {
7654  
7655 $title = 'Preference window';
7656 }
7657 }
7658  
7659 $winWidth = $axmud::CLIENT->customFreeWinWidth;
7660 if ($axmud::CLIENT->configWinIndexFlag) {
7661  
7662 $winWidth += $axmud::CLIENT->customConfigWinIndexWidth;
7663 }
7664  
7665 # For the benefit of MS Windows and its enormous buttons, increase the height of all
7666 # 'config' windows a little (this removes scrollbars in almost all tabs)
7667 $winHeight = $axmud::CLIENT->customFreeWinHeight;
7668 if (
7669 $^O eq 'MSWin32'
7670 && $axmud::CLIENT->customFreeWinHeight eq $axmud::CLIENT->constFreeWinHeight
7671 ) {
7672 $winHeight += 30;
7673 }
7674  
7675 # Setup
7676 my $self = {
7677 _objName => $winType . '_win_' . $number,
7678 _objClass => $class,
7679 _parentFile => undef, # No parent file object
7680 _parentWorld => undef, # No parent file object
7681 _privFlag => TRUE, # All IVs are private
7682  
7683 # Standard window object IVs
7684 # --------------------------
7685  
7686 # Unique number for this window object
7687 number => $number,
7688 # The window category - 'grid' or 'free'
7689 winCategory => 'free',
7690 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
7691 winType => $winType,
7692 # A name for the window (for 'config' windows, the same as the window type)
7693 winName => $winName,
7694 # The GA::Obj::Workspace object for the workspace in which this window is created
7695 workspaceObj => $workspaceObj,
7696 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
7697 # object. When this window opens/closes, the owner is informed via calls to its
7698 # ->add_childFreeWin / ->del_childFreeWin functions
7699 owner => $owner,
7700 # The GA::Session from which this function was called. 'undef' if the calling function
7701 # didn't specify a session and $owner's ->session IV is also 'undef'
7702 session => $session,
7703 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
7704 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
7705 # displayed in a 'dialogue' window)
7706 pseudoCmdMode => 'win_error',
7707  
7708 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
7709 # parent 'main' window's Gtk3::Window
7710 # The code should use this IV when it wants to do something to the window itself
7711 # (minimise it, make it active, etc)
7712 winWidget => undef,
7713 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
7714 # the parent GA::Table::PseudoWin table object
7715 # The code should use this IV when it wants to add, modify or remove widgets inside the
7716 # window itself
7717 winBox => undef,
7718 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
7719 # FALSE if not
7720 enabledFlag => FALSE,
7721 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
7722 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
7723 visibleFlag => TRUE,
7724 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
7725 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
7726 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
7727 childFreeWinHash => {},
7728 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
7729 # window is informed via a call to $self->del_childFreeWin
7730 # When the child is destroyed, this window might want to call some of its own functions
7731 # to update various widgets and/or IVs, in which case this window adds an entry to
7732 # this hash; a hash in the form
7733 # $childDestroyHash{unique_number} = list_reference
7734 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
7735 # reference to a list in groups of 2, in the form
7736 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
7737 childDestroyHash => {},
7738  
7739 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
7740 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
7741 # area)
7742 packingBox => undef, # Gtk3::VBox
7743  
7744 # Standard IVs for 'free' windows
7745  
7746 # The window's default size, in pixels
7747 widthPixels => $winWidth,
7748 heightPixels => $winHeight,
7749 # Default border/item spacing sizes used in the window, in pixels
7750 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
7751 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
7752  
7753 # A string to use as the window title. If 'undef', a generic title is used
7754 title => $title,
7755 # Hash containing any number of key-value pairs needed for this particular 'config'
7756 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
7757 # name and type. Set to an empty hash if not required
7758 configHash => {%configHash},
7759  
7760 # Standard IVs for 'config' windows
7761  
7762 # Widgets
7763 hPaned => undef, # Gtk3::HPaned
7764 scroller => undef, # Gtk3::ScrolledWindow
7765 treeStore => undef, # Gtk3::TreeStore
7766 treeView => undef, # Gtk3::TreeView
7767 vBox => undef, # Gtk3::VBox
7768 notebook => undef, # Gtk3::Notebook
7769 hBox => undef, # Gtk3::HBox
7770 okButton => undef, # Gtk3::Button
7771 cancelButton => undef, # Gtk3::Button
7772 resetButton => undef, # Gtk3::Button
7773 saveButton => undef, # Gtk3::Button
7774  
7775 # The standard grid size for the notebook (any 'edit'/'pref' window can use a different
7776 # size, if it wants)
7777 gridSize => 12,
7778  
7779 # The object to be edited in the window (for 'edit' windows only; should be 'undef' for
7780 # 'pref' windows)
7781 editObj => $editObj,
7782 # Flag set to TRUE if $editObj is either temporary, or has not yet been added to any
7783 # registry (usually because the user needs to name it first). Set to FALSE
7784 # (or 'undef') otherwise. Ignored if $editObj is not specified
7785 tempFlag => $tempFlag,
7786 # Flag that can be set to TRUE (usually by $self->setupNotebook or ->expandNotebook) if
7787 # $editObj is a current object (e.g. if it is a current profile); set to FALSE at all
7788 # other times
7789 currentFlag => FALSE,
7790 # For 'edit' windows, a hash of IVs in $editObj that should be changed. If no changes
7791 # have been made in the 'edit' window, the hash is empty; otherwise the hash contains
7792 # the new values for each IV to be modified
7793 # Hash in the form:
7794 # ->editHash{iv_name} = scalar;
7795 # ->editHash{iv_name} = list_reference;
7796 # ->editHash{iv_name} = hash_reference;
7797 # For 'pref' windows, a hash of key-value pairs set by the window's widgets;
7798 # $self->enableButtons can access this hash to perform any necessary actions
7799 # ('pref' windows don't make a call to ->saveChanges)
7800 editHash => {},
7801 # Hash containing any number of key-value pairs needed for this particular
7802 # 'edit'/'pref' window; for example, GA::PrefWin::TaskStart uses it to specify a task
7803 # name and type. Set to an empty hash if not required
7804 editConfigHash => \%configHash,
7805  
7806 # In the index on the left-hand side of the window, the pointer (Gtk3::TreeIter) for
7807 # the $self->notebook tab that's currently being drawn
7808 indexPointer => undef,
7809 # A hash of inner Gtk3::Notebooks. Keys are a tab number in the outer notebook (first
7810 # tab is #0); the corresponding values are the inner notebook for that tab, or
7811 # 'undef' if the tab has no inner notebook
7812 innerNotebookHash => {},
7813 };
7814  
7815 # Bless the object into existence
7816 bless $self, $class;
7817  
7818 return $self;
7819 }
7820  
7821 ##################
7822 # Methods
7823  
7824 # Standard window object functions
7825  
7826 # sub winSetup {} # Inherited from GA::Generic::FreeWin
7827  
7828 sub winEnable {
7829  
7830 # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup
7831 # After the Gtk3::Window has been setup and moved into position, makes it visible
7832 #
7833 # Expected arguments
7834 # (none besides $self)
7835 #
7836 # Return values
7837 # 'undef' on improper arguments or if $self->editObj is the wrong type of object
7838 # 1 on success
7839  
7840 my ($self, $check) = @_;
7841  
7842 # Check for improper arguments
7843 if (defined $check) {
7844  
7845 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
7846 }
7847  
7848 # For 'edit' windows, check that $self->editObj is of the right type. For 'pref' windows,
7849 # $self->editObj is not set, so the check always succeeds
7850 if (! $self->checkEditObj()) {
7851  
7852 return undef;
7853 }
7854  
7855 # Make the window appear on the desktop
7856 $self->winShowAll($self->_objClass . '->winEnable');
7857 $self->ivPoke('enabledFlag', TRUE);
7858  
7859 return 1;
7860 }
7861  
7862 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
7863  
7864 # sub winDestroy {} # Inherited from GA::Generic::FreeWin
7865  
7866 # sub winShowAll {} # Inherited from GA::Generic::Win
7867  
7868 sub drawWidgets {
7869  
7870 # Called by $self->winSetup
7871 # Sets up the 'edit'/'pref' window with its standard widgets
7872 #
7873 # Expected arguments
7874 # (none besides $self)
7875 #
7876 # Return values
7877 # 'undef' on improper arguments
7878 # 1 otherwise
7879  
7880 my ($self, $check) = @_;
7881  
7882 # Check for improper arguments
7883 if (defined $check) {
7884  
7885 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
7886 }
7887  
7888 if (! $axmud::CLIENT->configWinIndexFlag) {
7889  
7890 # Create a packing box
7891 my $packingBox = Gtk3::VBox->new(FALSE, 0);
7892 $self->winBox->add($packingBox);
7893 $packingBox->set_border_width(0);
7894  
7895 # Add a notebook at the top
7896 my $notebook = Gtk3::Notebook->new();
7897 $packingBox->pack_start($notebook, TRUE, TRUE, 0);
7898 $notebook->set_scrollable(TRUE);
7899 $notebook->popup_enable();
7900  
7901 # Add a button strip at the bottom, in a horizontal packing box
7902 my $hBox = Gtk3::HBox->new(FALSE, 0);
7903 $packingBox->pack_end($hBox, FALSE, FALSE, $self->spacingPixels);
7904  
7905 # Create Reset/Save/Cancel/OK buttons
7906 my ($okButton, $cancelButton, $resetButton, $saveButton) = $self->enableButtons($hBox);
7907  
7908 # Update IVs
7909 $self->ivPoke('packingBox', $packingBox);
7910 $self->ivPoke('notebook', $notebook);
7911 $self->ivPoke('hBox', $hBox);
7912 $self->ivPoke('okButton', $okButton);
7913 $self->ivPoke('cancelButton', $cancelButton);
7914 $self->ivPoke('resetButton', $resetButton);
7915 $self->ivPoke('saveButton', $saveButton);
7916  
7917 # Set up the notebook with its tabs
7918 $self->setupNotebook();
7919  
7920 } else {
7921  
7922 # Create a packing box
7923 my $packingBox = Gtk3::VBox->new(FALSE, 0);
7924 $self->winBox->add($packingBox);
7925 $packingBox->set_border_width(0);
7926  
7927 # Create a horizontal pane, with a treeview on the left, and a second vbox on the right
7928 my $hPaned = Gtk3::HPaned->new();
7929 $packingBox->pack_start($hPaned, TRUE, TRUE, 0);
7930 $hPaned->set_position($axmud::CLIENT->customConfigWinIndexWidth);
7931  
7932 # Create the treeview on the left
7933 my $scroller = Gtk3::ScrolledWindow->new;
7934 $hPaned->add1($scroller);
7935 $scroller->set_policy('automatic', 'automatic');
7936  
7937 my $treeStore = Gtk3::TreeStore->new( ['Glib::String', 'Glib::Int', 'Glib::Int'] );
7938 my $treeView = Gtk3::TreeView->new($treeStore);
7939 $scroller->add($treeView);
7940 # Enable interactive search
7941 $treeView->set_enable_search(TRUE);
7942  
7943 # Append columns to the treeview
7944 my $column = Gtk3::TreeViewColumn->new_with_attributes(
7945 'Index',
7946 Gtk3::CellRendererText->new,
7947 markup => 0,
7948 );
7949 $treeView->append_column(
7950 Gtk3::TreeViewColumn->new_with_attributes(
7951 'Index',
7952 Gtk3::CellRendererText->new,
7953 markup => 0,
7954 ),
7955 );
7956  
7957 for (my $i = 1; $i < 3; $i++) {
7958  
7959 my $column = Gtk3::TreeViewColumn->new_with_attributes(
7960 'invisible',
7961 Gtk3::CellRendererText->new,
7962 markup => $i,
7963 );
7964  
7965 $column->set_visible(FALSE);
7966 $treeView->append_column($column);
7967 }
7968  
7969 # Make the branches of the treeview clickable
7970 $treeView->signal_connect('row_activated' => sub {
7971  
7972 my ($treeView, $path, $column) = @_;
7973  
7974 my ($iter, $outer, $inner, $innerNotebook);
7975  
7976 $iter = $self->treeStore->get_iter($path);
7977 if ($iter) {
7978  
7979 $outer = $self->treeStore->get($self->treeStore->get_iter($path), 1);
7980 $inner = $self->treeStore->get($self->treeStore->get_iter($path), 2);
7981  
7982 $self->notebook->set_current_page($outer);
7983 $innerNotebook = $self->ivShow('innerNotebookHash', $outer);
7984 # (Not all tabs have their own inner notebook)
7985 if ($innerNotebook) {
7986  
7987 $innerNotebook->set_current_page($inner);
7988 }
7989 }
7990 });
7991  
7992 # Create the vbox on the right, with a notebook at the top, and a button strip at the
7993 # bottom
7994 my $vBox = Gtk3::VBox->new(FALSE, 0);
7995 $hPaned->add2($vBox);
7996  
7997 # Add the notebook
7998 my $notebook = Gtk3::Notebook->new();
7999 $vBox->pack_start($notebook, TRUE, TRUE, 0);
8000 $notebook->set_scrollable(TRUE);
8001 $notebook->popup_enable();
8002  
8003 # Add a button strip at the bottom, in a horizontal packing box
8004 my $hBox = Gtk3::HBox->new(FALSE, 0);
8005 $vBox->pack_end($hBox, FALSE, FALSE, $self->spacingPixels);
8006  
8007 # Create Reset/Save/Cancel/OK buttons
8008 my ($okButton, $cancelButton, $resetButton, $saveButton) = $self->enableButtons($hBox);
8009  
8010 # Update IVs
8011 $self->ivPoke('packingBox', $packingBox);
8012 $self->ivPoke('hPaned', $hPaned);
8013 $self->ivPoke('scroller', $scroller);
8014 $self->ivPoke('treeStore', $treeStore);
8015 $self->ivPoke('treeView', $treeView);
8016 $self->ivPoke('vBox', $vBox);
8017 $self->ivPoke('notebook', $notebook);
8018 $self->ivPoke('hBox', $hBox);
8019 $self->ivPoke('okButton', $okButton);
8020 $self->ivPoke('cancelButton', $cancelButton);
8021 $self->ivPoke('resetButton', $resetButton);
8022 $self->ivPoke('saveButton', $saveButton);
8023  
8024 # Set up the notebook with its tabs
8025 $self->setupNotebook();
8026  
8027 # Fully expand the index
8028 $self->treeView->expand_all();
8029 }
8030  
8031 return 1;
8032 }
8033  
8034 # sub redrawWidgets {} # Inherited from GA::Generic::Win
8035  
8036 # ->signal_connects
8037  
8038 sub setDeleteEvent {
8039  
8040 # Called by $self->winSetup
8041 # Set up a ->signal_connect to watch out for the user manually closing the 'config' window
8042 #
8043 # Expected arguments
8044 # (none besides $self)
8045 #
8046 # Return values
8047 # 'undef' on improper arguments
8048 # 1 otherwise
8049  
8050 my ($self, $check) = @_;
8051  
8052 # Check for improper arguments
8053 if (defined $check) {
8054  
8055 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
8056 }
8057  
8058 $self->winBox->signal_connect('delete-event' => sub {
8059  
8060 # Prevent Gtk3 from taking action directly. Instead redirect the request to
8061 # $self->winDestroy
8062 return $self->winDestroy();
8063 });
8064  
8065 return 1;
8066 }
8067  
8068 # Other functions
8069  
8070 sub checkEditObj {
8071  
8072 # Called by $self->winEnable
8073 # For 'edit' windows, checks that the object stored in $self->editObj is the correct class
8074 # of object. For 'pref' windows, the check always succeeds (because 'pref' windows don't
8075 # have an ->editObj)
8076 #
8077 # Expected arguments
8078 # (none besides $self)
8079 #
8080 # Return values
8081 # 'undef' on improper arguments or if the check fails
8082 # 1 if the check succeeds
8083  
8084 my ($self, $check) = @_;
8085  
8086 # Check for improper arguments
8087 if (defined $check) {
8088  
8089 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEditObj', @_);
8090 }
8091  
8092 # (Everything inherits from Games::Axmud, so in this generic function the check always
8093 # succeeds)
8094 if ($self->editObj && ! $self->editObj->isa('Games::Axmud')) {
8095 return undef;
8096 } else {
8097 return 1;
8098 }
8099 }
8100  
8101 sub enableButtons {
8102  
8103 # Called by $self->drawWidgets
8104 # Creates the OK/Cancel/Save/Reset buttons at the bottom of the window
8105 # Individual 'edit'/'pref' windows almost always inherit the generic ->winEnable method,
8106 # but can use their own $self->enableButtons (rather than inherit this one) if they don't
8107 # need all four buttons
8108 #
8109 # Expected arguments
8110 # $hBox - The horizontal packing box in which the buttons live (not yet stored as
8111 # an IV)
8112 #
8113 # Return values
8114 # An empty list on improper arguments
8115 # Otherwise, a list containing the four Gtk::Button objects created
8116  
8117 my ($self, $hBox, $check) = @_;
8118  
8119 # Local variables
8120 my @emptyList;
8121  
8122 # Check for improper arguments
8123 if (! defined $hBox || defined $check) {
8124  
8125 $axmud::CLIENT->writeImproper($self->_objClass . '->enableButtons', @_);
8126 return @emptyList;
8127 }
8128  
8129 # Create the OK button, desensitised if $self->tempFlag is TRUE
8130 my $okButton = Gtk3::Button->new('OK');
8131 $hBox->pack_end($okButton, FALSE, FALSE, $self->borderPixels);
8132 $okButton->get_child->set_width_chars(10);
8133 $okButton->signal_connect('clicked' => sub {
8134  
8135 $self->buttonOK();
8136 });
8137 $okButton->set_tooltip_text('Accept changes');
8138 if ($self->tempFlag) {
8139  
8140 $okButton->set_state('insensitive');
8141 }
8142  
8143 # Create the Cancel button (never desensitised)
8144 my $cancelButton = Gtk3::Button->new('Cancel');
8145 $hBox->pack_end($cancelButton, FALSE, FALSE, $self->spacingPixels);
8146 $cancelButton->get_child->set_width_chars(10);
8147 $cancelButton->signal_connect('clicked' => sub {
8148  
8149 $self->buttonCancel();
8150 });
8151 $cancelButton->set_tooltip_text('Cancel changes');
8152  
8153 # Create the Reset button, desensitised if $self->tempFlag is TRUE
8154 my $resetButton = Gtk3::Button->new('Reset');
8155 $hBox->pack_start($resetButton, FALSE, FALSE, $self->borderPixels);
8156 $resetButton->get_child->set_width_chars(10);
8157 $resetButton->signal_connect('clicked' => sub {
8158  
8159 $self->buttonReset();
8160 });
8161 $resetButton->set_tooltip_text('Reset changes without closing the window');
8162 if ($self->tempFlag) {
8163  
8164 $resetButton->set_state('insensitive');
8165 }
8166  
8167 # Create the Save button, desensitised if $self->tempFlag is TRUE
8168 my $saveButton = Gtk3::Button->new('Save');
8169 $hBox->pack_start($saveButton, FALSE, FALSE, $self->borderPixels);
8170 $saveButton->get_child->set_width_chars(10);
8171 $saveButton->signal_connect('clicked' => sub {
8172  
8173 $self->buttonSave();
8174 });
8175 $saveButton->set_tooltip_text('Save changes without closing the window');
8176 if ($self->tempFlag) {
8177  
8178 $saveButton->set_state('insensitive');
8179 }
8180  
8181 return ($okButton, $cancelButton, $resetButton, $saveButton);
8182 }
8183  
8184 sub enableSingleButton {
8185  
8186 # Called by $self->enableButtons when only a single 'OK' button is required (rather than
8187 # the usual four)
8188 # Creates the OK button at the bottom of the window
8189 #
8190 # Expected arguments
8191 # $hBox - The horizontal packing box in which the buttons live
8192 #
8193 # Return values
8194 # An empty list on improper arguments
8195 # Otherwise, a list containing the Gtk::Button object created
8196  
8197 my ($self, $hBox, $check) = @_;
8198  
8199 # Local variables
8200 my @emptyList;
8201  
8202 # Check for improper arguments
8203 if (! defined $hBox || defined $check) {
8204  
8205 $axmud::CLIENT->writeImproper($self->_objClass . '->enableSingleButton', @_);
8206 return @emptyList;
8207 }
8208  
8209 # Create the OK button
8210 my $okButton = Gtk3::Button->new('OK');
8211 $hBox->pack_end($okButton, FALSE, FALSE, $self->borderPixels);
8212 $okButton->get_child->set_width_chars(10);
8213 $okButton->signal_connect('clicked' => sub {
8214  
8215 $self->buttonOK();
8216 });
8217 $okButton->set_tooltip_text('Close window');
8218  
8219 # This object doesn't edit anything, so we don't need Cancel/Reset/Edit buttons
8220 return ($okButton);
8221 }
8222  
8223 sub setupNotebook {
8224  
8225 # Called by $self->winEnable
8226 # Creates the first tab for the notebook. The remaining tabs are created by
8227 # $self->expandNotebook
8228 #
8229 # Expected arguments
8230 # (none besides $self)
8231 #
8232 # Return values
8233 # 'undef' on improper arguments
8234 # 1 otherwise
8235  
8236 my ($self, $check) = @_;
8237  
8238 # Check for improper arguments
8239 if (defined $check) {
8240  
8241 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupNotebook', @_);
8242 }
8243  
8244 # Tab setup, using the standard grid size
8245 # N.B. No sub-headings
8246 my $grid = $self->addTab($self->notebook, '_Name');
8247  
8248 # Set up the rest of the tab
8249 $self->nameTab($grid);
8250  
8251 # Set up the remaining tabs
8252 $self->expandNotebook();
8253  
8254 # Tab complete
8255 return 1;
8256 }
8257  
8258 sub expandNotebook {
8259  
8260 # Called by $self->setupNotebook
8261 # Set up additional tabs for the notebook, depending on which type of object is being edited
8262 # Because this is the generic function, no additional tabs are actually set up here. This
8263 # generic function is usually only called for 'edit'/'pref' windows which have a single
8264 # tab (such as GA::EditWin::Interface::Active)
8265 #
8266 # Expected arguments
8267 # (none besides $self)
8268 #
8269 # Return values
8270 # 'undef' on improper arguments
8271 # 1 otherwise
8272  
8273 my ($self, $check) = @_;
8274  
8275 # Check for improper arguments
8276 if (defined $check) {
8277  
8278 return $axmud::CLIENT->writeImproper($self->_objClass . '->expandNotebook', @_);
8279 }
8280  
8281 # $self->additionalTab();
8282  
8283 return 1;
8284 }
8285  
8286 sub saveChanges {
8287  
8288 # Called by $self->buttonOK and $self->buttonSave (usually for 'edit' windows only, not
8289 # 'pref' windows)
8290 # Saves any changes made to data stored by the edit object
8291 #
8292 # Expected arguments
8293 # (none besides $self)
8294 #
8295 # Return values
8296 # 'undef' on improper arguments
8297 # 1 otherwise
8298  
8299 my ($self, $check) = @_;
8300  
8301 # Check for improper arguments
8302 if (defined $check) {
8303  
8304 return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
8305 }
8306  
8307 if ($self->editHash) {
8308  
8309 # Store the changes the user has made
8310 foreach my $key ($self->ivKeys('editHash')) {
8311  
8312 $self->editObj->{$key} = $self->ivShow('editHash', $key);
8313 }
8314  
8315 # The changes can now be cleared
8316 $self->ivEmpty('editHash');
8317  
8318 # Mark the object's corresponding file object as needing to be saved, if it exists
8319 if ($self->editObj->_parentFile) {
8320  
8321 $self->editObj->doModify('saveChanges');
8322 }
8323  
8324 # Update the current session's data viewer window, if it is open
8325 if ($self->session->viewerWin) {
8326  
8327 $self->session->viewerWin->updateNotebook();
8328 }
8329 }
8330  
8331 return 1;
8332 }
8333  
8334 # Add widgets
8335  
8336 sub addTab {
8337  
8338 # Adds a tab to the notebook, creating a scroller and a grid, all with standardised sizes
8339 #
8340 # Expected arguments
8341 # $notebook - The Gtk3::Notebook object to which this tab will be added
8342 # $mnemonic - A mnemonic string, e.g. 'N_ame'
8343 #
8344 # Optional arguments
8345 # $headingListRef - Reference to an optional list of sub-headings (which usually appear in
8346 # bold in the tab). If specified, the headings appear in the index
8347 # $columnSpaceWidth, $columnSpaceHeight
8348 # - The spacing between columns/rows, in pixels. If either of both are set
8349 # 'undef', the default size is used ($self->spacingPixels)
8350 #
8351 # Return values
8352 # 'undef' on improper arguments
8353 # Otherwise returns the Gtk3::Grid created
8354  
8355 my (
8356 $self, $notebook, $mnemonic, $headingListRef, $columnSpaceWidth, $columnSpaceHeight,
8357 $check,
8358 ) = @_;
8359  
8360 # Check for improper arguments
8361 if (! defined $notebook || ! defined $mnemonic || defined $check) {
8362  
8363 return $amid::MAIN->writeImproper($self->_objClass . '->addTab', @_);
8364 }
8365  
8366 # Set default sizes
8367 if (! defined $columnSpaceWidth) {
8368  
8369 $columnSpaceWidth = $self->spacingPixels;
8370 }
8371  
8372 if (! defined $columnSpaceHeight) {
8373  
8374 $columnSpaceHeight = $self->spacingPixels;
8375 }
8376  
8377 # Tab setup
8378 my $scroller = Gtk3::ScrolledWindow->new();
8379 $scroller->set_policy('automatic', 'automatic');
8380  
8381 my $tab = Gtk3::Label->new_with_mnemonic($mnemonic);
8382 my $page = $notebook->append_page($scroller, $tab);
8383  
8384 my $grid = Gtk3::Grid->new();
8385 $scroller->add_with_viewport($grid);
8386 $grid->set_border_width($self->spacingPixels);
8387 $grid->set_column_spacing($columnSpaceWidth);
8388 $grid->set_row_spacing($columnSpaceHeight);
8389  
8390 # Update the index, if present
8391 $self->addRowToIndex($notebook, $tab, $mnemonic, $headingListRef);
8392  
8393 # Update IVs
8394 if ($notebook eq $self->notebook) {
8395  
8396 $self->ivAdd('innerNotebookHash', $page, undef);
8397 }
8398  
8399 return $grid;
8400 }
8401  
8402 sub addInnerNotebookTabs {
8403  
8404 # Adds a tab to the notebook containing an inner notebook, so that we get a second row of
8405 # tabs immediately beneath the first one
8406 #
8407 # Expected arguments
8408 # $notebook - The Gtk3::Notebook object to which this tab will be added
8409 # $mnemonic - A mnemonic string, e.g. 'N_ame'
8410 #
8411 # Optional arguments
8412 # $headingListRef - Reference to an optional list of sub-headings (which usually appear in
8413 # bold in the tab). If specified, the headings appear in the index
8414 #
8415 # Return values
8416 # 'undef' on improper arguments
8417 # Otherwise returns the Gtk3::Notebook created
8418  
8419 my ($self, $notebook, $mnemonic, $headingListRef, $check) = @_;
8420  
8421 # Check for improper arguments
8422 if (! defined $notebook || ! defined $mnemonic || defined $check) {
8423  
8424 return $axmud::CLIENT->writeImproper($self->_objClass . '->addInnerNotebookTabs', @_);
8425 }
8426  
8427 # Tab setup
8428 my $innerNotebook = Gtk3::Notebook->new();
8429 $innerNotebook->set_scrollable(TRUE);
8430 $innerNotebook->popup_enable();
8431  
8432 my $tab = Gtk3::Label->new_with_mnemonic($mnemonic);
8433 my $page = $notebook->append_page($innerNotebook, $tab);
8434  
8435 # Update the index, if present
8436 $self->addRowToIndex($notebook, $tab, $mnemonic, $headingListRef);
8437  
8438 # Update IVs
8439 $self->ivAdd('innerNotebookHash', $page, $innerNotebook);
8440  
8441 # Tab complete
8442 return $innerNotebook;
8443 }
8444  
8445 sub addRowToIndex {
8446  
8447 # Called by $self->addTab and ->addInnerNotebookTabs
8448 # Adds a row to the index (treeview)
8449 #
8450 # Expected arguments
8451 # $notebook - The Gtk3::Notebook object to which this tab will be added
8452 # $tab - The tab itself (a Gtk3::Label)
8453 # $mnemonic - A mnemonic string, e.g. 'N_ame'
8454 #
8455 # Optional arguments
8456 # $headingListRef - Reference to an optional list of sub-headings (which usually appear in
8457 # bold in the tab). If specified, the headings appear in the index
8458 #
8459 # Return values
8460 # 'undef' on improper arguments
8461 # Otherwise returns the Gtk3::Notebook created
8462  
8463 my ($self, $notebook, $tab, $mnemonic, $headingListRef, $check) = @_;
8464  
8465 # Local variables
8466 my ($tabName, $pointer, $outer, $inner);
8467  
8468 # Check for improper arguments
8469 if (! defined $notebook || ! defined $tab || ! defined $mnemonic || defined $check) {
8470  
8471 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRowToIndex', @_);
8472 }
8473  
8474 $tabName = $mnemonic;
8475 $tabName =~ s/_//g;
8476  
8477 # N.B. The previous version used three layers of nesting. It is preserved here, commented
8478 # out, in case we want to go back to it
8479 # if ($self->treeStore) {
8480 #
8481 # if ($notebook eq $self->notebook) {
8482 #
8483 # # Outer tab
8484 # $pointer = $self->treeStore->append(undef);
8485 #
8486 # $self->ivPoke('indexPointer', $pointer);
8487 # $outer = $notebook->get_n_pages() - 1;
8488 # $inner = 0;
8489 #
8490 # $self->treeStore->set(
8491 # $pointer,
8492 # [0, 1, 2], ['<b>' . $tabName . ' tab</b>', $outer, $inner] );
8493 #
8494 # } else {
8495 #
8496 # # Inner tab
8497 # $pointer = $self->treeStore->append($self->indexPointer);
8498 # $outer = $self->notebook->get_n_pages() - 1;
8499 # $inner = $notebook->get_n_pages() - 1;
8500 #
8501 # $self->treeStore->set( $pointer, [0, 1, 2], [$tabName, $outer, $inner] );
8502 # }
8503 #
8504 # # Add sub-headings, if specified
8505 # if (defined $headingListRef) {
8506 #
8507 # my $childPointer = $pointer;
8508 #
8509 # foreach my $heading (@$headingListRef) {
8510 #
8511 # my $thisPointer = $self->treeStore->append($childPointer);
8512 #
8513 # $self->treeStore->set(
8514 # $thisPointer,
8515 # [0, 1, 2],
8516 # ['<i>' . $heading . '</i>', $outer, $inner],
8517 # );
8518 # }
8519 # }
8520 # }
8521  
8522 if ($self->treeStore) {
8523  
8524 if ($notebook eq $self->notebook) {
8525  
8526 # Outer tab
8527 $pointer = $self->treeStore->append(undef);
8528  
8529 $self->ivPoke('indexPointer', $pointer);
8530 $outer = $notebook->get_n_pages() - 1;
8531 $inner = 0;
8532  
8533 $self->treeStore->set(
8534 $pointer,
8535 [0, 1, 2], ['<b>' . $tabName . ' tab</b>', $outer, $inner] );
8536  
8537 } else {
8538  
8539 # Inner tab. Don't show 'Page 1' (etc) in the index, but do show an inner tab called
8540 # 'Triggers'
8541  
8542 # ($outer and $inner are re-used below...)
8543 $outer = $self->notebook->get_n_pages() - 1;
8544 $inner = $notebook->get_n_pages() - 1;
8545  
8546 if (! ($tabName =~ m/^Page\s+\d+$/)) {
8547  
8548 $pointer = $self->treeStore->append($self->indexPointer);
8549  
8550 $self->treeStore->set( $pointer, [0, 1, 2], [$tabName, $outer, $inner] );
8551 }
8552 }
8553  
8554 # Add sub-headings, if specified
8555 if (defined $headingListRef) {
8556  
8557 foreach my $heading (@$headingListRef) {
8558  
8559 my $thisPointer = $self->treeStore->append($self->indexPointer);
8560  
8561 $self->treeStore->set(
8562 $thisPointer,
8563 [0, 1, 2],
8564 [$heading, $outer, $inner],
8565 );
8566 }
8567 }
8568 }
8569  
8570 return 1;
8571 }
8572  
8573 sub addLabel {
8574  
8575 # Adds a Gtk3::Label at the specified position in the tab's Gtk3::Grid
8576 #
8577 # Example calls:
8578 # my $label = $self->addLabel($grid, 'Some plain text',
8579 # 0, 6, 0, 1);
8580 # my $label = $self->addLabel($grid, '<b>Some pango markup text</b>',
8581 # 0, 6, 0, 1,
8582 # 0, 0.5);
8583 #
8584 # Expected arguments
8585 # $grid - The tab's Gtk3::Grid object
8586 # $text - The text to display (plain text or pango markup text)
8587 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8588 # - The position of the label in the grid
8589 #
8590 # Optional arguments
8591 # $alignLeft, $alignRight
8592 # - Used in the call to ->set_alignment; two values in the range 0-1
8593 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
8594 #
8595 # Return values
8596 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8597 # Otherwise the Gtk3::Label created
8598  
8599 my (
8600 $self, $grid, $text, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $alignLeft,
8601 $alignRight, $check
8602 ) = @_;
8603  
8604 # Check for improper arguments
8605 if (
8606 ! defined $grid || ! defined $text || ! defined $leftAttach || ! defined $rightAttach
8607 || ! defined $topAttach || ! defined $bottomAttach || defined $check
8608 ) {
8609 return $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
8610 }
8611  
8612 # Check that the position in the grid makes sense
8613 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8614  
8615 return undef;
8616 }
8617  
8618 # Set default alignment, if none specified
8619 if (! defined $alignLeft) {
8620  
8621 $alignLeft = 0;
8622 }
8623  
8624 if (! defined $alignRight) {
8625  
8626 $alignRight = 0.5;
8627 }
8628  
8629 # Create the label
8630 my $label = Gtk3::Label->new();
8631 $label->set_markup($text);
8632  
8633 # Set its alignment
8634 $label->set_alignment($alignLeft, $alignRight);
8635  
8636 # Add the label to the grid
8637 $label->set_hexpand(TRUE);
8638 $label->set_vexpand(FALSE);
8639 $grid->attach(
8640 $label,
8641 $leftAttach,
8642 $topAttach,
8643 ($rightAttach - $leftAttach),
8644 ($bottomAttach - $topAttach),
8645 );
8646  
8647 return $label;
8648 }
8649  
8650 sub addLabelFrame {
8651  
8652 # Adds a Gtk3::Label within a Gtk3::Frame (giving the appearance of text in a box) at the
8653 # specified position in the tab's Gtk3::Grid
8654 #
8655 # Example calls:
8656 # my $label = $self->addLabel($grid, 'Some plain text',
8657 # 0, 6, 0, 1);
8658 # my $label = $self->addLabel($grid, '<b>Some pango markup text</b>',
8659 # 0, 6, 0, 1,
8660 # 0, 0.5);
8661 #
8662 # Expected arguments
8663 # $grid - The tab's Gtk3::Grid object
8664 # $text - The text to display (plain text or pango markup text)
8665 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8666 # - The position of the label in the grid
8667 #
8668 # Optional arguments
8669 # $alignLeft, $alignRight
8670 # - Used in the call to ->set_alignment; two values in the range 0-1
8671 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
8672 #
8673 # Return values
8674 # An empty list of improper arguments or if the widget's position in the Gtk3::Grid is
8675 # invalid
8676 # Otherwise, a list in the form
8677 # (gtk_frame, gtk_label)
8678  
8679 my (
8680 $self, $grid, $text, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $alignLeft,
8681 $alignRight, $check
8682 ) = @_;
8683  
8684 # Local variables
8685 my @emptyList;
8686  
8687 # Check for improper arguments
8688 if (
8689 ! defined $grid || ! defined $text || ! defined $leftAttach || ! defined $rightAttach
8690 || ! defined $topAttach || ! defined $bottomAttach || defined $check
8691 ) {
8692 $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
8693 return @emptyList;
8694 }
8695  
8696 # Check that the position in the grid makes sense
8697 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8698  
8699 return @emptyList;
8700 }
8701  
8702 # Set default alignment, if none specified
8703 if (! defined $alignLeft) {
8704  
8705 $alignLeft = 0;
8706 }
8707  
8708 if (! defined $alignRight) {
8709  
8710 $alignRight = 0.5;
8711 }
8712  
8713 # Create the frame
8714 my $frame = Gtk3::Frame->new(undef);
8715 $frame->set_border_width($self->borderPixels);
8716  
8717 # Create the label
8718 my $label = Gtk3::Label->new();
8719 $frame->add($label);
8720 $label->set_markup($text);
8721  
8722 # Set its alignment
8723 $label->set_alignment($alignLeft, $alignRight);
8724  
8725 # Add the frame to the grid
8726 $frame->set_hexpand(TRUE);
8727 $frame->set_vexpand(FALSE);
8728 $grid->attach(
8729 $frame,
8730 $leftAttach,
8731 $topAttach,
8732 ($rightAttach - $leftAttach),
8733 ($bottomAttach - $topAttach),
8734 );
8735  
8736 return ($frame, $label);
8737 }
8738  
8739 sub addButton {
8740  
8741 # Adds a Gtk3::Button at the specified position in the tab's Gtk3::Grid
8742 #
8743 # Example calls:
8744 # my $button = $self->addButton($grid, 'button_name', 'tooltips', \&buttonClicked,
8745 # 0, 6, 0, 1);
8746 # my $button = $self->addButton($grid, 'button_name', 'tooltips', undef,
8747 # 0, 6, 0, 1);
8748 # my $button = $self->addButton($grid, 'button_name', '', \&buttonClicked,
8749 # 0, 6, 0, 1);
8750 #
8751 # The referenced function (if specified) receives an argument list in the form:
8752 # ($self, button_widget)
8753 #
8754 # Expected arguments
8755 # $grid - The tab's Gtk3::Grid object
8756 # $name - The name displayed on the button
8757 # $tooltips - Tooltips to use for the button; empty strings are not used
8758 # $funcRef - Reference to the function to call when the button is clicked. If 'undef',
8759 # it's up to the calling function to create a ->signal_connect method
8760 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8761 # - The position of the button in the grid
8762 #
8763 # Optional arguments
8764 # $flag - If set to TRUE, the button is marked with an image (namely
8765 # /icons/system/irreversible.png), which shows an action which can't
8766 # easily be reversed (e.g. by clicking on the main 'Cancel' button)
8767 #
8768 # Return values
8769 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8770 # Otherwise the Gtk3::Button created
8771  
8772 my (
8773 $self, $grid, $name, $tooltips, $funcRef, $leftAttach, $rightAttach, $topAttach,
8774 $bottomAttach, $flag, $check
8775 ) = @_;
8776  
8777 # Local variables
8778 my $current;
8779  
8780 # Check for improper arguments
8781 if (
8782 ! defined $grid || ! defined $name || ! defined $tooltips || ! defined $leftAttach
8783 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8784 || defined $check
8785 ) {
8786 return $axmud::CLIENT->writeImproper($self->_objClass . '->addButton', @_);
8787 }
8788  
8789 # Check that the position in the grid makes sense
8790 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8791  
8792 return undef;
8793 }
8794  
8795 # If $flag was specified, but GA::Client->irreversibleIconFlag is FALSE, we can't draw an
8796 # icon to show the irreversible action; instead, add an asterisk to the button label
8797 if ($flag && ! $axmud::CLIENT->irreversibleIconFlag) {
8798  
8799 $name = '(*) ' . $name;
8800 }
8801  
8802 # Create the button
8803 my $button = Gtk3::Button->new($name);
8804  
8805 # If a callback function was specified, use it
8806 if ($funcRef) {
8807  
8808 $button->signal_connect('clicked' => sub {
8809  
8810 &$funcRef($self, $button);
8811 });
8812 }
8813  
8814 # Use tooltips, if any were specified
8815 if ($tooltips) {
8816  
8817 $button->set_tooltip_text($tooltips);
8818 }
8819  
8820 # Use the 'irreversible' icon, if it was specified
8821 if ($flag && $axmud::CLIENT->irreversibleIconFlag) {
8822  
8823 my $image = Gtk3::Image->new_from_file(
8824 $axmud::SHARE_DIR . '/icons/system/irreversible.png',
8825 );
8826  
8827 $button->set_image($image);
8828 }
8829  
8830 # Add the button to the grid
8831 $button->set_hexpand(TRUE);
8832 $button->set_vexpand(FALSE);
8833 $grid->attach(
8834 $button,
8835 $leftAttach,
8836 $topAttach,
8837 ($rightAttach - $leftAttach),
8838 ($bottomAttach - $topAttach),
8839 );
8840  
8841 return $button;
8842 }
8843  
8844 sub addCheckButton {
8845  
8846 # Adds a Gtk3::CheckButton with an accompanying label at the specified position in the
8847 # window's Gtk3::Grid
8848 #
8849 # Example calls:
8850 # my $checkButton = $self->addCheckButton($grid, 'Click me', 'some_IV', TRUE,
8851 # 0, 6, 0, 1);
8852 # my $checkButton = $self->addCheckButton($grid, undef, 'some_IV', TRUE,
8853 # 0, 6, 0, 1);
8854 #
8855 # Expected arguments
8856 # $grid - The tab's Gtk3::Grid object
8857 # $name - A 'name' for the checkbutton (displayed next to the button); if 'undef',
8858 # no name is displayed
8859 # $iv - A string naming the IV set when the check button is toggled. If 'undef',
8860 # nothing happens when the user toggles the checkbutton; it's up to the
8861 # calling function to check the button's state
8862 # $stateFlag - Flag set to FALSE if the checkbutton's state should be 'insensitive',
8863 # TRUE if it should be 'normal'
8864 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8865 # - The position of the checkbutton in the grid
8866 #
8867 # Return values
8868 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8869 # Otherwise the Gtk3::CheckButton created
8870  
8871 my (
8872 $self, $grid, $name, $iv, $stateFlag, $leftAttach, $rightAttach, $topAttach,
8873 $bottomAttach, $check
8874 ) = @_;
8875  
8876 # Check for improper arguments
8877 if (
8878 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
8879 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8880 || defined $check
8881 ) {
8882 return $axmud::CLIENT->writeImproper($self->_objClass . '->addCheckButton', @_);
8883 }
8884  
8885 # Check that the position in the grid makes sense
8886 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8887  
8888 return undef;
8889 }
8890  
8891 # Create the checkbutton
8892 my $checkButton;
8893 if (defined $name && $name ne '') {
8894 $checkButton = Gtk3::CheckButton->new_with_label($name);
8895 } else {
8896 $checkButton = Gtk3::CheckButton->new();
8897 }
8898  
8899 if ($iv) {
8900  
8901 # Display the existing value of the IV
8902 $checkButton->set_active($self->editObj->$iv);
8903  
8904 $checkButton->signal_connect('toggled' => sub {
8905  
8906 $self->ivAdd('editHash', $iv, $checkButton->get_active());
8907 });
8908 }
8909  
8910 # Make the checkbutton insensitive, if $stateFlag is FALSE
8911 if (! $stateFlag) {
8912  
8913 $checkButton->set_state('insensitive');
8914 }
8915  
8916 # Add the checkbutton to the grid
8917 $checkButton->set_hexpand(TRUE);
8918 $checkButton->set_vexpand(FALSE);
8919 $grid->attach(
8920 $checkButton,
8921 $leftAttach,
8922 $topAttach,
8923 ($rightAttach - $leftAttach),
8924 ($bottomAttach - $topAttach),
8925 );
8926  
8927 return $checkButton;
8928 }
8929  
8930 sub addRadioButton {
8931  
8932 # Adds a Gtk3::RadioButton at the specified position in the tab's Gtk3::Grid
8933 #
8934 # Example calls:
8935 # my ($group, $button) = $self->addRadioButton(
8936 # $grid, undef, $name, 'some_IV', $value, TRUE,
8937 # 0, 6, 0, 1);
8938 # my ($group2, $button2) = $self->addRadioButton(
8939 # $grid, $group, $name, 'some_IV', $value, TRUE,
8940 # 0, 6, 0, 1, 0, 0.5);
8941 #
8942 # Expected arguments
8943 # $grid - The tab's Gtk3::Grid object
8944 # $group - Reference to the radio button group created, when the first button in the
8945 # group was added (if set to 'undef', this is the first button, and a
8946 # group will be created for it)
8947 # $name - A 'name' for the radio button (displayed next to the button); if 'undef',
8948 # no name is displayed
8949 # $iv - A string naming the IV set when the radio button is toggled. If 'undef',
8950 # nothing happens when the user toggles the radiobutton; it's up to the
8951 # calling function to check the button's state
8952 # $value - The value to which the IV is set, when the radio button is selected
8953 # (ignored if $iv is 'undef')
8954 # $stateFlag - Flag set to FALSE if the radiobutton's state should be 'insensitive',
8955 # TRUE if it should be 'normal'
8956 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8957 # - The position of the radiobutton in the grid
8958 #
8959 # Optional arguments
8960 # $alignLeft, $alignRight
8961 # - Used in the call to ->set_alignment; two values in the range 0-1
8962 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
8963 #
8964 # Return values
8965 # An empty list on improper arguments or if the widget's position in the Gtk3::Grid is
8966 # invalid
8967 # Otherwise a list containing two elements: the radio button $group and the
8968 # Gtk3::RadioButton created
8969  
8970 my (
8971 $self, $grid, $group, $name, $iv, $value, $stateFlag, $leftAttach, $rightAttach,
8972 $topAttach, $bottomAttach, $alignLeft, $alignRight, $check
8973 ) = @_;
8974  
8975 # Local variables
8976 my @emptyList;
8977  
8978 # Check for improper arguments
8979 if (
8980 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
8981 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8982 || defined $check
8983 ) {
8984 $axmud::CLIENT->writeImproper($self->_objClass . '->addRadioButton', @_);
8985 return @emptyList;
8986 }
8987  
8988 # Check that the position in the grid makes sense
8989 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8990  
8991 return @emptyList;
8992 }
8993  
8994 # Set default alignment, if none specified
8995 if (! defined $alignLeft) {
8996  
8997 $alignLeft = 0;
8998 }
8999  
9000 if (! defined $alignRight) {
9001  
9002 $alignRight = 0.5;
9003 }
9004  
9005 # Create the radio button
9006 my $radioButton = Gtk3::RadioButton->new();
9007 # Add it to the existing group, if one was specified
9008 if (defined $group) {
9009  
9010 $radioButton->set_group($group);
9011 }
9012  
9013 if ($iv) {
9014  
9015 # If $value is the one currently stored in $self->editObj, mark this radio button
9016 # as active
9017 if (
9018 defined $value
9019 && defined $self->editObj->$iv
9020 && $value eq $self->editObj->$iv
9021 ) {
9022 $radioButton->set_active(TRUE);
9023 }
9024  
9025 $radioButton->signal_connect('toggled' => sub {
9026  
9027 # Set the IV only if this radiobutton has been selected
9028 if ($radioButton->get_active()) {
9029  
9030 $self->ivAdd('editHash', $iv, $value);
9031 }
9032 });
9033 }
9034  
9035 # Give the radio button a name, if one was specified
9036 if ($name) {
9037  
9038 $radioButton->set_label($name);
9039 }
9040  
9041 # Make the radio button insensitive, if $stateFlag is FALSE
9042 if (! $stateFlag) {
9043  
9044 $radioButton->set_state('insensitive');
9045 }
9046  
9047 # Set radio button's alignment
9048 $radioButton->set_alignment($alignLeft, $alignRight);
9049  
9050 # Add the radio button to the grid
9051 $radioButton->set_hexpand(FALSE);
9052 $radioButton->set_vexpand(FALSE);
9053 $grid->attach(
9054 $radioButton,
9055 $leftAttach,
9056 $topAttach,
9057 ($rightAttach - $leftAttach),
9058 ($bottomAttach - $topAttach),
9059 );
9060  
9061 return ($radioButton->get_group(), $radioButton);
9062 }
9063  
9064 sub addEntry {
9065  
9066 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid
9067 #
9068 # Example calls:
9069 # my $entry = $self->addEntry($grid, 'some_IV', TRUE,
9070 # 0, 6, 0, 1);
9071 # my $entry = $self->addEntry($grid, 'some_IV', FALSE,
9072 # 0, 6, 0, 1, 16, 16);
9073 # my $entry = $self->addEntry($grid, undef, TRUE,
9074 # 0, 6, 0, 1);
9075 #
9076 # Expected arguments
9077 # $grid - The tab's Gtk3::Grid object
9078 # $iv - A string naming the IV set when the user modifies the text in the entry
9079 # box. If 'undef', nothing happens when the user modifies the text; it's
9080 # up to the calling function to check the entry box's state
9081 # $stateFlag - Flag set to FALSE if the entry box's state should be 'insensitive', TRUE
9082 # if it should be 'normal'
9083 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9084 # - The position of the entry box in the grid
9085 #
9086 # Optional arguments
9087 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
9088 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
9089 #
9090 # Return values
9091 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9092 # Otherwise the Gtk3::Entry created
9093  
9094 my (
9095 $self, $grid, $iv, $stateFlag, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
9096 $widthChars, $maxChars, $check
9097 ) = @_;
9098  
9099 # Check for improper arguments
9100 if (
9101 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
9102 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9103 || defined $check
9104 ) {
9105 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntry', @_);
9106 }
9107  
9108 # Check that the position in the grid makes sense
9109 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9110  
9111 return undef;
9112 }
9113  
9114 # Create the entry
9115 my $entry = Gtk3::Entry->new();
9116  
9117 # Display the existing value of the IV
9118 if (defined $iv && defined $self->editObj->$iv) {
9119  
9120 $entry->set_text($self->editObj->$iv);
9121 }
9122  
9123 # Set the width, if specified
9124 if (defined $widthChars) {
9125  
9126 $entry->set_width_chars($widthChars);
9127 }
9128  
9129 # Set the maximum number of characters, if specified
9130 if (defined $maxChars) {
9131  
9132 $entry->set_max_length($maxChars);
9133 }
9134  
9135 # Signal connect
9136 if (defined $iv) {
9137  
9138 $entry->signal_connect('changed' => sub {
9139  
9140 my $text = $entry->get_text();
9141  
9142 $self->ivAdd('editHash', $iv, $text);
9143 });
9144 }
9145  
9146 # Make the entry insensitive, if $stateFlag is FALSE
9147 if (! $stateFlag) {
9148  
9149 $entry->set_state('insensitive');
9150 }
9151  
9152 # Add the entry to the grid
9153 $entry->set_hexpand(TRUE);
9154 $entry->set_vexpand(FALSE);
9155 $grid->attach(
9156 $entry,
9157 $leftAttach,
9158 $topAttach,
9159 ($rightAttach - $leftAttach),
9160 ($bottomAttach - $topAttach),
9161 );
9162  
9163 return $entry;
9164 }
9165  
9166 sub addEntryWithButton {
9167  
9168 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid. The entry is
9169 # displayed alongside a button that simultaneously shows whether the IV's value is 'undef'
9170 # and allows the user to set the IV to 'undef'
9171 #
9172 # Example calls:
9173 # my $entry = $self->addEntryWithButton($grid, 'some_IV', TRUE,
9174 # 0, 6, 0, 1);
9175 # my $entry = $self->addEntryWithButton($grid, 'some_IV', FALSE,
9176 # 0, 6, 0, 1, 16, 16);
9177 #
9178 # Expected arguments
9179 # $grid - The tab's Gtk3::Grid object
9180 # $iv - A string naming the IV set when the user modifies the text in the entry
9181 # box. Unlike most of these functions, the $iv must be specified
9182 # $stateFlag - Flag set to FALSE if the entry box's state should be 'insensitive', TRUE
9183 # if it should be 'normal'
9184 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9185 # - The position of the entry in the grid
9186 #
9187 # Optional arguments
9188 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
9189 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
9190 #
9191 # Return values
9192 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9193 # Otherwise the Gtk3::Entry created
9194  
9195 my (
9196 $self, $grid, $iv, $stateFlag, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
9197 $widthChars, $maxChars, $check
9198 ) = @_;
9199  
9200 # Check for improper arguments
9201 if (
9202 ! defined $grid || ! defined $iv || ! defined $stateFlag || ! defined $leftAttach
9203 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9204 || defined $check
9205 ) {
9206 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntryWithButton', @_);
9207 }
9208  
9209 # Check that the position in the grid makes sense
9210 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9211  
9212 return undef;
9213 }
9214 # Call $self->addEntry to create the entry as normal, reserving one square in the grid for
9215 # the button (we don't pass $iv to $self->addEntry because we're going to create our own
9216 # ->signal_connect)
9217 my $entry = $self->addEntry(
9218 $grid, undef, $stateFlag, $leftAttach, ($rightAttach - 1), $topAttach, $bottomAttach,
9219 $widthChars, $maxChars,
9220 );
9221  
9222 # Set the contents of the entry
9223 if (defined $iv && defined $self->editObj->$iv) {
9224  
9225 $entry->set_text($self->editObj->$iv);
9226 }
9227  
9228 # Create a button
9229 my $button = Gtk3::Button->new();
9230  
9231 # Set the icon to display on the button, depending on whether the IV is set to 'undef',
9232 # or not
9233 my $image;
9234 if (defined $iv && defined $self->editObj->$iv) {
9235  
9236 # Use the Gtk3 'clear' icon - clicking on the button sets the IV to undef
9237 $image = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
9238 # Give the button a tooltip
9239 $button->set_tooltip_text('Click to set this IV to \'undef\'');
9240  
9241 } else {
9242  
9243 # Use the Gtk3 'remove' icon - IV is already 'undef'; clicking on the button does
9244 # nothing
9245 $image = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
9246 # Give the button a tooltip
9247 $button->set_tooltip_text('This IV is already set to \'undef\'');
9248 }
9249  
9250 $button->set_image($image);
9251  
9252 # Make the button clickable
9253 $button->signal_connect('clicked' => sub {
9254  
9255 # Empty the entry to remove any text entered into it
9256 $entry->set_text('');
9257  
9258 # Set the IV to undef
9259 $self->ivAdd('editHash', $iv, undef);
9260  
9261 # Change the button's image to mark this IV as being set to undef
9262 my $image2 = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
9263 $button->set_image($image2);
9264 # Give the button a new tooltip
9265 $button->set_tooltip_text('This IV is already set to \'undef\'');
9266 });
9267  
9268 # Respond when the user types something in the box
9269 $entry->signal_connect('changed' => sub {
9270  
9271 my $text = $entry->get_text();
9272 $self->ivAdd('editHash', $iv, $text);
9273  
9274 # Contents of the entry can't possibly be 'undef' any more
9275 my $image3 = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
9276 $button->set_image($image3);
9277 # Give the button a new tooltip
9278 $button->set_tooltip_text('Click to set this IV to \'undef\'');
9279 });
9280  
9281 # Add the button to the grid (the entry has already been added)
9282 $button->set_hexpand(FALSE);
9283 $button->set_vexpand(FALSE);
9284 $leftAttach = $rightAttach - 1;
9285 $grid->attach(
9286 $button,
9287 $leftAttach,
9288 $topAttach,
9289 ($rightAttach - $leftAttach),
9290 ($bottomAttach - $topAttach),
9291 );
9292  
9293 return $entry;
9294 }
9295  
9296 sub addEntryWithIcon {
9297  
9298 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid. The entry contains
9299 # a stock icon to show whether the current contents of the entry is permissible
9300 # The stock icons used are 'gtk-yes' (for an acceptable value) and 'gtk-no' (for a
9301 # forbidden value)
9302 #
9303 # Example calls:
9304 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'int', 0, 1000,
9305 # 0, 6, 0, 1);
9306 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'odd', 1, 1001,
9307 # 0, 6, 0, 1);
9308 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'even', 0, 1000,
9309 # 0, 6, 0, 1);
9310 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'float', 0, 1000000,
9311 # 0, 6, 0, 1);
9312 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'string', 3, 16,
9313 # 0, 6, 0, 1);
9314 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'regex', 1, undef,
9315 # 0, 6, 0, 1);
9316 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', \&checkFunction, undef, undef,
9317 # 0, 6, 0, 1);
9318 #
9319 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'int', 0, 1000,
9320 # 0, 6, 0, 1, 16, 16);
9321 #
9322 # Expected arguments
9323 # $grid - The tab's Gtk3::Grid object
9324 # $iv - A string naming the IV set when the user modifies the text in the entry
9325 # box. If 'undef', nothing happens when the user modifies the text (except
9326 # that the icon is updated); it's up to the calling function to check the
9327 # entry box's state
9328 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
9329 # function
9330 # - If 'int', an integer is expected with the specified min/max values
9331 # - If 'odd', an odd-numbered integer with the specified min/max value is
9332 # expected. If the minimum value is less than 1, 1 is used instead
9333 # - If 'even', an even-numbered integer with the specified min/max value is
9334 # expected. If the minimum value is less than 0, 0 is used instead
9335 # - If 'float', a floating point number is expected with the specified min/max
9336 # values
9337 # - If 'string', a string is expected (which might be a number) with the
9338 # specified min/max length
9339 # - If 'regex', a valid regex is expected with the specified min/max length
9340 # - If a function reference, a function is called which should return 'undef'
9341 # or 1, depending on the value of the entry; the icon is set accordingly
9342 # $min, $max - The values described above (ignored when $mode is a function reference).
9343 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
9344 # maximum
9345 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9346 # - The position of the entry in the grid
9347 #
9348 # Optional arguments
9349 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
9350 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
9351 #
9352 # Return values
9353 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9354 # Otherwise the Gtk3::Entry created
9355  
9356 my (
9357 $self, $grid, $iv, $mode, $min, $max, $leftAttach, $rightAttach, $topAttach,
9358 $bottomAttach, $widthChars, $maxChars, $check
9359 ) = @_;
9360  
9361 # Local variables
9362 my $msg;
9363  
9364 # Check for improper arguments
9365 if (
9366 ! defined $grid || ! defined $mode || ! defined $leftAttach || ! defined $rightAttach
9367 || ! defined $topAttach || ! defined $bottomAttach || defined $check
9368 ) {
9369 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntryWithIcon', @_);
9370 }
9371  
9372 # Check that the position in the grid makes sense
9373 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9374  
9375 return undef;
9376 }
9377  
9378 # Check that the minimum/maximum values specified are valid and, if not, fix them
9379 if (defined $min && defined $max && $min > $max) {
9380  
9381 # Use no maximum value...
9382 $max = undef;
9383 # ...and show a warning, because this shouldn't happen
9384 if ($iv) {
9385 $msg = 'Minimum greater than maximum for IV \'' . $iv . '\'';
9386 } else {
9387 $msg = 'Minimum greater than maximum (min: ' . $min . ' max: ' . $max . ')';
9388 }
9389  
9390 $self->session->writeWarning(
9391 $msg,
9392 $self->_objClass . '->addEntryWithIcon',
9393 );
9394 }
9395  
9396 if ($mode eq 'odd' && defined $min && $min < 1) {
9397  
9398 # Lowest value of $min (if specified) is 1
9399 $min = 1;
9400  
9401 } elsif ($mode eq 'even' && defined $min && $min < 0) {
9402  
9403 # Lowest value of $min (if specified) is 0
9404 $min = 0;
9405 }
9406  
9407 # Create the entry
9408 my $entry = Gtk3::Entry->new();
9409  
9410 # Display the existing value of the IV
9411 if (defined $iv && defined $self->editObj->$iv) {
9412  
9413 $entry->set_text($self->editObj->$iv);
9414  
9415 if (! $self->checkEntry($self->editObj->$iv, $mode, $min, $max)) {
9416 $entry->set_icon_from_stock('secondary', 'gtk-no');
9417 } else {
9418 $entry->set_icon_from_stock('secondary', 'gtk-yes');
9419 }
9420  
9421 } else {
9422  
9423 # We still need to set the icon for an empty box
9424 if ($mode eq 'string' || $mode eq 'regex') {
9425  
9426 # Empty strings/regexes might be acceptable
9427 if (! $self->checkEntry('', $mode, $min, $max)) {
9428 $entry->set_icon_from_stock('secondary', 'gtk-no');
9429 } else {
9430 $entry->set_icon_from_stock('secondary', 'gtk-yes');
9431 }
9432  
9433 } else {
9434  
9435 # Box is empty, so any $self->checkEntry test will fail
9436 # When $mode is set to a function reference, we'll have to assume that an empty
9437 # entry box is not an acceptable value. If it is acceptable, you can call
9438 # $self->setEntryIcon immediately after calling this function
9439 $entry->set_icon_from_stock('secondary', 'gtk-no');
9440 }
9441 }
9442  
9443 # Customise the entry
9444 $entry->signal_connect('changed' => sub {
9445  
9446 my $value = $entry->get_text();
9447 # Check whether $value is a valid value, or not
9448 if (! $self->checkEntry($value, $mode, $min, $max)) {
9449  
9450 # Can't use this value
9451 if (defined $iv) {
9452  
9453 $self->ivDelete('editHash', $iv);
9454 }
9455  
9456 $entry->set_icon_from_stock('secondary', 'gtk-no');
9457  
9458 } else {
9459  
9460 # This is a valid value, so use it
9461 if (defined $iv) {
9462  
9463 $self->ivAdd('editHash', $iv, $value);
9464 }
9465  
9466 $entry->set_icon_from_stock('secondary', 'gtk-yes');
9467 }
9468 });
9469  
9470 # Set the width, if specified
9471 if (defined $widthChars) {
9472  
9473 $entry->set_width_chars($widthChars);
9474 }
9475  
9476 # Set the maximum number of characters, if specified
9477 if (defined $maxChars) {
9478  
9479 $entry->set_max_length($maxChars);
9480 }
9481  
9482 # Add the entry to the grid
9483 $entry->set_hexpand(TRUE);
9484 $entry->set_vexpand(FALSE);
9485 $grid->attach(
9486 $entry,
9487 $leftAttach,
9488 $topAttach,
9489 ($rightAttach - $leftAttach),
9490 ($bottomAttach - $topAttach),
9491 );
9492  
9493 return $entry;
9494 }
9495  
9496 sub addEntryWithIconButton {
9497  
9498 # A combination of ->addEntryWithButton and ->addEntryWithIcon, using the same arguments
9499 # as ->addEntryWithIcon
9500 # An IV value of 'undef' counts as acceptable, in addition to the usual conditions
9501 #
9502 # Expected arguments
9503 # $grid - The tab's Gtk3::Grid object
9504 # $iv - A string naming the IV set when the user modifies the text in the entry
9505 # box. Unlike most of these functions, the $iv must be specified
9506 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
9507 # function
9508 # - If 'int', an integer is expected with the specified min/max values
9509 # - If 'odd', an odd-numbered integer with the specified min/max value is
9510 # expected. If the minimum value is less than 1, 1 is used instead
9511 # - If 'even', an even-numbered integer with the specified min/max value is
9512 # expected. If the minimum value is less than 0, 0 is used instead
9513 # - If 'float', a floating point number is expected with the specified min/max
9514 # values
9515 # - If 'string', a string is expected (which might be a number) with the
9516 # specified min/max length
9517 # - If 'regex', a valid regex is expected with the specified min/max length
9518 # - If a function reference, a function is called which should return 'undef'
9519 # or 1, depending on the value of the entry; the icon is set accordingly
9520 # $min, $max - The values described above (ignored when $mode is a function reference).
9521 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
9522 # maximum
9523 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9524 # - The position of the entry in the grid
9525 #
9526 # Optional arguments
9527 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
9528 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
9529 #
9530 # Return values
9531 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9532 # Otherwise the Gtk3::Entry created
9533  
9534 my (
9535 $self, $grid, $iv, $mode, $min, $max, $leftAttach, $rightAttach, $topAttach,
9536 $bottomAttach, $widthChars, $maxChars, $check
9537 ) = @_;
9538  
9539 # Local variables
9540 my $msg;
9541  
9542 # Check for improper arguments
9543 if (
9544 ! defined $grid || ! defined $iv || ! defined $mode || ! defined $leftAttach
9545 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9546 || defined $check
9547 ) {
9548 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntryWithIconButton', @_);
9549 }
9550  
9551 # Check that the position in the grid makes sense
9552 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9553  
9554 return undef;
9555 }
9556  
9557 # Call $self->addEntryWithIcon to create the entry as normal, reserving one square in the
9558 # grid for the button (we don't pass $iv to $self->addEntryWithIcon because we're going
9559 # to create our own ->signal_connect)
9560 my $entry = $self->addEntryWithIcon(
9561 $grid, undef, $mode, $min, $max, $leftAttach, ($rightAttach - 1), $topAttach,
9562 $bottomAttach, $widthChars, $maxChars,
9563 );
9564  
9565 # Set the contents of the entry
9566 if (defined $self->editObj->$iv) {
9567  
9568 $entry->set_text($self->editObj->$iv);
9569  
9570 } else {
9571  
9572 # An empty box represents 'undef', which is an acceptable value
9573 # We must set the icon manually, as calling $entry->set_text('') doesn't emit the
9574 # 'changed' signals which checks the validity of the value
9575 $entry->set_icon_from_stock('secondary', 'gtk-yes');
9576 }
9577  
9578 # Create a button
9579 my $button = Gtk3::Button->new();
9580  
9581 # Set the icon to display on the button, depending on whether the IV is set to 'undef',
9582 # or not
9583 my $image;
9584 if (defined $iv && defined $self->editObj->$iv) {
9585  
9586 # Use the Gtk3 'clear' icon - clicking on the button sets the IV to undef
9587 $image = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
9588 # Give the button a tooltip
9589 $button->set_tooltip_text('Click to set this IV to \'undef\'');
9590  
9591 } else {
9592  
9593 # Use the Gtk3 'remove' icon - IV is already 'undef'; clicking on the button does
9594 # nothing
9595 $image = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
9596 # Give the button a tooltip
9597 $button->set_tooltip_text('This IV is already set to \'undef\'');
9598 }
9599  
9600 $button->set_image($image);
9601  
9602 # Make the button clickable
9603 $button->signal_connect('clicked' => sub {
9604  
9605 # Set the IV to undef
9606 $self->ivAdd('editHash', $iv, undef);
9607  
9608 # Empty the entry to remove any text entered into it, and update its icon
9609 $entry->set_text('');
9610 $entry->set_icon_from_stock('secondary', 'gtk-yes');
9611  
9612 # Change the button's image to mark this IV as being set to undef
9613 my $image2 = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
9614 $button->set_image($image2);
9615 # Give the button a new tooltip
9616 $button->set_tooltip_text('This IV is already set to \'undef\'');
9617 });
9618  
9619 # Respond when the user types something in the box
9620 $entry->signal_connect('changed' => sub {
9621  
9622 my $text = $entry->get_text();
9623 $self->ivAdd('editHash', $iv, $text);
9624  
9625 if ($self->checkEntry($text, $mode, $min, $max)) {
9626 $entry->set_icon_from_stock('secondary', 'gtk-yes');
9627 } else {
9628 $entry->set_icon_from_stock('secondary', 'gtk-no');
9629 }
9630  
9631 # Contents of the entry can't possibly be 'undef' any more
9632 my $image3 = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
9633 $button->set_image($image3);
9634 # Give the button a new tooltip
9635 $button->set_tooltip_text('Click to set this IV to \'undef\'');
9636 });
9637  
9638 # Add the button to the grid (the entry has already been added)
9639 $button->set_hexpand(FALSE);
9640 $button->set_vexpand(FALSE);
9641 $leftAttach = $rightAttach - 1;
9642 $grid->attach(
9643 $button,
9644 $leftAttach,
9645 $topAttach,
9646 ($rightAttach - $leftAttach),
9647 ($bottomAttach - $topAttach),
9648 );
9649  
9650 return $entry;
9651 }
9652  
9653 sub addComboBox {
9654  
9655 # Adds a Gtk3::ComboBox at the specified position in the window's Gtk3::Grid
9656 #
9657 # Example calls:
9658 # my $comboBox = $self->addComboBox($grid, 'some_IV', \@comboList, 'some_title', TRUE,
9659 # 0, 6, 0, 1);
9660 # my $comboBox = $self->addComboBox($grid, 'some_IV', \@comboList, '', FALSE,
9661 # 0, 6, 0, 1);
9662 #
9663 # Expected arguments
9664 # $grid - The tab's Gtk3::Grid object
9665 # $iv - A string naming the IV set when the user chooses an item in the combo
9666 # box. If 'undef', nothing happens when the user chooses an item in
9667 # the box; it's up to the calling function to check the box's state
9668 # $listRef - Reference to a list with initial values (can be an empty list)
9669 # $title - A string used as a title, e.g. 'Choose your favourite colour' - if an
9670 # empty string, the item at the top of the combobox list is the
9671 # current value of the IV
9672 # $noUndefFlag - If set to TRUE, the combo is populated only with the items in
9673 # $listRef. If set to FALSE (or 'undef'), the first item in the combo
9674 # is an empty value used to set the IV to 'undef'
9675 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9676 # - The position of the combo box in the grid
9677 #
9678 # Optional arguments
9679 #
9680 # Return values
9681 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9682 # Otherwise the Gtk3::ComboBox created
9683  
9684 my (
9685 $self, $grid, $iv, $listRef, $title, $noUndefFlag, $leftAttach, $rightAttach,
9686 $topAttach, $bottomAttach, $check
9687 ) = @_;
9688  
9689 # Check for improper arguments
9690 if (
9691 ! defined $grid || ! defined $listRef || ! defined $title || ! defined $leftAttach
9692 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9693 || defined $check
9694 ) {
9695 return $axmud::CLIENT->writeImproper($self->_objClass . '->addComboBox', @_);
9696 }
9697  
9698 # Check that the position in the grid makes sense
9699 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9700  
9701 return undef;
9702 }
9703  
9704 # Create the combobox
9705 my $comboBox = Gtk3::ComboBoxText->new();
9706  
9707 # Populate the combobox
9708 if ($title) {
9709  
9710 # The first item in the combobox list is a title
9711 $comboBox->append_text($title);
9712 $comboBox->set_active(0);
9713  
9714 } elsif ($iv) {
9715  
9716 if ($noUndefFlag) {
9717  
9718 if (defined $self->editObj->$iv) {
9719  
9720 # The first item is the current value of the IV, if there is one
9721 $comboBox->append_text($self->editObj->$iv);
9722 # Make this the active item
9723 $comboBox->set_active(0);
9724 }
9725  
9726 } else {
9727  
9728 # The first item is an empty line, for setting the IV to 'undef'
9729 $comboBox->append_text('');
9730  
9731 if (defined $self->editObj->$iv) {
9732  
9733 # The second item is the current value of the IV, if there is one
9734 $comboBox->append_text($self->editObj->$iv);
9735 # Make this the active item
9736 $comboBox->set_active(1);
9737  
9738 } else {
9739  
9740 # Make the 'undef' option the active item
9741 $comboBox->set_active(0);
9742 }
9743 }
9744  
9745 } elsif (! $noUndefFlag) {
9746  
9747 # The first item is an empty line, for setting the IV to 'undef'
9748 $comboBox->append_text('');
9749 # Make the 'undef' option the active item
9750 $comboBox->set_active(0);
9751 }
9752  
9753 foreach my $item (@$listRef) {
9754  
9755 # Don't show the current value of the IV twice
9756 if (
9757 ! $iv
9758 || ! defined $self->editObj->$iv
9759 || $item ne $self->editObj->$iv
9760 ) {
9761 $comboBox->append_text($item);
9762 }
9763 }
9764  
9765 if (! $iv && $noUndefFlag) {
9766  
9767 # The active item hasn't been set yet
9768 $comboBox->set_active(0);
9769 }
9770  
9771 if ($iv) {
9772  
9773 $comboBox->signal_connect('changed' => sub {
9774  
9775 my $text = $comboBox->get_active_text();
9776  
9777 # If the user has selected the title, ignore it
9778 if (! $title || $text ne $title) {
9779  
9780 # If the user has selected the empty line at the top, set the IV to 'undef'
9781 if (! $text) {
9782  
9783 $self->ivAdd('editHash', $iv, undef);
9784  
9785 # Otherwise set the IV to the specified value
9786 } else {
9787  
9788 $self->ivAdd('editHash', $iv, $text);
9789 }
9790 }
9791 });
9792 }
9793  
9794 # Add the combobox to the grid
9795 $comboBox->set_hexpand(TRUE);
9796 $comboBox->set_vexpand(FALSE);
9797 $grid->attach(
9798 $comboBox,
9799 $leftAttach,
9800 $topAttach,
9801 ($rightAttach - $leftAttach),
9802 ($bottomAttach - $topAttach),
9803 );
9804  
9805 return $comboBox;
9806 }
9807  
9808 sub addTextView {
9809  
9810 # Adds a Gtk3::TextView at the specified position in the window's Gtk3::Grid
9811 #
9812 # Example calls:
9813 # my $textView = $self->addTextView($grid, 'some_IV', TRUE,
9814 # 0, 6, 0, 1);
9815 # my $textView = $self->addTextView($grid, 'some_IV', FALSE,
9816 # 0, 6, 0, 1,
9817 # TRUE, FALSE, TRUE,
9818 # -1, 120);
9819 #
9820 # Expected arguments
9821 # $grid - The tab's Gtk3::Grid object
9822 # $iv - A string naming the IV set when the user modifies the contents of the
9823 # textview. If 'undef', nothing happens when the user modifies the
9824 # contents; it's up to the calling function to check the textview's state
9825 # $editableFlag
9826 # - Flag set to TRUE if the textView should be editable, FALSE if it shouldn't
9827 # be editable
9828 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9829 # - The position of the textview in the grid
9830 #
9831 # Optional arguments
9832 # $listFlag - Flag set to TRUE if the contents of the textview should be treated as a
9833 # list, FALSE (or 'undef') if it should be treated as a single string
9834 # containing newline characters. Default value is TRUE (treat as a list)
9835 # $removeEmptyFlag
9836 # - Flag set to TRUE if empty lines should be removed when the IV is set,
9837 # FALSE (or 'undef') if they should be retained. Default value is TRUE
9838 # (remove lines)
9839 # $removeSpaceFlag
9840 # - Flag set to TRUE if lines should have leading/trailing whitespace removed
9841 # when the IV is set, FALSE (or 'undef') if not. Default value is TRUE
9842 # (remove leading/trailing whitespace)
9843 # $noScrollFlag
9844 # - Flag set to TRUE if word-wrap mode should be turned on, preventing a
9845 # horizontal scrollbar, FALSE (or 'undef') if the textview should scroll
9846 # in both dimensions. Default value is FALSE (scroll in both dimensions)
9847 # $width, $height
9848 # - The width and height (in pixels) of the frame containing the list. If
9849 # specified, values of -1 mean 'don't set this value'. The default values
9850 # are (-1, -1)
9851 #
9852 # Return values
9853 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9854 # Otherwise the Gtk3::TextView created (inside a Gtk::ScrolledWindow)
9855  
9856 my (
9857 $self, $grid, $iv, $editableFlag, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
9858 $listFlag, $removeEmptyFlag, $removeSpaceFlag, $noScrollFlag, $width, $height, $check
9859 ) = @_;
9860  
9861 # Check for improper arguments
9862 if (
9863 ! defined $grid || ! defined $editableFlag || ! defined $leftAttach
9864 || ! defined $rightAttach || ! defined $topAttach || defined $check
9865 ) {
9866 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTextView', @_);
9867 }
9868  
9869 # Check that the position in the grid makes sense
9870 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9871  
9872 return undef;
9873 }
9874  
9875 # Set defaults
9876 if (! defined $listFlag) {
9877  
9878 $listFlag = TRUE;
9879 }
9880  
9881 if (! defined $removeEmptyFlag) {
9882  
9883 $removeEmptyFlag = TRUE;
9884 }
9885  
9886 if (! defined $removeSpaceFlag) {
9887  
9888 $removeSpaceFlag = TRUE;
9889 }
9890  
9891 if (! defined $width) {
9892  
9893 $width = -1; # Let Gtk3 set the width
9894 }
9895  
9896 if (! defined $height) {
9897  
9898 $height = -1; # Let Gtk3 set the height
9899 }
9900  
9901 # Creating a containing Gtk3::Frame and Gtk3::ScrolledWindow
9902 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
9903 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
9904 $scroll->set_policy('automatic', 'automatic');
9905 $scroll->set_size_request($width, $height);
9906 # $scroll->set_border_width($self->spacingPixels);
9907  
9908 # Create a textview with default colours/fonts
9909 my $textView = Gtk3::TextView->new();
9910 $scroll->add($textView);
9911 my $buffer = Gtk3::TextBuffer->new();
9912 $textView->set_buffer($buffer);
9913 if ($noScrollFlag) {
9914  
9915 $textView->set_wrap_mode('word-char'); # Wrap words if possible, characters if not
9916 $textView->set_justification('left');
9917 }
9918  
9919 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);
9920  
9921 if ($iv) {
9922  
9923 # Display the existing value of the IV (the call to $buffer->set_text requires a
9924 # defined value, so don't try to display 'undef')
9925 if ($self->editObj->$iv) {
9926  
9927 if ($listFlag) {
9928  
9929 # The call to ->ivPeek returns the contents of the IV as a flat list
9930 $buffer->set_text(join("\n", $self->editObj->ivPeek($iv)));
9931  
9932 } else {
9933  
9934 $buffer->set_text($self->editObj->$iv);
9935 }
9936 }
9937  
9938 $buffer->signal_connect('changed' => sub {
9939  
9940 my (
9941 $text,
9942 @list, @finalList,
9943 );
9944  
9945 $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer);
9946  
9947 if ($listFlag) {
9948  
9949 # Split the contents of the textview into a list of lines, separated by
9950 # newline characters
9951 @list = split("\n", $text);
9952 # Remove any empty lines and leading/trailing whitespace, if allowed
9953 foreach my $line (@list) {
9954  
9955 if ($line && $removeSpaceFlag) {
9956  
9957 $line =~ s/^\s+//; # Remove leading whitespace
9958 $line =~ s/\s+$//; # Remove trailing whitespace
9959 }
9960  
9961 if ($line || ! $removeEmptyFlag) {
9962  
9963 push (@finalList, $line);
9964 }
9965 }
9966  
9967 # Set the IV
9968 $self->ivAdd('editHash', $iv, \@finalList);
9969  
9970 } else {
9971  
9972 # Treat the contents of the IV as a single string
9973 $self->ivAdd('editHash', $iv, $text);
9974 }
9975 });
9976 }
9977  
9978 # Make the textview editable or not editable
9979 $textView->set_editable($editableFlag);
9980  
9981 # Add the textview to the grid
9982 $scroll->set_hexpand(TRUE);
9983 $scroll->set_vexpand(TRUE);
9984 $grid->attach(
9985 $scroll,
9986 $leftAttach,
9987 $topAttach,
9988 ($rightAttach - $leftAttach),
9989 ($bottomAttach - $topAttach),
9990 );
9991  
9992 return $textView;
9993 }
9994  
9995 sub addSimpleList {
9996  
9997 # Adds a GA::Obj::SimpleList at the specified position in the window's Gtk3::Grid
9998 #
9999 # Example calls:
10000 # my $slWidget = $self->addSimpleList($grid, 'some_IV', \@columnList,
10001 # 0, 6, 0, 1);
10002 # my $slWidget = $self->addSimpleList($grid, 'some_IV', \@columnList,
10003 # 0, 6, 0, 1,
10004 # -1, -1,
10005 # GA::Client->getMethodRef('function_name'));
10006 #
10007 # Expected arguments
10008 # $grid - The tab's Gtk3::Grid object
10009 # $iv - The IV in $self->editObj containing the data being edited. If 'undef',
10010 # the list is not populated with data; it's up to the calling function
10011 # to do it
10012 # $columnListRef - Reference to a list of column headings and types, in the form
10013 # ('heading', 'column_type', 'heading', 'column_type'...)
10014 # - 'column_type' is one of the column types specified by
10015 # GA::Obj::SimpleList, e.g. 'scalar', 'int'
10016 # - 'column_type' can also be 'bool' for a non-clickable checkbox, or
10017 # 'bool_editable' for a clickable checkbox
10018 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10019 # - The position of the simple list in the grid
10020 #
10021 # Optional arguments
10022 # $width, $height - The width and height (in pixels) of the scroller containing the list.
10023 # If specified, values of -1 mean 'don't set this value'. The default
10024 # values are (-1, -1)
10025 # $funcRef - Reference to the function to call when a (sensitised) checkbutton is
10026 # clicked. If 'undef', it's up to the calling function to create a
10027 # ->signal_connect method. Function references can be obtained by a
10028 # call to GA::Client->getMethodRef
10029 #
10030 # Return values
10031 # 'undef' on improper arguments
10032 # Otherwise the GA::Obj::SimpleList created
10033  
10034 my (
10035 $self, $grid, $iv, $columnListRef, $leftAttach, $rightAttach, $topAttach,
10036 $bottomAttach, $width, $height, $funcRef, $check,
10037 ) = @_;
10038  
10039 # Local variables
10040 my (
10041 $refType, $count,
10042 @columnList, @spareList,
10043 );
10044  
10045 # Check for improper arguments
10046 if (
10047 ! defined $grid || ! defined $columnListRef || ! defined $leftAttach
10048 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
10049 || defined $check
10050 ) {
10051 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleList', @_);
10052 }
10053  
10054 # Check that the position in the grid makes sense
10055 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10056  
10057 return undef;
10058 }
10059  
10060 # Set defaults
10061 if (! defined $width) {
10062  
10063 $width = -1; # Let Gtk3 set the width
10064 }
10065  
10066 if (! defined $height) {
10067  
10068 $height = -1; # Let Gtk3 set the height
10069 }
10070  
10071 # Dereference the list of columns, and convert 'bool_editable' to 'bool' values for Gtk's
10072 # convenience
10073 foreach my $item (@$columnListRef) {
10074  
10075 if ($item eq 'bool_editable') {
10076 push(@columnList, 'bool');
10077 } else {
10078 push(@columnList, $item);
10079 }
10080 }
10081  
10082 # Add a simple list
10083 my $frame = Gtk3::Frame->new(undef);
10084 $frame->set_border_width(0);
10085  
10086 my $scroller = Gtk3::ScrolledWindow->new();
10087 $frame->add($scroller);
10088 $scroller->set_shadow_type($axmud::CLIENT->constShadowType);
10089 $scroller->set_policy('automatic', 'automatic');
10090 $scroller->set_border_width(0);
10091 $scroller->set_size_request($width, $height);
10092  
10093 my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList);
10094 $scroller->add($slWidget);
10095  
10096 # No interactive searches required
10097 $slWidget->set_enable_search(FALSE);
10098  
10099 # Fill the columns with data
10100 if ($iv) {
10101  
10102 $refType = ref $self->editObj->{$iv};
10103  
10104 if ($refType eq 'HASH') {
10105  
10106 # Sort the hash by key, before adding it to the simple list
10107 $self->resetSortListData($slWidget, [$self->editObj->$iv]);
10108  
10109 } else {
10110  
10111 # Assume that the list/hash IV can be displayed in its current order
10112 $self->resetListData($slWidget, [$self->editObj->$iv], (scalar @columnList / 2));
10113 }
10114 }
10115  
10116 # Make all columns of type 'bool' and 'bool_editable' (which are composed of checkbuttons)
10117 # clickable or non-clickable, as required
10118 $count = -1;
10119 @spareList = @$columnListRef;
10120 do {
10121  
10122 my $title = shift @spareList;
10123 my $type = shift @spareList;
10124  
10125 $count++;
10126  
10127 if ($type eq 'bool') {
10128  
10129 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
10130 $cellRenderer->set(activatable => FALSE);
10131  
10132 } elsif ($type eq 'bool_editable') {
10133  
10134 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
10135 $cellRenderer->set(activatable => TRUE);
10136  
10137 if (defined $funcRef) {
10138  
10139 $cellRenderer->signal_connect('toggled' => sub {
10140  
10141 my ($widget, $path) = @_;
10142  
10143 my $model = $slWidget->get_model();
10144 my $iter = $model->get_iter(Gtk3::TreePath->new_from_string($path));
10145  
10146 # Pass on the contents of each cell in the clicked row; it's up to the
10147 # called code to check the contents of multiple checkboxes, if they exist
10148 my @dataList = ();
10149 for (my $i = 0; $i < scalar (@columnList / 2); $i++) {
10150  
10151 push(@dataList, $model->get($iter, $i));
10152 }
10153  
10154 &$funcRef($slWidget, $model, $iter, @dataList);
10155 });
10156 }
10157 }
10158  
10159 } until (! @spareList);
10160  
10161 # Add the simple list to the grid
10162 $frame->set_hexpand(TRUE);
10163 $frame->set_vexpand(TRUE);
10164 $grid->attach(
10165 $frame,
10166 $leftAttach,
10167 $topAttach,
10168 ($rightAttach - $leftAttach),
10169 ($bottomAttach - $topAttach),
10170 );
10171  
10172 return $slWidget;
10173 }
10174  
10175 sub addRegexButton {
10176  
10177 # Adds a Gtk3::Button at the specified position in the tab's Gtk3::Grid. The button, when
10178 # clicked, checks regexes in a list of IVs, and opens a dialogue window to display the
10179 # result
10180 #
10181 # Example calls:
10182 # my $button = $self->addRegexButton($grid, $listRef,
10183 # 0, 6, 0, 1);
10184 #
10185 # Expected arguments
10186 # $grid - The tab's Gtk3::Grid object
10187 # $listRef - Reference to a list in groups of 2, in the form (type, iv, type, iv...)
10188 # where 'type' is 'scalar' to test a pattern stored in a scalar IV, 'list'
10189 # to test the patterns stored in a list IV, 'keys' or 'values' to test
10190 # the patterns stored as keys/values in a hash IV, or 'both' to test the
10191 # patterns stored as keys and values in a hash IV. If the referenced list
10192 # is empty, no patterns are tested (and the button is desensitised). If
10193 # any 'type' is not recognised, patterns in the IV are not tested (but
10194 # other IVs are still tested)
10195 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10196 # - The position of the button in the grid
10197 #
10198 # Return values
10199 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
10200 # Otherwise the Gtk3::Button created
10201  
10202 my (
10203 $self, $grid, $listRef, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $check,
10204 ) = @_;
10205  
10206 # Check for improper arguments
10207 if (
10208 ! defined $grid || ! defined $listRef || ! defined $leftAttach
10209 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
10210 || defined $check
10211 ) {
10212 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRegexButton', @_);
10213 }
10214  
10215 # Check that the position in the grid makes sense
10216 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10217  
10218 return undef;
10219 }
10220  
10221 # Create the button
10222 my $button = Gtk3::Button->new('Check patterns');
10223 $button->set_tooltip_text(
10224 'Check that the patterns on this page are valid regular expressions',
10225 );
10226  
10227 if (! @$listRef) {
10228  
10229 # No IVs specified so no patterns to check
10230 $button->set_sensitive(FALSE);
10231  
10232 } else {
10233  
10234 # Respond to a mouse click on the button
10235 $button->signal_connect('clicked' => sub {
10236  
10237 my (
10238 $msg, $count,
10239 @list, @patternList, @errorList,
10240 );
10241  
10242 @list = @$listRef;
10243  
10244 do {
10245  
10246 my (
10247 $type, $iv, $value,
10248 @valueList,
10249 %valueHash,
10250 );
10251  
10252 $type = shift @list;
10253 $iv = shift @list;
10254  
10255 # Generate a list of patterns stored in the IV, but ignore any 'undef' values
10256 # and ignore any unrecognised $types
10257 if ($type eq 'scalar') {
10258  
10259 $value = $self->getEditHash_scalarIV($iv);
10260 if (defined $value) {
10261  
10262 push (@patternList, $value);
10263 }
10264  
10265 } elsif ($type eq 'list') {
10266  
10267 @valueList = $self->getEditHash_listIV($iv);
10268 foreach my $item (@valueList) {
10269  
10270 if (defined $item) {
10271  
10272 push (@patternList, $item);
10273 }
10274 }
10275  
10276 } elsif ($type eq 'keys' || $type eq 'values' || $type eq 'both') {
10277  
10278 %valueHash = $self->getEditHash_hashIV($iv);
10279  
10280 if ($type eq 'keys') {
10281  
10282 push (@patternList, keys %valueHash);
10283  
10284 } elsif ($type eq 'values') {
10285  
10286 foreach my $item (values %valueHash) {
10287  
10288 if (defined $item) {
10289  
10290 push (@patternList, $item);
10291 }
10292 }
10293  
10294 } else {
10295  
10296 foreach my $key (keys %valueHash) {
10297  
10298 my $item = $valueHash{$key};
10299  
10300 if (defined $item) {
10301 push (@patternList, $key, $item);
10302 } else {
10303 push (@patternList, $key);
10304 }
10305 }
10306 }
10307 }
10308  
10309 } until (! @list);
10310  
10311 if (! @patternList) {
10312  
10313 $self->showMsgDialogue(
10314 'Check patterns',
10315 'info',
10316 'There are no patterns on this page',
10317 'ok',
10318 );
10319  
10320 } else {
10321  
10322 # Check every pattern in turn. GA::Client->regexCheck returns 'undef' if the
10323 # regex is valid, or an error message if it's not valid
10324 foreach my $pattern (@patternList) {
10325  
10326 my $error = $axmud::CLIENT->regexCheck($pattern);
10327 if (defined $error) {
10328  
10329 push (@errorList, $pattern, $error);
10330 }
10331 }
10332  
10333 if (! @errorList) {
10334  
10335 $self->showMsgDialogue(
10336 'Check patterns',
10337 'info',
10338 'All patterns on this page are valid',
10339 'ok',
10340 );
10341  
10342 } else {
10343  
10344 $msg = 'Patterns checked: ' . (scalar @patternList) . ', errors: '
10345 . ((scalar @errorList) / 2);
10346  
10347 $count = 0;
10348 do {
10349  
10350 my ($pattern, $error);
10351  
10352 $pattern = shift @errorList;
10353 $error = shift @errorList;
10354 $count++;
10355  
10356 chomp $pattern;
10357 chomp $error;
10358  
10359 $msg .= "\n\n$pattern\n$error";
10360  
10361 # (Only show the first 2 errors - don't want a dialogue window as big as
10362 # the desktop)
10363 if ($count >= 2 && @errorList) {
10364  
10365 $msg .= "\n\n...";
10366 @errorList = ();
10367 }
10368  
10369 } until (! @errorList);
10370  
10371 $self->showMsgDialogue(
10372 'Check patterns',
10373 'error',
10374 $msg,
10375 'ok',
10376 undef,
10377 TRUE, # Preserve newline characters in $msg
10378 );
10379 }
10380 }
10381 });
10382 }
10383  
10384 # Add the button to the grid
10385 $button->set_hexpand(TRUE);
10386 $button->set_vexpand(FALSE);
10387 $grid->attach(
10388 $button,
10389 $leftAttach,
10390 $topAttach,
10391 ($rightAttach - $leftAttach),
10392 ($bottomAttach - $topAttach),
10393 );
10394  
10395 return $button;
10396 }
10397  
10398 # Add widgets - special functions for GA::EditWin::Generic::Interface and
10399 # GA::EditWin::Interface::Active
10400  
10401 sub useCheckButton {
10402  
10403 # Adapted from $self->addCheckButton
10404 # Adds a Gtk3::CheckButton with an accompnaying label at the specified position in the
10405 # window's Gtk3::Grid. Instead of setting an IV in $self->editHash, sets a key-value pair
10406 # in $self->attribHash
10407 #
10408 # Example calls:
10409 # my $checkButton = $self->useCheckButton($grid, 'Click me', 'some_attribute', TRUE,
10410 # 0, 6, 0, 1);
10411 # my $checkButton = $self->useCheckButton($grid, undef, 'some_attribute', TRUE,
10412 # 0, 6, 0, 1);
10413 #
10414 # Expected arguments
10415 # $grid - The tab's Gtk3::Grid object
10416 # $name - A 'name' for the checkbutton (displayed next to the button); if 'undef',
10417 # no name is displayed
10418 # $attrib - The name of the attribute set when the check button is toggled (matches
10419 # a key in $self->attribHash and GA::Interface::Trigger->attribHash)
10420 # $stateFlag - Flag set to FALSE if the checkbutton's state should be 'insensitive',
10421 # TRUE if it should be 'normal'
10422 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10423 # - The position of the checkbutton in the grid
10424 #
10425 # Optional arguments
10426 # $alignX, $alignY
10427 # - Used in the call to ->set_alignment; two values in the range 0-1
10428 # - If not specified, $alignX is set to 0, $alignY to 0.5
10429 #
10430 # Return values
10431 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
10432 # Otherwise the Gtk3::CheckButton created
10433  
10434 my (
10435 $self, $grid, $name, $attrib, $stateFlag, $leftAttach, $rightAttach, $topAttach,
10436 $bottomAttach, $check
10437 ) = @_;
10438  
10439 # Check for improper arguments
10440 if (
10441 ! defined $grid || ! defined $attrib || ! defined $stateFlag || ! defined $leftAttach
10442 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
10443 || defined $check
10444 ) {
10445 return $axmud::CLIENT->writeImproper($self->_objClass . '->useCheckButton', @_);
10446 }
10447  
10448 # Check that the position in the grid makes sense
10449 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10450  
10451 return undef;
10452 }
10453  
10454 # Create the checkbutton
10455 my $checkButton;
10456 if (defined $name && $name ne '') {
10457 $checkButton = Gtk3::CheckButton->new_with_label($name);
10458 } else {
10459 $checkButton = Gtk3::CheckButton->new();
10460 }
10461  
10462 $checkButton->set_active($self->editObj->ivShow('attribHash', $attrib));
10463 $checkButton->signal_connect('toggled' => sub {
10464  
10465 $self->ivAdd('attribHash', $attrib, $checkButton->get_active());
10466 });
10467  
10468 # Make the checkbutton insensitive, if $stateFlag is FALSE
10469 if (! $stateFlag) {
10470  
10471 $checkButton->set_state('insensitive');
10472 }
10473  
10474 # Add the checkbutton to the grid
10475 $checkButton->set_hexpand(TRUE);
10476 $checkButton->set_vexpand(FALSE);
10477 $grid->attach(
10478 $checkButton,
10479 $leftAttach,
10480 $topAttach,
10481 ($rightAttach - $leftAttach),
10482 ($bottomAttach - $topAttach),
10483 );
10484  
10485 return $checkButton;
10486 }
10487  
10488 sub useRadioButton {
10489  
10490 # Adapted from $self->addRadioButton
10491 # Adds a Gtk3::RadioButton at the specified position in the tab's Gtk3::Grid. Instead of
10492 # setting an IV in $self->editHash, sets a key-value pair in $self->attribHash
10493 #
10494 # Example calls:
10495 # my ($group, $button) = $self->useRadioButton(
10496 # $grid, undef, $name, 'some_attribute', $value, TRUE,
10497 # 0, 6, 0, 1);
10498 # my ($group2, $button2) = $self->useRadioButton(
10499 # $grid, $group, $name, 'some_attribute', $value, TRUE,
10500 # 0, 6, 0, 1, 0, 0.5);
10501 #
10502 # Expected arguments
10503 # $grid - The tab's Gtk3::Grid object
10504 # $group - Reference to the radio button group created, when the first button in the
10505 # group was added (if set to 'undef', this is the first button, and a
10506 # group will be created for it)
10507 # $name - A 'name' for the radio button (displayed next to the button); if 'undef',
10508 # no name is displayed
10509 # $attrib - The name of the attribute set when the radio button is toggled (matches
10510 # a key in $self->attribHash and GA::Interface::Trigger->attribHash)
10511 # $value - The value to which the attribute is set, when the radio button is selected
10512 # $stateFlag - Flag set to FALSE if the radiobutton's state should be 'insensitive',
10513 # TRUE if it should be 'normal'
10514 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10515 # - The position of the radiobutton in the grid
10516 #
10517 # Optional arguments
10518 # $alignLeft, $alignRight
10519 # - Used in the call to ->set_alignment; two values in the range 0-1
10520 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
10521 #
10522 # Return values
10523 # An empty list on improper arguments or if the widget's position in the Gtk3::Grid is
10524 # invalid
10525 # Otherwise a list containing two elements: the radio button $group and the
10526 # Gtk3::RadioButton created
10527  
10528 my (
10529 $self, $grid, $group, $name, $attrib, $value, $stateFlag, $leftAttach, $rightAttach,
10530 $topAttach, $bottomAttach, $alignLeft, $alignRight, $check
10531 ) = @_;
10532  
10533 # Local variables
10534 my @emptyList;
10535  
10536 # Check for improper arguments
10537 if (
10538 ! defined $grid || ! defined $attrib || ! defined $stateFlag || ! defined $leftAttach
10539 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
10540 || defined $check
10541 ) {
10542 $axmud::CLIENT->writeImproper($self->_objClass . '->useRadioButton', @_);
10543 return @emptyList;
10544 }
10545  
10546 # Check that the position in the grid makes sense
10547 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10548  
10549 return @emptyList;
10550 }
10551  
10552 # Set default alignment, if none specified
10553 if (! defined $alignLeft) {
10554  
10555 $alignLeft = 0;
10556 }
10557  
10558 if (! defined $alignRight) {
10559  
10560 $alignRight = 0.5;
10561 }
10562  
10563 # Create the radio button
10564 my $radioButton = Gtk3::RadioButton->new();
10565 # Add it to the existing group, if one was specified
10566 if (defined $group) {
10567  
10568 $radioButton->set_group($group);
10569 }
10570  
10571 # If $value is the one currently stored in $self->editObj->attribHash, mark this radio
10572 # button as active
10573 if (defined $value && $value eq $self->editObj->ivShow('attribHash', $attrib)) {
10574  
10575 $radioButton->set_active(TRUE);
10576 }
10577  
10578 $radioButton->signal_connect('toggled' => sub {
10579  
10580 # Set the attribute only if this radiobutton has been selected
10581 if ($radioButton->get_active()) {
10582  
10583 $self->ivAdd('attribHash', $attrib, $value);
10584 }
10585 });
10586  
10587 # Give the radio button a name, if one was specified
10588 if ($name) {
10589  
10590 $radioButton->set_label($name);
10591 }
10592  
10593 # Make the radio button insensitive, if $stateFlag is FALSE
10594 if (! $stateFlag) {
10595  
10596 $radioButton->set_state('insensitive');
10597 }
10598  
10599 # Set radio button's alignment
10600 $radioButton->set_alignment($alignLeft, $alignRight);
10601  
10602 # Add the radio button to the grid
10603 $radioButton->set_hexpand(FALSE);
10604 $radioButton->set_vexpand(FALSE);
10605 $grid->attach(
10606 $radioButton,
10607 $leftAttach,
10608 $topAttach,
10609 ($rightAttach - $leftAttach),
10610 ($bottomAttach - $topAttach),
10611 );
10612  
10613 return ($radioButton->get_group(), $radioButton);
10614 }
10615  
10616 sub useEntryWithIcon {
10617  
10618 # Adapted from $self->addEntryWithIcon
10619 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid. The entry contains
10620 # a stock icon to show whether the current contents of the entry is permissible
10621 # The stock icons used are 'gtk-yes' (for an acceptable value) and 'gtk-no' (for a
10622 # forbidden value)
10623 # Instead of setting an IV in $self->editHash, sets a key-value pair in $self->attribHash
10624 #
10625 # Example calls:
10626 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'int', 0, 1000,
10627 # 0, 6, 0, 1);
10628 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'odd', 1, 1001,
10629 # 0, 6, 0, 1);
10630 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'even', 0, 1000,
10631 # 0, 6, 0, 1);
10632 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'float', 0, 1000000,
10633 # 0, 6, 0, 1);
10634 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'string', 3, 16,
10635 # 0, 6, 0, 1);
10636 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'regex', 1, undef,
10637 # 0, 6, 0, 1);
10638 # my $entry = $self->useEntryWithIcon(
10639 # $grid, 'some_attribute', \&checkFunction, undef, undef,
10640 # 0, 6, 0, 1);
10641 #
10642 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'int', 0, 1000,
10643 # 0, 6, 0, 1, 16, 16);
10644 #
10645 # Expected arguments
10646 # $grid - The tab's Gtk3::Grid object
10647 # $attrib - The name of the attribute set when the user modifies the text in the entry
10648 # box
10649 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
10650 # function
10651 # - If 'int', an integer is expected with the specified min/max values
10652 # - If 'odd', an odd-numbered integer with the specified min/max value is
10653 # expected. If the minimum value is less than 1, 1 is used instead
10654 # - If 'even', an even-numbered integer with the specified min/max value is
10655 # expected. If the minimum value is less than 0, 0 is used instead
10656 # - If 'float', a floating point number is expected with the specified min/max
10657 # values
10658 # - If 'string', a string is expected (which might be a number) with the
10659 # specified min/max length
10660 # - If 'regex', a valid regex is expected with the specified min/max length
10661 # - If a function reference, a function is called which should return 'undef'
10662 # or 1, depending on the value of the entry; the icon is set accordingly
10663 # $min, $max - The values described above (ignored when $mode is a function reference).
10664 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
10665 # maximum
10666 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10667 # - The position of the entry in the grid
10668 #
10669 # Optional arguments
10670 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
10671 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
10672 #
10673 # Return values
10674 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
10675 # Otherwise the Gtk3::Entry created
10676  
10677 my (
10678 $self, $grid, $attrib, $mode, $min, $max, $leftAttach, $rightAttach, $topAttach,
10679 $bottomAttach, $widthChars, $maxChars, $check
10680 ) = @_;
10681  
10682 # Local variables
10683 my $current;
10684  
10685 # Check for improper arguments
10686 if (
10687 ! defined $grid || ! defined $attrib || ! defined $mode || ! defined $leftAttach
10688 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
10689 || defined $check
10690 ) {
10691 return $axmud::CLIENT->writeImproper($self->_objClass . '->useEntryWithIcon', @_);
10692 }
10693  
10694 # Check that the position in the grid makes sense
10695 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10696  
10697 return undef;
10698 }
10699  
10700 # Check that the minimum/maximum values specified are valid and, if not, fix them
10701 if (defined $min && defined $max && $min > $max) {
10702  
10703 # Use no maximum value...
10704 $max = undef;
10705 # ...and show a warning, because this shouldn't happen
10706 $self->session->writeWarning(
10707 'Minimum greater than maximum for attribute \'' . $attrib . '\'',
10708 $self->_objClass . '->addEntryWithIcon',
10709 );
10710 }
10711  
10712 if ($mode eq 'odd' && defined $min && $min < 1) {
10713  
10714 # Lowest value of $min (if specified) is 1
10715 $min = 1;
10716  
10717 } elsif ($mode eq 'even' && defined $min && $min < 0) {
10718  
10719 # Lowest value of $min (if specified) is 0
10720 $min = 0;
10721 }
10722  
10723 # Create the entry
10724 my $entry = Gtk3::Entry->new();
10725  
10726 # Display the existing value of the attribute
10727 $current = $self->editObj->ivShow('attribHash', $attrib);
10728 if (defined $current) {
10729  
10730 $entry->set_text($current);
10731  
10732 if (! $self->checkEntry($current, $mode, $min, $max)) {
10733 $entry->set_icon_from_stock('secondary', 'gtk-no');
10734 } else {
10735 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10736 }
10737  
10738 } else {
10739  
10740 # We still need to set the icon for an empty box
10741 if ($mode eq 'string' || $mode eq 'regex') {
10742  
10743 # Empty strings/regexes might be acceptable
10744 if (! $self->checkEntry('', $mode, $min, $max)) {
10745 $entry->set_icon_from_stock('secondary', 'gtk-no');
10746 } else {
10747 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10748 }
10749  
10750 } else {
10751  
10752 # Box is empty, so any $self->checkEntry test will fail (for $mode
10753 # set to a function reference, we'll have to assume that)
10754 $entry->set_icon_from_stock('secondary', 'gtk-no');
10755 }
10756 }
10757  
10758 # Customise the entry
10759 $entry->signal_connect('changed' => sub {
10760  
10761 my $value = $entry->get_text();
10762 # Check whether $value is a valid value, or not
10763 if (! $self->checkEntry($value, $mode, $min, $max)) {
10764  
10765 # Can't use this value
10766 $self->ivDelete('attribHash', $attrib);
10767 $entry->set_icon_from_stock('secondary', 'gtk-no');
10768  
10769 } else {
10770  
10771 # This is a valid value, so use it
10772 $self->ivAdd('attribHash', $attrib, $value);
10773 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10774 }
10775 });
10776  
10777 # Set the width, if specified
10778 if (defined $widthChars) {
10779  
10780 $entry->set_width_chars($widthChars);
10781 }
10782  
10783 # Set the maximum number of characters, if specified
10784 if (defined $maxChars) {
10785  
10786 $entry->set_max_length($maxChars);
10787 }
10788  
10789 # Add the entry to the grid
10790 $entry->set_hexpand(TRUE);
10791 $entry->set_vexpand(FALSE);
10792 $grid->attach(
10793 $entry,
10794 $leftAttach,
10795 $topAttach,
10796 ($rightAttach - $leftAttach),
10797 ($bottomAttach - $topAttach),
10798 );
10799  
10800 return $entry;
10801 }
10802  
10803 sub useComboBox {
10804  
10805 # Adapted from $self->addComboBox
10806 # Adds a Gtk3::ComboBox at the specified position in the window's Gtk3::Grid. Instead of
10807 # setting an IV in $self->editHash, sets a key-value pair in $self->attribHash
10808 #
10809 # Example calls:
10810 # my $comboBox = $self->useComboBox($grid, 'some_attribute', \@comboList, 'some_title',
10811 # 0, 6, 0, 1);
10812 # my $comboBox = $self->useComboBox($grid, 'some_attribute', \@comboList, '',
10813 # 0, 6, 0, 1);
10814 #
10815 # Expected arguments
10816 # $grid - The tab's Gtk3::Grid object
10817 # $attrib - The name of the attribute set when the check button is toggled (matches
10818 # a key in $self->attribHash and GA::Interface::Trigger->attribHash)
10819 # $listRef - Reference to a list with initial values (can be an empty list)
10820 # $title - A string used as a title, e.g. 'Choose your favourite colour' - if an
10821 # empty string, the item at the top of the combobox list is the current
10822 # value of the attribute
10823 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10824 # - The position of the combo box in the grid
10825 #
10826 # Return values
10827 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
10828 # Otherwise the Gtk3::ComboBox created
10829  
10830 my (
10831 $self, $grid, $attrib, $listRef, $title, $leftAttach, $rightAttach, $topAttach,
10832 $bottomAttach, $check
10833 ) = @_;
10834  
10835 # Local variables
10836 my $current;
10837  
10838 # Check for improper arguments
10839 if (
10840 ! defined $grid || ! defined $attrib || ! defined $listRef || ! defined $title
10841 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
10842 || ! defined $bottomAttach || defined $check
10843 ) {
10844 return $axmud::CLIENT->writeImproper($self->_objClass . '->useComboBox', @_);
10845 }
10846  
10847 # Check that the position in the grid makes sense
10848 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10849  
10850 return undef;
10851 }
10852  
10853 # Create the combobox
10854 my $comboBox = Gtk3::ComboBoxText->new();
10855  
10856 # Populate the combobox
10857 if ($title) {
10858  
10859 # The first item in the combobox list is a title
10860 $comboBox->append_text($title);
10861 $comboBox->set_active(0);
10862  
10863 } else {
10864  
10865 $current = $self->editObj->ivShow('attribHash', $attrib);
10866 if ($current) {
10867  
10868 # The first item is the current value of the IV, if there is one
10869 $comboBox->append_text($current);
10870 # Make this the active item
10871 $comboBox->set_active(0);
10872 }
10873 }
10874  
10875 foreach my $item (@$listRef) {
10876  
10877 # Don't show the current value of the IV twice
10878 if (! $current || $item ne $current) {
10879  
10880 $comboBox->append_text($item);
10881 }
10882 }
10883  
10884 $comboBox->signal_connect('changed' => sub {
10885  
10886 my $text = $comboBox->get_active_text();
10887  
10888 # If the user has selected the title, ignore it
10889 if (! $title || $text ne $title) {
10890  
10891 # If the user has selected the empty line at the top, set the attribute to an
10892 # empty string
10893 if (! $text) {
10894  
10895 $self->ivAdd('attribHash', $attrib, '');
10896  
10897 # Otherwise set the attribute to the specified value
10898 } else {
10899  
10900 $self->ivAdd('attribHash', $attrib, $text);
10901 }
10902 }
10903 });
10904  
10905 # Add the combobox to the grid
10906 $comboBox->set_hexpand(TRUE);
10907 $comboBox->set_vexpand(FALSE);
10908 $grid->attach(
10909 $comboBox,
10910 $leftAttach,
10911 $topAttach,
10912 ($rightAttach - $leftAttach),
10913 ($bottomAttach - $topAttach),
10914 );
10915  
10916 return $comboBox;
10917 }
10918  
10919 # Add widget support functions
10920  
10921 sub checkEntry {
10922  
10923 # Called by $self->addEntryWithIcon
10924 # Check whether the text entered in an entry box is a valid value for the IV, or not
10925 #
10926 # Expected arguments
10927 # $value - The value currently in the entry box
10928 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
10929 # function
10930 # - If 'int', an integer is expected with the specified min/max values
10931 # - If 'odd', an odd-numbered integer with the specified min/max value is
10932 # expected. If the minimum value is less than 1, 1 is used instead
10933 # - If 'even', an even-numbered integer with the specified min/max value is
10934 # expected. If the minimum value is less than 0, 0 is used instead
10935 # - If 'float', a floating point number is expected with the specified min/max
10936 # values
10937 # - If 'string', a string is expected (which might be a number) with the
10938 # specified min/max length
10939 # - If 'regex', a valid regex is expected with the specified min/max length
10940 # - If a function reference, a function is called which should return 'undef'
10941 # or 1, depending on the value of the entry; the icon is set accordingly
10942 # $min, $max - The values described above (ignored when $mode is a function reference).
10943 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
10944 # maximum
10945 #
10946 # Return values
10947 # 'undef' on improper arguments or if $value is an invalid value for the IV
10948 # 1 if $value is a valid value for the IV
10949  
10950 my ($self, $value, $mode, $min, $max, $check) = @_;
10951  
10952 # Local variables
10953 my $result;
10954  
10955 # Check for improper arguments
10956 if (! defined $value || ! defined $mode || defined $check) {
10957  
10958 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEntry', @_);
10959 }
10960  
10961 # 'int' mode
10962 if ($mode eq 'int') {
10963  
10964 if (
10965 ! defined $value
10966 || $value eq '' # Required for $entry->set_text('');
10967 || ! ($value =~ m/^\-?\d+$/)
10968 || (defined $min && $value < $min)
10969 || (defined $max && $value > $max)
10970 ) {
10971 # Invalid value
10972 return undef;
10973  
10974 } else {
10975  
10976 # Valid value
10977 return 1;
10978 }
10979  
10980 # 'odd' mode
10981 } elsif ($mode eq 'odd') {
10982  
10983 if (
10984 ! defined $value
10985 || $value eq '' # Required for $entry->set_text('');
10986 || ! ($value =~ m/^\-?\d+$/)
10987 || (defined $min && $value < $min)
10988 || (defined $max && $value > $max)
10989 || ! ($value % 2) # Number is even
10990 ) {
10991 # Invalid value
10992 return undef;
10993  
10994 } else {
10995  
10996 # Valid value
10997 return 1;
10998 }
10999  
11000 # 'even' mode
11001 } elsif ($mode eq 'even') {
11002  
11003 if (
11004 ! defined $value
11005 || $value eq '' # Required for $entry->set_text('');
11006 || ! ($value =~ m/^\-?\d+$/)
11007 || (defined $min && $value < $min)
11008 || (defined $max && $value > $max)
11009 || ! ($value % 2) # Number is even
11010 ) {
11011 # Invalid value
11012 return undef;
11013  
11014 } else {
11015  
11016 # Valid value
11017 return 1;
11018 }
11019  
11020 # 'float' mode
11021 } elsif ($mode eq 'float') {
11022  
11023 if (
11024 ! defined $value
11025 || $value eq '' # Required for $entry->set_text('');
11026 || ! ($value =~ /^[+-]?\d+\.?\d*$/)
11027 || (defined $min && $value < $min)
11028 || (defined $max && $value > $max)
11029 ) {
11030 # Invalid value
11031 return undef;
11032  
11033 } else {
11034  
11035 # Valid value
11036 return 1;
11037 }
11038  
11039 # 'string' mode
11040 } elsif ($mode eq 'string') {
11041  
11042 if (
11043 ! defined $value
11044 || (defined $min && length($value) < $min)
11045 || (defined $max && length($value) > $max)
11046 ) {
11047 # Invalid value
11048 return undef;
11049  
11050 } else {
11051  
11052 # Valid value
11053 return 1;
11054 }
11055  
11056  
11057 # 'regex' mode
11058 } elsif ($mode eq 'regex') {
11059  
11060 if (
11061 ! defined $value
11062 || (defined $min && length($value) < $min)
11063 || (defined $max && length($value) > $max)
11064 # ->regexCheck returns 'undef' for a valid regex, a string for an invalid one
11065 || $axmud::CLIENT->regexCheck($value)
11066 ) {
11067 # Invalid value
11068 return undef;
11069  
11070 } else {
11071  
11072 # Valid value
11073 return 1;
11074 }
11075  
11076 # $mode must be a function reference. Call the function so it can check $value and
11077 # return 'undef' or 1
11078 } else {
11079  
11080 return &$mode($self, $value);
11081 }
11082 }
11083  
11084 sub checkEntryIcon {
11085  
11086 # Called by the same function that called $self->addEntryWithIcon
11087 # When it's time to do something with the data entered, instead of having to call
11088 # $self->checkEntry for every entry box, we can just look at the icon
11089 # This function checks a list of Gtk3::Entry boxes and returns 1 if they are all showing the
11090 # 'gtk-ok' icon (meaning the values entered are acceptable)
11091 #
11092 # Expected arguments
11093 # @list - List of Gtk3::Entry boxes
11094 #
11095 # Return values
11096 # 'undef' on improper arguments, or if any of the entry boxes are using the 'gtk-no' icon
11097 # (meaning the value entered isn't acceptable) or if anything in @list is 'undef'
11098 # 1 if all the entry boxes are using the 'gtk-yes' icon (meaning the values entered are
11099 # all acceptable)
11100  
11101 my ($self, @list) = @_;
11102  
11103 # Check for improper arguments
11104 if (! @list) {
11105  
11106 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEntryIcon', @_);
11107 }
11108  
11109 foreach my $entry (@list) {
11110  
11111 # Check that the calling function didn't specify $entry4 when it meant to specify
11112 # $entry3
11113 if (! defined $entry) {
11114  
11115 return $self->writeError(
11116 'Undefined entry box',
11117 $self->_objClass . '->checkEntryIcon',
11118 );
11119  
11120 } elsif ($entry->get_icon_stock('secondary') ne 'gtk-yes') {
11121  
11122 return undef;
11123 }
11124 }
11125  
11126 # All values acceptable for this IV
11127 return 1;
11128 }
11129  
11130 sub setEntryIcon {
11131  
11132 # Called by the same function that called $self->addEntryWithIcon
11133 # If we need to manually change the entry's icon for some reason, this function can be
11134 # called
11135 # For example, if ->addEntryWithIcon is called with a function reference which sets the icon
11136 # every time the entry's text is changed, no IV is specified but we want an empty entry
11137 # box to be an acceptable value, this function can take care of it
11138 #
11139 # Expected arguments
11140 # $entry - The Gtk3::Entry whose icon should be modified
11141 # $flag - TRUE to use 'gtk-yes' (representing an acceptable value), FALSE to use
11142 # 'gtk-no' (representing an unacceptable value)
11143 #
11144 # Return values
11145 # 'undef' on improper arguments
11146 # 1 otherwise
11147  
11148 my ($self, $entry, $flag, $check) = @_;
11149  
11150 # Check for improper arguments
11151 if (! defined $entry || ! defined $flag || defined $check) {
11152  
11153 return $axmud::CLIENT->writeImproper($self->_objClass . '->setEntryIcon', @_);
11154 }
11155  
11156 if (! $flag) {
11157 $entry->set_icon_from_stock('secondary', 'gtk-no');
11158 } else {
11159 $entry->set_icon_from_stock('secondary', 'gtk-yes');
11160 }
11161  
11162 return 1;
11163 }
11164  
11165 sub resetEntryBoxes {
11166  
11167 # Empties the contents of any entry boxes appearing in a list of Gtk3 widgets, ignoring any
11168 # other widgets
11169 #
11170 # Expected arguments
11171 # (none besides $self)
11172 #
11173 # Optional arguments
11174 # @list - List of Gtk3 widgets (can be an empty list)
11175 #
11176 # Return values
11177 # 'undef' on improper arguments or if anything in @list is 'undef'
11178 # 1 otherwise
11179  
11180 my ($self, @list) = @_;
11181  
11182 # (No improper arguments to check)
11183  
11184 foreach my $widget (@list) {
11185  
11186 # Check that the calling function didn't specify $entry4 when it meant to specify
11187 # $entry3
11188 if (! defined $widget) {
11189  
11190 return $self->writeError(
11191 'Undefined widget',
11192 $self->_objClass . '->resetEntryBoxes',
11193 );
11194  
11195 } elsif ($widget->isa('Gtk3::Entry')) {
11196  
11197 $widget->set_text('');
11198 }
11199 }
11200  
11201 return 1;
11202 }
11203  
11204 sub addSimpleListButtons_listIV {
11205  
11206 # Adds four standard buttons used with GA::Obj::SimpleList widgets, when they're
11207 # displaying a list IV. The buttons are 'Add', 'Delete', 'Reset' and 'Clear'
11208 # NB The ->signal_connect method for the 'Add' button must be specified by the calling
11209 # function
11210 #
11211 # Example calls:
11212 # my $addButton = $self->addSimpleListButtons_listIV($grid, $slWidget, 'some_IV', 10);
11213 #
11214 # Expected arguments
11215 # $grid - The tab's Gtk3::Grid object
11216 # $slWidget - The GA::Obj::SimpleList object on which the buttons will act
11217 # $iv - The list IV in $self->editObj storing the data being edited
11218 # $rowNumber - On the current tab's grid, the row on which the buttons are put
11219 # $columns - The number of columns. For a straightforward list, 1, but many IVs
11220 # (particularly in profiles) have list IVs with data in groups of two,
11221 # three or more
11222 #
11223 # Optional arguments
11224 # @widgetList - List of Gtk3 widgets (entry boxes or combos) that are reset when the
11225 # 'Delete', 'Reset' and 'Clear' buttons are used. If the list is empty, no
11226 # widgets are reset
11227 #
11228 # Return values
11229 # 'undef' on improper arguments
11230 # Otherwise returns the Gtk::Button labelled 'Add', so the calling function can add a
11231 # ->signal_connect to it
11232  
11233 my ($self, $grid, $slWidget, $iv, $rowNumber, $columns, @widgetList) = @_;
11234  
11235 # Check for improper arguments
11236 if (
11237 ! defined $grid || ! defined $slWidget || ! defined $iv || ! defined $rowNumber
11238 || ! defined $columns
11239 ) {
11240 return $axmud::CLIENT->writeImproper(
11241 $self->_objClass . '->addSimpleListButtons_listIV',
11242 @_,
11243 );
11244 }
11245  
11246 # 'Add' button
11247 my $button = Gtk3::Button->new('Add');
11248 $button->set_tooltip_text('Add new value(s)');
11249 $grid->attach($button, 1, $rowNumber, 2, 1);
11250  
11251 # NB The signal_connect method for the 'Add' button must be specified by the callling
11252 # function. Here is some example code:
11253 #
11254 # $button->signal_connect('clicked' => sub {
11255 #
11256 # my ($pattern, $grpNum);
11257 #
11258 # $pattern = $entry->get_text();
11259 # $grpNum = $entry2->get_text();
11260 #
11261 # if ($self->checkEntryIcon($entry, $entry2)) {
11262 #
11263 # # Add new values to (the end of) the list IV
11264 # $self->addEditHash_listIV('myListIV',
11265 # undef, FALSE,
11266 # $pattern, $grpNum,
11267 # );
11268 #
11269 # # Refresh the simple list and reset entry boxes
11270 # $self->refreshList_listIV(
11271 # $slWidget,
11272 # scalar (@columnList / 2),
11273 # 'myListIV',
11274 # );
11275 #
11276 # $self->resetEntryBoxes($entry, $entry2);
11277 # }
11278 # });
11279  
11280 # 'Delete' button
11281 my $button2 = Gtk3::Button->new('Delete');
11282 $button2->signal_connect('clicked' => sub {
11283  
11284 # Get the selected row
11285 my ($index) = $slWidget->get_selected_indices();
11286 if (defined $index) {
11287  
11288 # Delete the value (or values) on this row
11289 $self->deleteEditHash_listIV($iv, ($index * $columns), $columns);
11290  
11291 # Refresh the simple list and reset entry boxes
11292 $self->refreshList_listIV($slWidget, $columns, $iv);
11293 $self->resetEntryBoxes(@widgetList);
11294 }
11295 });
11296 $button2->set_tooltip_text('Delete the selected value(s)');
11297 $grid->attach($button2, 6, $rowNumber, 2, 1);
11298  
11299 # 'Reset' button
11300 my $button3 = Gtk3::Button->new('Reset');
11301 $button3->signal_connect('clicked' => sub {
11302  
11303 # Remove this IV from $self->editHash, so that the IV in $self->editObj takes over
11304 $self->ivDelete('editHash', $iv);
11305  
11306 # Refresh the simple list and reset entry boxes
11307 $self->refreshList_listIV($slWidget, $columns, $iv);
11308 $self->resetEntryBoxes(@widgetList);
11309 });
11310 $button3->set_tooltip_text('Reset the list');
11311 $grid->attach($button3, 8, $rowNumber, 2, 1);
11312  
11313 # 'Clear' button
11314 my $button4 = Gtk3::Button->new('Clear');
11315 $button4->signal_connect('clicked' => sub {
11316  
11317 # Add an empty list to $self->editHash
11318 $self->ivAdd('editHash', $iv, []);
11319  
11320 # Refresh the simple list and reset entry boxes
11321 $self->refreshList_listIV($slWidget, $columns, $iv);
11322 $self->resetEntryBoxes(@widgetList);
11323 });
11324 $button4->set_tooltip_text('Clear the list of values');
11325 $grid->attach($button4, 10, $rowNumber, 2, 1);
11326  
11327 return $button;
11328 }
11329  
11330 sub addSimpleListButtons_hashIV {
11331  
11332 # Adds four standard buttons used with GA::Obj::SimpleList widgets, when they're
11333 # displaying a hash IV. The buttons are 'Add', 'Delete', 'Reset' and 'Clear'
11334 # NB The ->signal_connect method for the 'Add' button must be specified by the calling
11335 # function
11336 #
11337 # Example calls:
11338 # my $addButton = $self->addSimpleListButton_hashIV($grid, $slWidget, 'someIV', 10);
11339 #
11340 # Expected arguments
11341 # $grid - The tab's Gtk3::Grid object
11342 # $slWidget - The GA::Obj::SimpleList object on which the buttons will act
11343 # $iv - The hash IV in $self->editObj storing the data being edited
11344 # $rowNumber - On the current tab's grid, the row on which the buttons are put
11345 #
11346 # Optional arguments
11347 # @widgetList - List of Gtk3 widgets (entry boxes or combos) that are reset when the
11348 # 'Delete', 'Reset' and 'Clear' buttons are used. If the list is empty, no
11349 # widgets are reset
11350 #
11351 # Return values
11352 # 'undef' on improper arguments
11353 # Otherwise the Gtk::Button labelled 'Add', so the calling function can add a
11354 # ->signal_connect to it
11355  
11356 my ($self, $grid, $slWidget, $iv, $rowNumber, @widgetList) = @_;
11357  
11358 # Check for improper arguments
11359 if (! defined $grid || ! defined $slWidget || ! defined $iv || ! defined $rowNumber) {
11360  
11361 return $axmud::CLIENT->writeImproper(
11362 $self->_objClass . '->addSimpleListButtons_hashIV',
11363 @_,
11364 );
11365 }
11366  
11367 # 'Add' button
11368 my $button = Gtk3::Button->new('Add');
11369 $button->set_tooltip_text('Add a new key/value pair');
11370 $grid->attach($button, 1, $rowNumber, 2, 1);
11371  
11372 # NB The signal_connect method for the 'Add' button must be specified by the callling
11373 # function. Here is some example code:
11374 # $button->signal_connect('clicked' => sub {
11375 #
11376 # my ($key, $value);
11377 #
11378 # $key = $entry->get_text();
11379 # $value = $entry2->get_text();
11380 #
11381 # if ($self->checkEntryIcon($entry, $entry2)) {
11382 #
11383 # # Add a new key-value pair
11384 # $self->modifyEditHash_hashIV('myHashIV', $key, $value);
11385 #
11386 # # Refresh the simple list and reset entry boxes
11387 # $self->refreshList_hashIV($slWidget, scalar (@columnList / 2), 'myHashIV');
11388 # $self->resetEntryBoxes($entry, $entry2);
11389 # }
11390 # });
11391  
11392 # 'Delete' button
11393 my $button2 = Gtk3::Button->new('Delete');
11394 $button2->signal_connect('clicked' => sub {
11395  
11396 my ($key) = $self->getSimpleListData($slWidget, 0);
11397 if (defined $key) {
11398  
11399 # Delete the key-value pair from the hash
11400 $self->modifyEditHash_hashIV($iv, $key, undef, TRUE);
11401  
11402 # Refresh the simple list and reset entry boxes
11403 $self->refreshList_hashIV($slWidget, 2, $iv);
11404 $self->resetEntryBoxes(@widgetList);
11405 }
11406 });
11407 $button2->set_tooltip_text('Delete the selected key/value pair');
11408 $grid->attach($button2, 6, $rowNumber, 2, 1);
11409  
11410 # 'Reset' button
11411 my $button3 = Gtk3::Button->new('Reset');
11412 $button3->signal_connect('clicked' => sub {
11413  
11414 # Remove this IV from $self->editHash, so that the IV in $self->editObj takes over
11415 $self->ivDelete('editHash', $iv);
11416  
11417 # Refresh the simple list and reset entry boxes
11418 $self->refreshList_hashIV($slWidget, 2, $iv);
11419 $self->resetEntryBoxes(@widgetList);
11420 });
11421 $button3->set_tooltip_text('Reset the hash of key/value pairs');
11422 $grid->attach($button3, 8, $rowNumber, 2, 1);
11423  
11424 # 'Clear' button
11425 my $button4 = Gtk3::Button->new('Clear');
11426 $button4->signal_connect('clicked' => sub {
11427  
11428 # Add an empty hash to $self->editHash
11429 $self->ivAdd('editHash', $iv, {});
11430  
11431 # Refresh the simple list and reset entry boxes
11432 $self->refreshList_hashIV($slWidget, 2, $iv);
11433 $self->resetEntryBoxes(@widgetList);
11434 });
11435 $button4->set_tooltip_text('Clear the hash of key/value pairs');
11436 $grid->attach($button4, 10, $rowNumber, 2, 1);
11437  
11438 return $button;
11439 }
11440  
11441 sub refreshList_listIV {
11442  
11443 # Standard function for refreshing (or initialising) GA::Obj::SimpleList widgets when they
11444 # are displaying a list in two columns
11445 #
11446 # Expected arguments
11447 # $slWidget - The GA::Obj::SimpleList
11448 # $columns - The number of columns. Should be 2; this argument is retained for
11449 # consistency with other functions
11450 # $iv - The IV being displayed in the simple list
11451 #
11452 # Return values
11453 # 'undef' on improper arguments
11454 # 1 otherwise
11455  
11456 my ($self, $slWidget, $columns, $iv, $check) = @_;
11457  
11458 # Local variables
11459 my (
11460 $listRef, $row, $column,
11461 @ivList, @newList, @sortedList, @dataList,
11462 );
11463  
11464 # Check for improper arguments
11465 if (! defined $slWidget || ! defined $columns || ! defined $iv || defined $check) {
11466  
11467 return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshList_listIV', @_);
11468 }
11469  
11470 # Import the list being displayed
11471 if (defined $self->ivShow('editHash', $iv)) {
11472  
11473 # Use the current hash
11474 $listRef = $self->ivShow('editHash', $iv);
11475 @ivList = @$listRef;
11476  
11477 } else {
11478  
11479 # Use the original hash
11480 @ivList = $self->editObj->ivPeek($iv);
11481 }
11482  
11483 # Sort the list. If there is only one column, it's a straightforward sort; otherwise, we
11484 # have to convert @ivList into a two-dimensional list, in the form
11485 # $newList[row_number][column_number], and sort by columns
11486 if ($columns == 1) {
11487  
11488 # Straightforward sort
11489 @dataList = sort {lc($a) cmp lc($b)} (@ivList);
11490  
11491 } else {
11492  
11493 # Don't bother sorting, if there's only one row, if there are more than 2 columns or if
11494 # the IV name doesn't end in 'Hash'
11495 if (scalar @ivList > $columns && $columns == 2 && (substr($iv, -4) eq 'Hash')) {
11496  
11497 # Convert @ivList into a 2-dimensional list
11498 $row = -1;
11499 do {
11500  
11501 $row++;
11502 $newList[$row] = [splice (@ivList, 0, $columns)];
11503  
11504 } until (! @ivList);
11505  
11506 # Sort by the first column
11507 @sortedList = sort {lc($$a[0]) cmp lc($$b[0])} (@newList);
11508  
11509 # Flatten @newList into a 1-dimensional list, row by row
11510 foreach my $rowRef (@sortedList) {
11511  
11512 push (@dataList, @$rowRef);
11513 }
11514  
11515 } else {
11516  
11517 # Only one row, or too many columns to sort
11518 push (@dataList, @ivList);
11519 }
11520 }
11521  
11522 # Reset the simple list
11523 $self->resetListData($slWidget, [@dataList], $columns);
11524  
11525 return 1;
11526 }
11527  
11528 sub refreshList_hashIV {
11529  
11530 # Standard function for refreshing (or initialising) GA::Obj::SimpleList widgets, when
11531 # they're displaying a hash in two columns
11532 #
11533 # Expected arguments
11534 # $slWidget - The GA::Obj::SimpleList
11535 # $columns - The number of columns. Should be 2; this argument is retained for
11536 # consistency with other functions
11537 # $iv - The IV being displayed in the simple list
11538 #
11539 # Return values
11540 # 'undef' on improper arguments
11541 # 1 otherwise
11542  
11543 my ($self, $slWidget, $columns, $iv, $check) = @_;
11544  
11545 # Local variables
11546 my (
11547 $hashRef,
11548 @sortedList, @dataList,
11549 %ivHash,
11550 );
11551  
11552 # Check for improper arguments
11553 if (! defined $slWidget || ! defined $columns || ! defined $iv || defined $check) {
11554  
11555 return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshList_hashIV', @_);
11556 }
11557  
11558 # Import the hash being displayed
11559 if (defined $self->ivShow('editHash', $iv)) {
11560  
11561 # Use the current hash
11562 $hashRef = $self->ivShow('editHash', $iv);
11563 %ivHash = %$hashRef;
11564  
11565 } else {
11566  
11567 # Use the original hash
11568 %ivHash = $self->editObj->ivPeek($iv);
11569 }
11570  
11571 # Get a sorted list of keys, so they can be displayed in alphabetical order
11572 @sortedList = sort {lc($a) cmp lc($b)} (keys %ivHash);
11573  
11574 # Compile the simple list data
11575 foreach my $key (@sortedList) {
11576  
11577 push (@dataList, $key, $ivHash{$key});
11578 }
11579  
11580 # Reset the simple list
11581 $self->resetListData($slWidget, [@dataList], $columns);
11582  
11583 return 1;
11584 }
11585  
11586 sub resetComboBox {
11587  
11588 # Can be called by anything
11589 # Resets the contents of a combo box
11590 #
11591 # Expected arguments
11592 # $combo - The combo box to reset
11593 #
11594 # Optional arguments
11595 # @comboList - List of items to add to the combo box. If the list is empty, the combo
11596 # box is emptied
11597 #
11598 # Return values
11599 # 'undef' on improper arguments
11600 # 1 otherwise
11601  
11602 my ($self, $combo, @comboList) = @_;
11603  
11604 # Check for improper arguments
11605 if (! defined $combo) {
11606  
11607 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetComboBox', @_);
11608 }
11609  
11610 # Empty the combobox
11611 my $treeModel = $combo->get_model();
11612 $treeModel->clear();
11613  
11614 # Fill it with the new list of items
11615 if (@comboList) {
11616  
11617 foreach my $item (@comboList) {
11618  
11619 $combo->append_text($item);
11620 }
11621  
11622 $combo->set_active(0);
11623 }
11624  
11625 return 1;
11626 }
11627  
11628 # Data accessors
11629  
11630 sub getEditHash_scalarIV {
11631  
11632 # Can be called by anything
11633 # $self->editHash can contain scalar values, in the form
11634 # $hash{'name_of_iv'} = scalar_value
11635 # This function can be called to return the scalar value. However, if the IV hasn't yet been
11636 # added to $self->editHash, this function returns the contents of the IV in
11637 # $self->editObj, instead
11638 #
11639 # Expected arguments
11640 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11641 #
11642 # Return values
11643 # 'undef' on improper arguments
11644 # Otherwise, returns a scalar value (may be 'undef')
11645  
11646 my ($self, $iv, $check) = @_;
11647  
11648 # Check for improper arguments
11649 if (! defined $iv || defined $check) {
11650  
11651 return $axmud::CLIENT->writeImproper($self->_objClass . '->getEditHash_listIV', @_);
11652 }
11653  
11654 # Check the specified IV actually exists in $self->editHash
11655 if (! $self->ivExists('editHash', $iv)) {
11656  
11657 # It doesn't, so return the contents of the list IV, instead
11658 return $self->editObj->$iv;
11659  
11660 } else {
11661  
11662 return $self->ivShow('editHash', $iv);
11663 }
11664 }
11665  
11666 sub getEditHash_listIV {
11667  
11668 # Can be called by anything
11669 # $self->editHash can contain lists, in the form
11670 # $hash{'name_of_iv'} = reference_to_anonymous_list
11671 # This function can be called to return the contents of the dereferenced list. However, if
11672 # the IV hasn't yet been added to $self->editHash, this function returns the contents of
11673 # the IV in $self->editObj, instead
11674 #
11675 # Expected arguments
11676 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11677 #
11678 # Return values
11679 # An empty list on improper arguments
11680 # Otherwise, returns a list of values (might be empty)
11681  
11682 my ($self, $iv, $check) = @_;
11683  
11684 # Local variables
11685 my (
11686 $listRef,
11687 @emptyList,
11688 );
11689  
11690 # Check for improper arguments
11691 if (! defined $iv || defined $check) {
11692  
11693 $axmud::CLIENT->writeImproper($self->_objClass . '->getEditHash_listIV', @_);
11694 return @emptyList;
11695 }
11696  
11697 # Check the specified IV actually exists in $self->editHash
11698 if (! $self->ivExists('editHash', $iv)) {
11699  
11700 # It doesn't, so return the contents of the list IV, instead
11701 return $self->editObj->$iv;
11702  
11703 } else {
11704  
11705 $listRef = $self->ivShow('editHash', $iv);
11706 return @$listRef;
11707 }
11708 }
11709  
11710 sub getEditHash_hashIV {
11711  
11712 # Can be called by anything
11713 # $self->editHash can contain hashes, in the form
11714 # $hash{'name_of_iv'} = reference_to_anonymous_hash
11715 # This function can be called to return the contents of the dereferenced hash as a list.
11716 # However, if the IV hasn't yet been added to $self->editHash, this function returns the
11717 # contents of the IV in $self->editObj, instead
11718 #
11719 # Expected arguments
11720 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11721 #
11722 # Return values
11723 # An empty list on improper arguments
11724 # Otherwise, returns a hash of values (as a flat list, which might be empty)
11725  
11726 my ($self, $iv, $check) = @_;
11727  
11728 # Local variables
11729 my (
11730 $hashRef,
11731 @list, @emptyList,
11732 %hash,
11733 );
11734  
11735 # Check for improper arguments
11736 if (! defined $iv || defined $check) {
11737  
11738 $axmud::CLIENT->writeImproper($self->_objClass . '->getEditHash_hashIV', @_);
11739 return @emptyList;
11740 }
11741  
11742 # Check the specified IV actually exists in $self->editHash
11743 if (! $self->ivExists('editHash', $iv)) {
11744  
11745 # It doesn't, so return the contents of the hash IV, instead
11746 return $self->editObj->$iv;
11747  
11748 } else {
11749  
11750 $hashRef = $self->ivShow('editHash', $iv);
11751 return %$hashRef;
11752 }
11753 }
11754  
11755 sub addEditHash_listIV {
11756  
11757 # Can be called by anything
11758 # Adds a value (or group of values) to a list IV, and saves the whole list IV
11759 # If this IV hasn't been modified yet - i.e., if it is stored in $self->editObj but not in
11760 # $self->editHash, the list is copied from $self->editObj, modified, then saved to
11761 # $self->editHash
11762 #
11763 # Expected arguments
11764 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11765 # $index - The index at which to insert the value (or group of values). If 0, the
11766 # value(s) are inserted at the the start of the list (equivalent to
11767 # 'unshift'). If 'undef', the value(s) are inserted at the end of the
11768 # list (equivalent to 'push')
11769 # $replaceFlag
11770 # - If set to TRUE, the value(s) at $index (and onwards) are replaced. If set
11771 # to FALSE, the value(s) are inserted at this point
11772 # @valueList - The value(s) to add to the list
11773 #
11774 # Return values
11775 # 'undef' on improper arguments
11776 # 1 otherwise
11777  
11778 my ($self, $iv, $index, $replaceFlag, @valueList) = @_;
11779  
11780 # Local variables
11781 my @ivList;
11782  
11783 # Check for improper arguments
11784 if (! defined $iv || ! defined $replaceFlag || ! @valueList) {
11785  
11786 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEditHash_listIV', @_);
11787 }
11788  
11789 # Import the list from $self->editHash if it's there, or the original list from
11790 # $self->editObj otherwise
11791 @ivList = $self->getEditHash_listIV($iv);
11792  
11793 if ($replaceFlag && defined $index) {
11794  
11795 # Replace existing values
11796 for (my $count = $index; $count < ($index + scalar @valueList); $count++) {
11797  
11798 $ivList[$count] = shift @valueList;
11799 }
11800  
11801 } elsif (! $replaceFlag && defined $index) {
11802  
11803 # Add value(s) at the insertion point
11804 splice(@ivList, $index, 0, @valueList);
11805  
11806 } else {
11807  
11808 # ($index not defined)
11809 # Add values to the end of the list
11810 push (@ivList, @valueList);
11811 }
11812  
11813 # Save the modified list
11814 $self->ivAdd('editHash', $iv, \@ivList);
11815  
11816 return 1;
11817 }
11818  
11819 sub deleteEditHash_listIV {
11820  
11821 # Can be called by anything
11822 # Deletes a value (or group of values) from a list IV, and saves the whole list IV
11823 # If this IV hasn't been modified yet - i.e., if it is stored in $self->editObj but not in
11824 # $self->editHash, the list is copied from $self->editObj, modified, then saved to
11825 # $self->editHash
11826 #
11827 # Expected arguments
11828 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11829 # $index - The index at which to remove the value (or group of values). If 0, the
11830 # value(s) are deleted from the the start of the list (equivalent to 'shift').
11831 # If 'undef', the value(s) are deleted the end of the list (roughly equivalent
11832 # to 'pop').
11833 # $number - The number of values to delete (usually 1)
11834 #
11835 # Return values
11836 # 'undef' on improper arguments
11837 # 1 otherwise
11838  
11839 my ($self, $iv, $index, $number, $check) = @_;
11840  
11841 # Local variables
11842 my @ivList;
11843  
11844 # Check for improper arguments
11845 if (! defined $iv || ! defined $number || defined $check) {
11846  
11847 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteEditHash_listIV', @_);
11848 }
11849  
11850 # Import the list from $self->editHash if it's there, or the original list from
11851 # $self->editObj otherwise
11852 @ivList = $self->getEditHash_listIV($iv);
11853  
11854 if (defined $index) {
11855  
11856 splice(@ivList, $index, $number);
11857  
11858 } else {
11859  
11860 # Delete values from the end of a list
11861 splice(@ivList, ($index * -1), $number);
11862 }
11863  
11864 # Save the modified list
11865 $self->ivAdd('editHash', $iv, \@ivList);
11866  
11867 return 1;
11868 }
11869  
11870 sub modifyEditHash_hashIV {
11871  
11872 # Can be called by anything
11873 # Adds (or replaces) a single key-value pair in a hash IV, and saves the whole hash IV
11874 # If this IV hasn't been modified yet - i.e., if it is stored in $self->editObj but not in
11875 # $self->editHash, the hash is copied from $self->editObj, modified, then saved to
11876 # $self->editHash
11877 #
11878 # Expected arguments
11879 # $iv - The IV to be checked; a key in $self->editHash or an IV in
11880 # $self->editObj
11881 # $key, $value - The key/value pair to replace ($value can be 'undef')
11882 #
11883 # Optional arguments
11884 # $deleteFlag - If set to TRUE, the key-value pair is deleted from the hash ($value is
11885 # ignored, and should be set to 'undef')
11886 #
11887 # Return values
11888 # 'undef' on improper arguments
11889 # 1 otherwise
11890  
11891 my ($self, $iv, $key, $value, $deleteFlag, $check) = @_;
11892  
11893 # Local variables
11894 my %ivHash;
11895  
11896 # Check for improper arguments
11897 if (! defined $iv || ! defined $key || defined $check) {
11898  
11899 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyEditHash_hashIV', @_);
11900 }
11901  
11902 # Import the hash from $self->editHash if it's there, or the original hash from
11903 # $self->editObj otherwise
11904 if ($self->ivExists('editHash', $iv)) {
11905 %ivHash = $self->getEditHash_hashIV($iv);
11906 } else {
11907 %ivHash = $self->editObj->$iv;
11908 }
11909  
11910 if ($deleteFlag) {
11911  
11912 # Delete the key-value pair
11913 if (exists $ivHash{$key}) {
11914  
11915 delete $ivHash{$key};
11916 }
11917  
11918 } else {
11919  
11920 # Add the key-value pair
11921 $ivHash{$key} = $value;
11922 }
11923  
11924 # Save the modified hash
11925 $self->ivAdd('editHash', $iv, \%ivHash);
11926  
11927 return 1;
11928 }
11929  
11930 sub updateListDataWithKey {
11931  
11932 # Can be called by any tab function to update the data in a GA::Obj::SimpleList when it is
11933 # storing data in two columns representing the contents of a hash
11934 # The first column is the key, the second column its corresponding value
11935 # If the key already exists in the list, it is replaced; otherwise a new key-value pair is
11936 # added to the simple list
11937 # If the key is not defined or an empty string, it isn't added to the simple list
11938 #
11939 # Expected arguments
11940 # $slWidget - The GA::Obj::SimpleList to modify
11941 # $key - The key to add to the list, which will eventually be stored as a hash
11942 # $value - Its corresponding value
11943 #
11944 # Return values
11945 # 'undef' on improper arguments, or if $key is 'undef' or an empty string
11946 # 1 otherwise
11947  
11948 my ($self, $slWidget, $key, $value, $check) = @_;
11949  
11950 # Local variables
11951 my (
11952 @list,
11953 %hash,
11954 );
11955  
11956 # Check for improper arguments
11957 if (! defined $slWidget || defined $check) {
11958  
11959 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateListDataWithKey', @_);
11960 }
11961  
11962 # If $key is 'undef' or an empty string, do nothing
11963 if (! $key) {
11964  
11965 return undef;
11966 }
11967  
11968 # Convert the data stored in the GA::Obj::SimpleList into a hash
11969 %hash = $self->convertListDataToHash($slWidget);
11970  
11971 # Add the key-value pair
11972 $hash{$key} = $value;
11973  
11974 # Get a list of keys in the hash, so we can sort it alphabetically
11975 @list = sort {lc($a) cmp lc($b)} (keys %hash);
11976  
11977 # Reset the GA::Obj::SimpleList
11978 @{$slWidget->{data}} = ();
11979  
11980 foreach my $sortedKey (@list) {
11981  
11982 push (@{$slWidget->{data}}, [$sortedKey, $hash{$sortedKey}]);
11983 }
11984  
11985 return 1;
11986 }
11987  
11988 sub findKeyInListData {
11989  
11990 # Can be called by any tab function to check the data in a GA::Obj::SimpleList when it is
11991 # storing data in two columns representing the contents of a hash
11992 # The first column is the key, the second column its corresponding value
11993 # Checks whether the specified key exists in list's data
11994 #
11995 # Expected arguments
11996 # $slWidget - The GA::Obj::SimpleList to modify
11997 # $key - The key to add to the list's data
11998 #
11999 # Return values
12000 # undef on improper arguments, if $key is 'undef' or an empty string or if the key doesn't
12001 # exist in the list's data
12002 # 1 if the key would exist in the hash, if the list's data were converted to a hash right
12003 # now
12004  
12005 my ($self, $slWidget, $key, $check) = @_;
12006  
12007 # Local variables
12008 my (
12009 @list,
12010 %hash,
12011 );
12012  
12013 # Check for improper arguments
12014 if (! defined $slWidget || defined $check) {
12015  
12016 return $axmud::CLIENT->writeImproper($self->_objClass . '->findKeyInListData', @_);
12017 }
12018  
12019 # If $key is 'undef' or an empty string, do nothing
12020 if (! $key) {
12021  
12022 return undef;
12023 }
12024  
12025 # Convert the data stored in the GA::Obj::SimpleList into a hash
12026 %hash = $self->convertListDataToHash($slWidget);
12027  
12028 # See whether the key exists
12029 if (exists $hash{$key}) {
12030 return 1;
12031 } else {
12032 return undef;
12033 }
12034 }
12035  
12036 sub convertListDataToHash {
12037  
12038 # Can be called by any tab function to convert the data in a GA::Obj::SimpleList (in which
12039 # data is stored in two columns) into a hash
12040 #
12041 # Expected arguments
12042 # $slWidget - The GA::Obj::SimpleList to use
12043 #
12044 # Return values
12045 # An empty hash on improper arguments
12046 # Otherwise, returns the hash
12047  
12048 my ($self, $slWidget, $check) = @_;
12049  
12050 # Local variables
12051 my (
12052 @listRefList,
12053 %emptyHash, %hash,
12054 );
12055  
12056 # Check for improper arguments
12057 if (! defined $slWidget || defined $check) {
12058  
12059 $axmud::CLIENT->writeImproper($self->_objClass . '->convertListDataToHash', @_);
12060 return %emptyHash; # Returns an empty hash
12061 }
12062  
12063 @listRefList = @{$slWidget->{data}};
12064 foreach my $listRef (@listRefList) {
12065  
12066 $hash{$$listRef[0]} = $$listRef[1];
12067 }
12068  
12069 return %hash;
12070 }
12071  
12072 sub storeListData {
12073  
12074 # Can be called by any tab function to store the data in a GA::Obj::SimpleList in
12075 # $self->editHash
12076 #
12077 # Expected arguments
12078 # $slWidget - The GA::Obj::SimpleList to use
12079 # $iv - The name of the instance variable in $self->editHash where the list is
12080 # stored
12081 #
12082 # Return values
12083 # 'undef' on improper arguments
12084 # 1 otherwise
12085  
12086 my ($self, $slWidget, $iv, $check) = @_;
12087  
12088 # Local variables
12089 my (@storeList, @listOfRefs);
12090  
12091 # Check for improper arguments
12092 if (! defined $slWidget || ! defined $iv || defined $check) {
12093  
12094 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeListData', @_);
12095 }
12096  
12097 @listOfRefs = @{$slWidget->{data}};
12098 foreach my $ref (@listOfRefs) {
12099  
12100 push (@storeList, @$ref);
12101 }
12102  
12103 $self->ivAdd('editHash', $iv, \@storeList);
12104  
12105 return 1;
12106 }
12107  
12108 sub storeListColumnInList {
12109  
12110 # Can be called by any tab function to store the data from a single column in a
12111 # GA::Obj::SimpleList as a list in $self->editHash
12112 #
12113 # Expected arguments
12114 # $slWidget - The GA::Obj::SimpleList to use
12115 # $iv - The name of the instance variable in $self->editHash in which the column's
12116 # data is stored
12117 # $column - The number of the chosen column
12118 #
12119 # Return values
12120 # 'undef' on improper arguments
12121 # 1 otherwise
12122  
12123 my ($self, $slWidget, $iv, $column, $check) = @_;
12124  
12125 # Local variables
12126 my (
12127 @listOfRefs, @dataList, @saveList,
12128 %storeHash,
12129 );
12130  
12131 # Check for improper arguments
12132 if (! defined $slWidget || ! defined $iv || ! defined $column || defined $check) {
12133  
12134 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeListColumnInList', @_);
12135 }
12136  
12137 @listOfRefs = @{$slWidget->{data}};
12138 foreach my $ref (@listOfRefs) {
12139  
12140 @dataList = @$ref;
12141 push (@saveList, $dataList[$column]);
12142 }
12143  
12144 $self->ivAdd('editHash', $iv, \@saveList);
12145  
12146 return 1;
12147 }
12148  
12149 sub storeListDataInHash {
12150  
12151 # Can be called by any tab function to store the data in a GA::Obj::SimpleList in
12152 # $self->editHash
12153 # This is a companion function to $self->storeListData (which stores the data as a list);
12154 # this function stores the data as a hash
12155 #
12156 # Expected arguments
12157 # $slWidget - Reference to a GA::Obj::SimpleList
12158 # $iv - The name of the instance variable in $self->editHash where the hash is
12159 # stored
12160 #
12161 # Return values
12162 # 'undef' on improper arguments
12163 # 1 otherwise
12164  
12165 my ($self, $slWidget, $iv, $check) = @_;
12166  
12167 # Local variables
12168 my (
12169 @listOfRefs, @dataList,
12170 %storeHash,
12171 );
12172  
12173 # Check for improper arguments
12174 if (! defined $slWidget || ! defined $iv || defined $check) {
12175  
12176 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeListDataInHash', @_);
12177 }
12178  
12179 @listOfRefs = @{$slWidget->{data}};
12180 foreach my $ref (@listOfRefs) {
12181  
12182 @dataList = @$ref;
12183 $storeHash{$dataList[0]} = $dataList[1];
12184 }
12185  
12186 $self->ivAdd('editHash', $iv, \%storeHash);
12187  
12188 return 1;
12189 }
12190  
12191 # Standard tabs
12192  
12193 sub privateDataTab {
12194  
12195 # Standard private data tab - stores data in a single hash IV, such as the ->privateHash in
12196 # all profiles. The contents of the hash is displayed in a simple list. Each key's value
12197 # can itself be a scalar, list or hash, each of which can be edited from the tab
12198 # Currently used by the 'edit' windows for profiles, world model objects, exit model
12199 # objects and quests
12200 #
12201 # Expected arguments
12202 # $hashIV - The hash IV to be edited
12203 # $tabName - A name to display on the tab, with one letter highlighted as a keyboard
12204 # shortcut (e.g. '_Private')
12205 # $titleLabel - The main label to display at the top of the tab, e.g. 'Private data hash'
12206 # (displayed in bold)
12207 # $minorLabel - The label to display just below the main label (displayed in italics)
12208 #
12209 # Return values
12210 # 'undef' on improper arguments
12211 # 1 otherwise
12212  
12213 my ($self, $hashIV, $tabName, $titleLabel, $minorLabel, $check) = @_;
12214  
12215 # Local variables
12216 my (@columnList, @comboList);
12217  
12218 # Check for improper arguments
12219 if (
12220 ! defined $hashIV || ! defined $tabName || ! defined $titleLabel
12221 || ! defined $minorLabel || defined $check
12222 ) {
12223 return $axmud::CLIENT->writeImproper($self->_objClass . '->privateDataTab', @_);
12224 }
12225  
12226 # Tab setup
12227 my $grid = $self->addTab(
12228 $self->notebook,
12229 $tabName,
12230 [$titleLabel],
12231 );
12232  
12233 # Private settings hash
12234 $self->addLabel($grid, '<b>' . $titleLabel . '</b>',
12235 0, 12, 0, 1);
12236 $self->addLabel($grid, '<i>' . $minorLabel . '</i>',
12237 1, 12, 1, 2);
12238  
12239 # Add a simple list
12240 @columnList = (
12241 'Key', 'text',
12242 'Type', 'text',
12243 'Value(s)', 'text',
12244 );
12245  
12246 my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
12247 1, 12, 2, 10);
12248  
12249 # Initialise the simple list
12250 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
12251  
12252 # Add an entry for adding new data to the private hash
12253 $self->addLabel($grid, 'Key',
12254 1, 3, 10, 11);
12255 # Show an icon for when something is entered; however the icon isn't checked (as would
12256 # normally happen)
12257 my $entry = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12258 3, 6, 10, 11);
12259  
12260 # The $key's corresponding value is either a scalar, a reference to a list or a reference to
12261 # a hash
12262 # Add three buttons to allow the user to add one of these three types of value
12263 my $button = $self->addButton($grid, 'Add scalar...', 'Add a scalar value', undef,
12264 6, 8, 10, 11);
12265 $button->signal_connect('clicked' => sub {
12266  
12267 my (
12268 $key,
12269 %ivHash,
12270 );
12271  
12272 $key = $entry->get_text();
12273  
12274 # Check the key hasn't already been created
12275 %ivHash = $self->getEditHash_hashIV($hashIV);
12276 if (! exists $ivHash{$key}) {
12277  
12278 # Prompt the user for a scalar value
12279 $self->promptScalar(
12280 $hashIV,
12281 $key, # Mode 2
12282 FALSE,
12283 undef,
12284 FALSE,
12285 'privateDataTab_refreshList',
12286 $slWidget,
12287 scalar (@columnList / 2),
12288 $hashIV,
12289 );
12290  
12291 # Reset the entry box
12292 $entry->set_text('');
12293 }
12294 });
12295  
12296 my $button2 = $self->addButton($grid, 'Add list...', 'Add a list value', undef,
12297 8, 10, 10, 11);
12298 $button2->signal_connect('clicked' => sub {
12299  
12300 my (
12301 $key,
12302 %ivHash,
12303 );
12304  
12305 $key = $entry->get_text();
12306  
12307 # Check the key hasn't already been created
12308 %ivHash = $self->getEditHash_hashIV($hashIV);
12309 if (! exists $ivHash{$key}) {
12310  
12311 # Prompt the user for a list value
12312 $self->promptList(
12313 $hashIV,
12314 $key, # Mode 2
12315 undef,
12316 FALSE,
12317 'privateDataTab_refreshList',
12318 $slWidget,
12319 scalar (@columnList / 2),
12320 $hashIV,
12321 );
12322  
12323 # Reset the entry box
12324 $entry->set_text('');
12325 }
12326 });
12327  
12328 my $button3 = $self->addButton($grid, 'Add hash...', 'Add a hash value', undef,
12329 10, 12, 10, 11);
12330 $button3->signal_connect('clicked' => sub {
12331  
12332 my (
12333 $key,
12334 %ivHash,
12335 );
12336  
12337 $key = $entry->get_text();
12338  
12339 # Check the key hasn't already been created
12340 %ivHash = $self->getEditHash_hashIV($hashIV);
12341 if (! exists $ivHash{$key}) {
12342  
12343 # Prompt the user for a hash value
12344 $self->promptHash(
12345 $hashIV,
12346 $key, # Mode 2
12347 undef,
12348 FALSE,
12349 'privateDataTab_refreshList',
12350 $slWidget,
12351 scalar (@columnList / 2),
12352 $hashIV,
12353 );
12354  
12355 # Reset the entry box
12356 $entry->set_text('');
12357 }
12358 });
12359  
12360 # Add the standard editing button
12361 my $button4 = Gtk3::Button->new('Edit');
12362 $button4->signal_connect('clicked' => sub {
12363  
12364 my (
12365 $key, $type,
12366 %ivHash,
12367 );
12368  
12369 ($key) = $self->getSimpleListData($slWidget, 0);
12370 %ivHash = $self->getEditHash_hashIV($hashIV);
12371 if (defined $key && exists $ivHash{$key}) {
12372  
12373 $type = ref $ivHash{$key};
12374  
12375 # Call ->promptScalar, ->promptList and ->promptHash
12376 if ($type eq 'ARRAY') {
12377  
12378 $self->promptList(
12379 $hashIV,
12380 $key, # Mode 2
12381 undef,
12382 FALSE,
12383 'privateDataTab_refreshList',
12384 $slWidget,
12385 scalar (@columnList / 2),
12386 $hashIV,
12387 );
12388  
12389 } elsif ($type eq 'HASH') {
12390  
12391 $self->promptHash(
12392 $hashIV,
12393 $key, # Mode 2
12394 undef,
12395 FALSE,
12396 'privateDataTab_refreshList',
12397 $slWidget,
12398 scalar (@columnList / 2),
12399 $hashIV,
12400 );
12401  
12402 } else {
12403  
12404 # Prompt the user for a scalar value
12405 $self->promptScalar(
12406 $hashIV,
12407 $key, # Mode 2
12408 FALSE,
12409 undef,
12410 FALSE,
12411 'privateDataTab_refreshList',
12412 $slWidget,
12413 scalar (@columnList / 2),
12414 $hashIV,
12415 );
12416 }
12417 }
12418 });
12419 $button4->set_tooltip_text('Edit the selected key');
12420 $grid->attach($button4, 1, 11, 3, 1);
12421  
12422 my $button5 = Gtk3::Button->new('Delete');
12423 $button5->signal_connect('clicked' => sub {
12424  
12425 my ($key) = $self->getSimpleListData($slWidget, 0);
12426 if (defined $key) {
12427  
12428 # Delete the key-value pair from the hash
12429 $self->modifyEditHash_hashIV($hashIV, $key, undef, TRUE);
12430  
12431 # Update the simple list
12432 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
12433 }
12434 });
12435 $button5->set_tooltip_text('Delete the selected key');
12436 $grid->attach($button5, 6, 11, 2, 1);
12437  
12438 my $button6 = Gtk3::Button->new('Reset');
12439 $button6->signal_connect('clicked' => sub {
12440  
12441 # Remove this IV from $self->editHash, so that the IV in $self->editObj takes over
12442 $self->ivDelete('editHash', $hashIV);
12443  
12444 # Update the simple list
12445 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
12446 });
12447 $button6->set_tooltip_text('Reset the list of keys');
12448 $grid->attach($button6, 8, 11, 2, 1);
12449  
12450 my $button7 = Gtk3::Button->new('Clear');
12451 $button7->signal_connect('clicked' => sub {
12452  
12453 # Add an empty hash to $self->editHash
12454 $self->ivAdd('editHash', $hashIV, {});
12455  
12456 # Update the simple list
12457 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
12458 });
12459 $button7->set_tooltip_text('Clear the list of keys');
12460 $grid->attach($button7, 10, 11, 2, 1);
12461  
12462 # Tab complete
12463 return 1;
12464 }
12465  
12466 sub privateDataTab_refreshList {
12467  
12468 # Called by $self->privateDataTab to refresh the simple list
12469 #
12470 # Expected arguments
12471 # $slWidget - The GA::Obj::SimpleList
12472 # $columns - The number of columns
12473 # $hashIV - The hash IV being edited
12474 #
12475 # Return values
12476 # 'undef' on improper arguments
12477 # 1 otherwise
12478  
12479 my ($self, $slWidget, $columns, $hashIV, $check) = @_;
12480  
12481 # Local variables
12482 my (
12483 @dataList,
12484 %ivHash,
12485 );
12486  
12487 # Check for improper arguments
12488 if (! defined $slWidget || ! defined $columns || ! defined $hashIV || defined $check) {
12489  
12490 return $axmud::CLIENT->writeImproper(
12491 $self->_objClass . '->privateDataTab_refreshList',
12492 @_,
12493 );
12494 }
12495  
12496 # Import the IV (for convenience)
12497 %ivHash = $self->getEditHash_hashIV($hashIV);
12498  
12499 # Compile the simple list data
12500 foreach my $key (sort {lc($a) cmp lc($b)} (keys %ivHash)) {
12501  
12502 my (
12503 $value, $typeString, $valueString, $type,
12504 %hash,
12505 );
12506  
12507 $value = $ivHash{$key};
12508  
12509 if (! defined $value) {
12510  
12511 $typeString = 'scalar';
12512 $valueString = '<undef>';
12513  
12514 } else {
12515  
12516 $type = ref $value;
12517 if ($type eq 'ARRAY') {
12518  
12519 $typeString = 'list';
12520 foreach my $item (@$value) {
12521  
12522 if (! defined $valueString) {
12523 $valueString = $item;
12524 } else {
12525 $valueString .= ', ' . $item;
12526 }
12527 }
12528  
12529 } elsif ($type eq 'HASH') {
12530  
12531 $typeString = 'hash';
12532 foreach my $thisKey (sort {lc($a) cmp lc($b)} (keys %$value)) {
12533  
12534 my $thisValue = $$value{$thisKey};
12535 if (! defined $thisValue) {
12536  
12537 $thisValue = '<undef>';
12538 }
12539  
12540 if (! defined $valueString) {
12541 $valueString = $thisKey . ':' . $thisValue;
12542 } else {
12543 $valueString .= ', ' . $thisKey . ':' . $thisValue;
12544 }
12545 }
12546  
12547 } else {
12548  
12549 $typeString = 'scalar';
12550 $valueString = $value;
12551 }
12552 }
12553  
12554 push (@dataList,
12555 $key,
12556 $typeString,
12557 $valueString,
12558 );
12559 }
12560  
12561 # Reset the simple list
12562 $self->resetListData($slWidget, [@dataList], $columns);
12563  
12564 return 1;
12565 }
12566  
12567 # Shared tabs (shared by GA::EditWin::Profile::Char and GA::EditWin::Task)
12568  
12569 sub objects1Tab {
12570  
12571 # Objects1 tab
12572 #
12573 # Expected arguments
12574 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
12575 #
12576 # Return values
12577 # 'undef' on improper arguments
12578 # 1 otherwise
12579  
12580 my ($self, $innerNotebook, $check) = @_;
12581  
12582 # Local variables
12583 my (
12584 $page, $charObj,
12585 @columnList,
12586 %objHash,
12587 );
12588  
12589 # Check for improper arguments
12590 if (! defined $innerNotebook || defined $check) {
12591  
12592 return $axmud::CLIENT->writeImproper($self->_objClass . '->objects1Tab', @_);
12593 }
12594  
12595 # Tab setup. This tab is used in the task 'pref' window, and an identical copy used in the
12596 # character profile 'edit' window
12597 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
12598 $page = 'Page _3';
12599 } else {
12600 $page = 'Page _1';
12601 }
12602  
12603 my $grid = $self->addTab(
12604 $innerNotebook,
12605 $page,
12606 ['Protected objects'],
12607 );
12608  
12609 # Decide which character profile we're using
12610 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
12611 $charObj = $self->session->currentChar;
12612 } else {
12613 $charObj = $self->editObj;
12614 }
12615  
12616 # Protected objects
12617 $self->addLabel($grid, '<b>Protected objects</b>',
12618 0, 12, 0, 1);
12619 $self->addLabel($grid,
12620 '<i>List of objects which enjoy semi-protection against being sold and dropped</i>',
12621 1, 12, 1, 2);
12622  
12623 # Add a simple list
12624 @columnList = (
12625 'Categories', 'text', # ->categoryList
12626 'Main noun', 'text', # ->noun
12627 'Other nouns', 'text', # ->otherNounList
12628 'Adjs', 'text', # ->adjList
12629 'Pseudo adjs', 'text', # ->pseudoAdjList
12630 'Unknowns', 'text', # ->unknownWordList
12631 );
12632  
12633 my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
12634 1, 12, 2, 9);
12635  
12636 # Create a hash to link lines in the simple list to objects in the protected objects list,
12637 # in the form
12638 # $objHash{line_number} = blessed_reference_of_protected_object
12639 # Each time the simple list is refreshed, the hash is updated
12640 %objHash = $self->objects1Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12641  
12642 # Add buttons
12643 my $button = $self->addButton($grid,
12644 'Unprotect',
12645 'Delete the selected protected object',
12646 undef,
12647 1, 3, 9, 10,
12648 TRUE); # Irreversible
12649 $button->signal_connect('clicked' => sub {
12650  
12651 my ($index, $lineRef, $obj, $cmd, $match, $count);
12652  
12653 ($index) = $slWidget->get_selected_indices();
12654 if (defined $index) {
12655  
12656 $obj = $objHash{$index};
12657  
12658 if ($charObj) { # Check there is a current character profile
12659  
12660 # Find the object's position in the protected objects list maintained by the
12661 # character profile (which may possibly have changed, since the simple list
12662 # was last updated)
12663 $count = -1;
12664 foreach my $element ($charObj->protectObjList) {
12665  
12666 $count++;
12667  
12668 if ($element eq $obj) {
12669  
12670 $match = $count;
12671 }
12672 }
12673  
12674 if (defined $match) {
12675  
12676 # Unprotect the object. The ';unprotectobject' command lists objects
12677 # starting from 1, not 0 (so we must add 1 to $match)
12678 $self->session->pseudoCmd(
12679 'unprotectobject ' . ($match + 1),
12680 $self->pseudoCmdMode,
12681 );
12682  
12683 %objHash = $self->objects1Tab_refreshList(
12684 $slWidget,
12685 scalar (@columnList / 2),
12686 $charObj,
12687 );
12688 }
12689 }
12690 }
12691 });
12692  
12693 my $button2 = $self->addButton($grid, 'Edit...', 'Edit the protected object', undef,
12694 3, 5, 9, 10);
12695 $button2->signal_connect('clicked' => sub {
12696  
12697 my ($index, $obj, $childWinObj);
12698  
12699 ($index) = $slWidget->get_selected_indices();
12700 if (defined $index && exists $objHash{$index}) {
12701  
12702 $obj = $objHash{$index};
12703  
12704 # Open an 'edit' window for the protected object
12705 $childWinObj = $self->createFreeWin(
12706 'Games::Axmud::EditWin::Protect',
12707 $self,
12708 $self->session,
12709 'Edit protected object \'' . $obj->noun . '\'',
12710 $obj,
12711 FALSE, # Not temporary
12712 );
12713  
12714 if ($childWinObj) {
12715  
12716 # When the 'edit' window closes, update the simple list
12717 $self->add_childDestroy(
12718 $childWinObj,
12719 'objects1Tab_refreshList',
12720 [$slWidget, (scalar @columnList / 2), $charObj],
12721 );
12722 }
12723 }
12724 });
12725  
12726 my $button3 = $self->addButton($grid,
12727 'Dump list',
12728 'Display the list of protected objects in the \'main\' window',
12729 undef,
12730 8, 10, 9, 10);
12731 $button3->signal_connect('clicked' => sub {
12732  
12733 $self->session->pseudoCmd('listprotectobject', $self->pseudoCmdMode);
12734  
12735 %objHash
12736 = $self->objects1Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12737 });
12738  
12739 my $button4 = $self->addButton($grid,
12740 'Refresh list',
12741 'Refresh the list of protected objects',
12742 undef,
12743 10, 12, 9, 10);
12744 $button4->signal_connect('clicked' => sub {
12745  
12746 # Refresh the simple list
12747 %objHash
12748 = $self->objects1Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12749  
12750 # If there is no current character profile (and we need one), the buttons (except for
12751 # the 'refresh list' button) must be insensitive
12752 if ($charObj) {
12753 $self->sensitiseWidgets($button, $button2);
12754 } else {
12755 $self->desensitiseWidgets($button, $button2);
12756 }
12757 });
12758  
12759 my $button5 = $self->addButton($grid,
12760 'Protect objects matching words:',
12761 'Protect objects matching this list of words',
12762 undef,
12763 1, 5, 10, 11,
12764 TRUE); # Irreversible
12765 my $entry = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12766 5, 12, 10, 11);
12767 $button5->signal_connect('clicked' => sub {
12768  
12769 my $wordString = $entry->get_text();
12770  
12771 if ($self->checkEntryIcon($entry)) {
12772  
12773 # Protect objects matching these words
12774 $self->session->pseudoCmd(
12775 'protectobject ' . $wordString,
12776 $self->pseudoCmdMode,
12777 );
12778  
12779 # Refresh the simple list and reset the entry boxes
12780 %objHash = $self->objects1Tab_refreshList(
12781 $slWidget,
12782 scalar (@columnList / 2),
12783 $charObj,
12784 );
12785 $self->resetEntryBoxes($entry);
12786 }
12787 });
12788  
12789 my $button6 = $self->addButton($grid,
12790 'Monitor objects matching words:',
12791 'Monitor objects matching this list of words',
12792 undef,
12793 1, 5, 11, 12,
12794 TRUE); # Irreversible
12795 my $entry2 = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12796 5, 12, 11, 12);
12797 $button6->signal_connect('clicked' => sub {
12798  
12799 my $wordString = $entry2->get_text();
12800  
12801 if ($self->checkEntryIcon($entry2)) {
12802  
12803 # Monitor objects matching these words
12804 $self->session->pseudoCmd(
12805 'monitorobject ' . $wordString,
12806 $self->pseudoCmdMode,
12807 );
12808  
12809 # Refresh the simple list and reset the entry boxes
12810 %objHash = $self->objects1Tab_refreshList(
12811 $slWidget,
12812 scalar (@columnList / 2),
12813 $charObj,
12814 );
12815 $self->resetEntryBoxes($entry2);
12816 }
12817 });
12818  
12819 # Widgets can't be manipulated when this isn't a current profile (or a current task)
12820 if (! $self->currentFlag) {
12821  
12822 $button->set_sensitive(FALSE);
12823 $button2->set_sensitive(FALSE);
12824 $button3->set_sensitive(FALSE);
12825 $button4->set_sensitive(FALSE);
12826 $button5->set_sensitive(FALSE);
12827 $button6->set_sensitive(FALSE);
12828 $entry->set_sensitive(FALSE);
12829 $entry2->set_sensitive(FALSE);
12830 }
12831  
12832 # Tab complete
12833 return 1;
12834 }
12835  
12836 sub objects1Tab_refreshList {
12837  
12838 # Called by $self->objects1Tab to reset the GA::Obj::SimpleList
12839 #
12840 # Expected arguments
12841 # $slWidget - The GA::Obj::SimpleList
12842 # $columns - The number of columns in the list
12843 #
12844 # Optional arguments
12845 # $charObj - The character profile whose list of protected objects we're showing.
12846 # If set to 'undef', it's because there is no current character and,
12847 # because we need one, we therefore show an empty list
12848 #
12849 # Return values
12850 # An empty hash on improper arguments
12851 # Otherwise, a hash which links lines in the simple list to the objects it contains
12852 # - which replaces the hash %objHash in $self->objects1Tab
12853  
12854 my ($self, $slWidget, $columns, $charObj, $check) = @_;
12855  
12856 # Local variables
12857 my (
12858 $count,
12859 @objList, @dataList,
12860 %emptyHash, %objHash,
12861 );
12862  
12863 # Check for improper arguments
12864 if (! defined $slWidget || ! defined $columns || defined $check) {
12865  
12866 $axmud::CLIENT->writeImproper($self->_objClass . '->objects1Tab_refreshList', @_);
12867 return %emptyHash;
12868 }
12869  
12870 # Don't display anything if there is no specified character profile
12871 if (! $charObj) {
12872  
12873 $self->resetListData($slWidget, [], $columns);
12874  
12875 } else {
12876  
12877 # Import the list of protected objects
12878 @objList = $charObj->protectObjList;
12879  
12880 # Refresh the simple list, and create a new hash of objects linked to the line they
12881 # appear on
12882 $count = -1;
12883  
12884 # Compile the simple list data
12885 foreach my $obj (@objList) {
12886  
12887 $count++;
12888  
12889 push (@dataList,
12890 join(' ', $obj->categoryList),
12891 $obj->noun,
12892 join(' ', $obj->otherNounList),
12893 join(' ', $obj->adjList),
12894 join(' ', $obj->pseudoAdjList),
12895 join(' ', $obj->unknownWordList),
12896 );
12897  
12898 $objHash{$count} = $obj;
12899 }
12900  
12901 # Reset the simple list
12902 $self->resetListData($slWidget, [@dataList], $columns);
12903 }
12904  
12905 return %objHash;
12906 }
12907  
12908 sub objects2Tab {
12909  
12910 # Objects2 tab
12911 #
12912 # Expected arguments
12913 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
12914 #
12915 # Return values
12916 # 'undef' on improper arguments
12917 # 1 otherwise
12918  
12919 my ($self, $innerNotebook, $check) = @_;
12920  
12921 # Local variables
12922 my (
12923 $page, $charObj,
12924 @columnList,
12925 %objHash,
12926 );
12927  
12928 # Check for improper arguments
12929 if (! defined $innerNotebook || defined $check) {
12930  
12931 return $axmud::CLIENT->writeImproper($self->_objClass . '->objects2Tab', @_);
12932 }
12933  
12934 # Tab setup. This tab is used in the task 'pref' window, and an identical copy used in the
12935 # character profile 'edit' window
12936 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
12937 $page = 'Page _4';
12938 } else {
12939 $page = 'Page _2';
12940 }
12941  
12942 my $grid = $self->addTab(
12943 $innerNotebook,
12944 $page,
12945 ['Monitored objects'],
12946 );
12947  
12948 # Decide which character profile we're using
12949 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
12950 $charObj = $self->session->currentChar;
12951 } else {
12952 $charObj = $self->editObj;
12953 }
12954  
12955 # Monitored objects
12956 $self->addLabel($grid, '<b>Monitored objects</b>',
12957 0, 12, 0, 1);
12958 $self->addLabel($grid,
12959 '<i>List of objects whose condition is monitored by the Condition task</i>',
12960 1, 12, 1, 2);
12961  
12962 # Add a simple list
12963 @columnList = (
12964 'Categories', 'text', # ->categoryList
12965 'Main noun', 'text', # ->noun
12966 'Other nouns', 'text', # ->otherNounList
12967 'Adjs', 'text', # ->adjList
12968 'Pseudo adjs', 'text', # ->pseudoAdjList
12969 'Unknowns', 'text', # ->unknownWordList
12970 );
12971  
12972 my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
12973 1, 12, 2, 9);
12974  
12975 # Create a hash to link lines in the simple list to objects in the monitored objects list,
12976 # in the form
12977 # $objHash{line_number} = blessed_reference_of_monitored_object
12978 # Each time the simple list is refreshed, the hash is updated
12979 %objHash = $self->objects2Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12980  
12981 # Add buttons
12982 my $button = $self->addButton($grid,
12983 'Unmonitor',
12984 'Delete the selected monitored object',
12985 undef,
12986 1, 3, 9, 10,
12987 TRUE); # Irreversible
12988 $button->signal_connect('clicked' => sub {
12989  
12990 my ($index, $lineRef, $obj, $cmd, $match, $count);
12991  
12992 ($index) = $slWidget->get_selected_indices();
12993 if (defined $index) {
12994  
12995 $obj = $objHash{$index};
12996  
12997 if ($charObj) { # Check there is a current character profile
12998  
12999 # Find the object's position in the monitored objects list maintained by the
13000 # character profile (which may possibly have changed, since the simple list
13001 # was last updated)
13002 $count = -1;
13003 foreach my $element ($charObj->monitorObjList) {
13004  
13005 $count++;
13006  
13007 if ($element eq $obj) {
13008  
13009 $match = $count;
13010 }
13011 }
13012  
13013 if (defined $match) {
13014  
13015 # Unmonitor the object. The ';unmonitortobject' command lists objects
13016 # starting from 1, not 0 (so we must add 1 to $match)
13017 $self->session->pseudoCmd(
13018 'unmonitorobject ' . ($match + 1),
13019 $self->pseudoCmdMode,
13020 );
13021  
13022 %objHash = $self->objects2Tab_refreshList(
13023 $slWidget,
13024 scalar (@columnList / 2),
13025 $charObj,
13026 );
13027 }
13028 }
13029 }
13030 });
13031  
13032 my $button2 = $self->addButton($grid, 'Edit...', 'Edit the monitored object', undef,
13033 3, 5, 9, 10);
13034 $button2->signal_connect('clicked' => sub {
13035  
13036 my ($index, $obj, $childWinObj);
13037  
13038 ($index) = $slWidget->get_selected_indices();
13039 if (defined $index) {
13040  
13041 $obj = $objHash{$index};
13042  
13043 # Open an 'edit' window for the monitored object (the same 'edit' window is used for
13044 # both protected and monitored objects, at the moment)
13045 $childWinObj = $self->createFreeWin(
13046 'Games::Axmud::EditWin::Protect',
13047 $self,
13048 $self->session,
13049 'Edit monitored object \'' . $obj->noun . '\'',
13050 $obj,
13051 FALSE, # Not temporary
13052 );
13053  
13054 if ($childWinObj) {
13055  
13056 # When the 'edit' window closes, update the simple list
13057 $self->add_childDestroy(
13058 $childWinObj,
13059 'objects2Tab_refreshList',
13060 [$slWidget, (scalar @columnList / 2), $charObj],
13061 );
13062 }
13063 }
13064 });
13065  
13066 my $button3 = $self->addButton($grid,
13067 'Dump list',
13068 'Display the list of monitored objects in the \'main\' window',
13069 undef,
13070 8, 10, 9, 10);
13071 $button3->signal_connect('clicked' => sub {
13072  
13073 $self->session->pseudoCmd('listmonitorobject', $self->pseudoCmdMode);
13074  
13075 %objHash
13076 = $self->objects2Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
13077 });
13078  
13079 my $button4 = $self->addButton($grid,
13080 'Refresh list',
13081 'Refresh the list of monitored objects',
13082 undef,
13083 10, 12, 9, 10);
13084 $button4->signal_connect('clicked' => sub {
13085  
13086 # Refresh the simple list
13087 %objHash
13088 = $self->objects2Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
13089  
13090 # If there is no current character profile (and we need one), the buttons (except for
13091 # the 'refresh list' button) must be insensitive
13092 if ($charObj) {
13093 $self->sensitiseWidgets($button, $button2);
13094 } else {
13095 $self->desensitiseWidgets($button, $button2);
13096 }
13097 });
13098  
13099 my $button5 = $self->addButton($grid,
13100 'Protect objects matching words:',
13101 'Protect objects matching this list of words',
13102 undef,
13103 1, 5, 10, 11,
13104 TRUE); # Irreversible
13105  
13106 my $entry = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
13107 5, 12, 10, 11);
13108  
13109 $button5->signal_connect('clicked' => sub {
13110  
13111 my $wordString = $entry->get_text();
13112  
13113 if ($self->checkEntryIcon($entry)) {
13114  
13115 # Protect objects matching these words
13116 $self->session->pseudoCmd(
13117 'protectobject ' . $wordString,
13118 $self->pseudoCmdMode,
13119 );
13120  
13121 # Refresh the simple list and reset the entry boxes
13122 %objHash = $self->objects2Tab_refreshList(
13123 $slWidget,
13124 scalar(@columnList / 2),
13125 $charObj,
13126 );
13127  
13128 $self->resetEntryBoxes($entry);
13129 }
13130 });
13131  
13132 my $button6 = $self->addButton($grid,
13133 'Monitor objects matching words:',
13134 'Monitor objects matching this list of words',
13135 undef,
13136 1, 5, 11, 12,
13137 TRUE); # Irreversible
13138 my $entry2 = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
13139 5, 12, 11, 12);
13140 $button6->signal_connect('clicked' => sub {
13141  
13142 my $wordString = $entry2->get_text();
13143  
13144 if ($self->checkEntryIcon($entry2)) {
13145  
13146 # Monitor objects matching these words
13147 $self->session->pseudoCmd(
13148 'monitorobject ' . $wordString,
13149 $self->pseudoCmdMode,
13150 );
13151  
13152 # Refresh the simple list and reset the entry boxes
13153 %objHash = $self->objects2Tab_refreshList(
13154 $slWidget,
13155 scalar(@columnList / 2),
13156 $charObj,
13157 );
13158  
13159 $self->resetEntryBoxes($entry2);
13160 }
13161 });
13162  
13163 # Widgets can't be manipulated when this isn't a current profile (or a current task)
13164 if (! $self->currentFlag) {
13165  
13166 $button->set_sensitive(FALSE);
13167 $button2->set_sensitive(FALSE);
13168 $button3->set_sensitive(FALSE);
13169 $button4->set_sensitive(FALSE);
13170 $button5->set_sensitive(FALSE);
13171 $button6->set_sensitive(FALSE);
13172 $entry->set_sensitive(FALSE);
13173 $entry2->set_sensitive(FALSE);
13174 }
13175  
13176 # Tab complete
13177 return 1;
13178 }
13179  
13180 sub objects2Tab_refreshList {
13181  
13182 # Called by $self->objects2Tab to reset the GA::Obj::SimpleList
13183 #
13184 # Expected arguments
13185 # $slWidget - The GA::Obj::SimpleList
13186 # $columns - The number of columns in the list
13187 #
13188 # Optional arguments
13189 # $charObj - The character profile whose list of monitored objects we're showing.
13190 # If set to 'undef', it's because there is no current character and,
13191 # because we need one, we therefore show an empty list
13192 #
13193 # Return values
13194 # An empty hash on improper arguments
13195 # Otherwise, a hash which links lines in the simple list to the objects it contains
13196 # - which replaces the hash %objHash in $self->objects2Tab
13197  
13198 my ($self, $slWidget, $columns, $charObj, $check) = @_;
13199  
13200 # Local variables
13201 my (
13202 $count,
13203 @objList, @dataList,
13204 %emptyHash, %objHash,
13205 );
13206  
13207 # Check for improper arguments
13208 if (! defined $slWidget || ! defined $columns || defined $check) {
13209  
13210 $axmud::CLIENT->writeImproper($self->_objClass . '->objects2Tab_refreshList', @_);
13211 return %emptyHash;
13212 }
13213  
13214 # Don't display anything if there is no specified character profile
13215 if (! $charObj) {
13216  
13217 $self->resetListData($slWidget, [], $columns);
13218  
13219 } else {
13220  
13221 # Import the list of monitored objects
13222 @objList = $charObj->monitorObjList;
13223  
13224 # Refresh the simple list, and create a new hash of objects linked to the line they
13225 # appear on
13226 $count = -1;
13227  
13228 # Compile the simple list data
13229 foreach my $obj (@objList) {
13230  
13231 $count++;
13232 push (@dataList,
13233 join(' ', $obj->categoryList),
13234 $obj->noun,
13235 join(' ', $obj->otherNounList),
13236 join(' ', $obj->adjList),
13237 join(' ', $obj->pseudoAdjList),
13238 join(' ', $obj->unknownWordList),
13239 );
13240  
13241 $objHash{$count} = $obj;
13242 }
13243  
13244 # Reset the simple list
13245 $self->resetListData($slWidget, [@dataList], $columns);
13246 }
13247  
13248 return %objHash;
13249 }
13250  
13251 # Shared tabs (shared by GA::EditWin::Generic::ModelObj and GA::PrefWin::Search)
13252  
13253 sub openChildEditWin {
13254  
13255 # Opens an 'edit' window for a different world model object (e.g. after clicking the 'Edit'
13256 # button on one of the 'Family' tabs)
13257 #
13258 # Expected arguments
13259 # $number - The number of the world model object for which to open an 'edit' window
13260 #
13261 # Return values
13262 # 'undef' on improper arguments or if the model object doesn't seem to exist
13263 # 1 otherwise
13264  
13265 my ($self, $number, $check) = @_;
13266  
13267 # Local variables
13268 my $obj;
13269  
13270 # Check for improper arguments
13271 if (! defined $number || defined $check) {
13272  
13273 return $axmud::CLIENT->writeImproper($self->_objClass . '->openChildEditWin', @_);
13274 }
13275  
13276 # Check that the object really exists
13277 if (! $self->session->worldModelObj->ivExists('modelHash', $number)) {
13278  
13279 return undef;
13280  
13281 } else {
13282  
13283 $obj = $self->session->worldModelObj->ivShow('modelHash', $number);
13284 }
13285  
13286 # Open up an 'edit' window to edit the object
13287 $self->createFreeWin(
13288 'Games::Axmud::EditWin::ModelObj::' . ucfirst($obj->category),
13289 $self,
13290 $self->session,
13291 'Edit ' . $obj->category . ' model object #' . $obj->number,
13292 $obj,
13293 FALSE, # Not temporary,
13294 );
13295  
13296 return 1;
13297 }
13298  
13299 # Shared tabs (shared by GA::EditWin::Interface::Active and GA::EditWin::Interface::Trigger,
13300 # etc
13301  
13302 sub triggerAttributesTab {
13303  
13304 # TriggerAttributes tab
13305 #
13306 # Expected arguments
13307 # (none besides $self)
13308 #
13309 # Return values
13310 # 'undef' on improper arguments
13311 # 1 otherwise
13312  
13313 my ($self, $check) = @_;
13314  
13315 # Check for improper arguments
13316 if (defined $check) {
13317  
13318 return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerAttributesTab', @_);
13319 }
13320  
13321 # Tab setup
13322 # Create a notebook within the main one, so that we have two rows of tabs
13323 my $innerNotebook = $self->addInnerNotebookTabs($self->notebook, '_Attributes');
13324  
13325 # Add tabs to the inner notebook
13326 $self->triggerAttributes1Tab($innerNotebook);
13327 $self->triggerAttributes2Tab($innerNotebook);
13328  
13329 return 1;
13330 }
13331  
13332 sub triggerAttributes1Tab {
13333  
13334 # TriggerAttributes1Tab tab
13335 #
13336 # Expected arguments
13337 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
13338 #
13339 # Return values
13340 # 'undef' on improper arguments
13341 # 1 otherwise
13342  
13343 my ($self, $innerNotebook, $check) = @_;
13344  
13345 # Check for improper arguments
13346 if (! defined $innerNotebook || defined $check) {
13347  
13348 return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerAttributes1Tab', @_);
13349 }
13350  
13351 # Tab setup
13352 my $grid = $self->addTab(
13353 $innerNotebook,
13354 'Page _1',
13355 ['Trigger attributes'],
13356 );
13357  
13358 # Trigger attributes
13359 $self->addLabel($grid, '<b>Trigger attributes</b>',
13360 0, 12, 0, 1);
13361  
13362 # Left column
13363 $self->useCheckButton(
13364 $grid,
13365 'Ignore the trigger response (e.g. just apply a style)',
13366 'ignore_response',
13367 TRUE,
13368 1, 6, 1, 2);
13369 $self->useCheckButton($grid, 'Ignore case', 'ignore_case', TRUE,
13370 1, 6, 2, 3);
13371 $self->useCheckButton($grid, 'Keep checking triggers after a match', 'keep_checking', TRUE,
13372 1, 6, 3, 4);
13373 $self->useCheckButton($grid, 'Splitter trigger', 'splitter', TRUE,
13374 1, 6, 4, 5);
13375 $self->useCheckButton(
13376 $grid, 'Split after matching pattern, not before', 'split_after', TRUE,
13377 1, 6, 5, 6);
13378 $self->useCheckButton(
13379 $grid, 'Split line multiple times, if multiple matches', 'keep_splitting', TRUE,
13380 1, 6, 6, 7);
13381 $self->useCheckButton($grid, 'Rewriter trigger', 'rewriter', TRUE,
13382 1, 6, 7, 8);
13383 $self->useCheckButton($grid, 'Rewrite every matching part of line', 'rewrite_global', TRUE,
13384 1, 6, 8, 9);
13385  
13386 # Right column
13387 my $checkButton = $self->useCheckButton(
13388 $grid, 'Only fire in session\'s default pane', 'default_pane', TRUE,
13389 7, 12, 1, 2);
13390 $self->addLabel($grid, 'Fire in named pane',
13391 7, 9, 2, 3);
13392 my $entry = $self->addEntry($grid, undef, TRUE,
13393 9, 12, 2, 3,
13394 8, 8);
13395 $entry->set_text($self->editObj->ivShow('attribHash', 'pane_name'));
13396 if ($entry->get_text()) {
13397  
13398 $checkButton->set_sensitive(FALSE);
13399 }
13400  
13401 $entry->signal_connect('changed' => sub {
13402  
13403 my $text = $entry->get_text();
13404  
13405 # If the user has emptied the entry box, set the attribute to an empty string
13406 if (! $text) {
13407  
13408 $self->ivAdd('attribHash', 'pane_name', '');
13409 $checkButton->set_sensitive(TRUE);
13410  
13411 # Otherwise set the attribute to the specified value
13412 } else {
13413  
13414 $self->ivAdd('attribHash', 'pane_name', $text);
13415 $checkButton->set_active(FALSE);
13416 $checkButton->set_sensitive(FALSE);
13417 }
13418 });
13419  
13420 $self->useCheckButton($grid, 'Require a prompt to fire', 'need_prompt', TRUE,
13421 7, 12, 3, 4);
13422 $self->useCheckButton($grid, 'Require a login to fire', 'need_login', TRUE,
13423 7, 12, 4, 5);
13424 $self->useCheckButton($grid, 'Omit (gag) from output', 'gag', TRUE,
13425 7, 12, 5, 6);
13426 $self->useCheckButton($grid, 'Omit (gag) from logfile', 'gag_log', TRUE,
13427 7, 12, 6, 7);
13428 $self->useCheckButton($grid, 'Temporary trigger', 'temporary', TRUE,
13429 7, 12, 7, 8);
13430 $self->addLabel($grid, 'Cooldown (in seconds)',
13431 7, 9, 8, 9);
13432 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
13433 9, 12, 8, 9,
13434 8, 8);
13435  
13436 # Tab complete
13437 return 1;
13438 }
13439  
13440 sub triggerAttributes2Tab {
13441  
13442 # TriggerAttributes2Tab tab
13443 #
13444 # Expected arguments
13445 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
13446 #
13447 # Return values
13448 # 'undef' on improper arguments
13449 # 1 otherwise
13450  
13451 my ($self, $innerNotebook, $check) = @_;
13452  
13453 # Local variables
13454 my (@grpNumList, @comboList, @comboList2);
13455  
13456 # Check for improper arguments
13457 if (! defined $innerNotebook || defined $check) {
13458  
13459 return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerAttributes2Tab', @_);
13460 }
13461  
13462 # Tab setup
13463 my $grid = $self->addTab(
13464 $innerNotebook,
13465 'Page _2',
13466 ['Trigger styles'],
13467 );
13468  
13469 # (Need just a little extra space to make everything fit)
13470 $grid->set_column_spacing($self->spacingPixels - 1);
13471 $grid->set_row_spacing($self->spacingPixels - 1);
13472  
13473 # Trigger styles
13474 $self->addLabel($grid, '<b>Trigger styles</b>',
13475 0, 12, 0, 1);
13476  
13477 # Top left
13478 my ($group, $radioButton) = $self->useRadioButton(
13479 $grid, undef,
13480 'Mode 0', # Radio button name
13481 'style_mode', # Attribute to set
13482 0, # Attribute set to this value when toggled
13483 TRUE, # Sensitive widget
13484 1, 2, 1, 2);
13485 $self->addLabel($grid, 'Don\'t apply styles',
13486 2, 5, 1, 2);
13487  
13488 ($group, $radioButton) = $self->useRadioButton(
13489 $grid, $group, 'Mode -1', 'style_mode', -1, TRUE,
13490 1, 2, 2, 3);
13491 $self->addLabel($grid, 'Apply style to whole line',
13492 2, 5, 2, 3);
13493  
13494 # Top right
13495 ($group, $radioButton) = $self->useRadioButton(
13496 $grid, $group, 'Mode -2', 'style_mode', -2, TRUE,
13497 5, 7, 1, 2);
13498 $self->addLabel($grid, 'Apply style to matched text',
13499 7, 10, 1, 2);
13500  
13501 my ($group2, $radioButton2) = $self->useRadioButton(
13502 $grid, $group,
13503 'Mode n',
13504 'style_mode',
13505 -3, # Non-standard value; set to correct value by $self->saveChanges
13506 TRUE,
13507 5, 7, 2, 3);
13508 $self->addLabel($grid, 'Apply style to matched substring #:',
13509 7, 10, 2, 3);
13510 @grpNumList = (1, 2, 3, 4, 5, 6, 7, 8, 9);
13511 my $combo = $self->useComboBox(
13512 $grid,
13513 '_substr_num',
13514 \@grpNumList,
13515 'Select:',
13516 10, 12, 2, 3);
13517  
13518 if (
13519 $self->editObj->ivShow('attribHash', 'style_mode')
13520 && $self->editObj->ivShow('attribHash', 'style_mode') > 0
13521 ) {
13522 # Style mode is 1 or more, which corresponds to the radio button on the top-right
13523 $radioButton2->set_active(TRUE);
13524 $combo->set_active($self->editObj->ivShow('attribHash', 'style_mode'));
13525 }
13526  
13527 # Bottom left
13528 $self->addLabel($grid, '<u>Trigger style to apply:</u>',
13529 1, 12, 3, 4);
13530  
13531 $self->triggerAttributesTab_addRadioButtons($grid, 'Italics:', 'style_italics', 4);
13532 $self->triggerAttributesTab_addRadioButtons($grid, 'Underline:', 'style_underline', 5);
13533 $self->triggerAttributesTab_addRadioButtons($grid, 'Slow blink:', 'style_blink_slow', 6);
13534 $self->triggerAttributesTab_addRadioButtons($grid, 'Fast blink:', 'style_blink_fast', 7);
13535 $self->triggerAttributesTab_addRadioButtons($grid, 'Strike-through:', 'style_strike', 8);
13536 $self->triggerAttributesTab_addRadioButtons($grid, 'Link:', 'style_link', 9);
13537  
13538 # Bottom right
13539 push (@comboList, '');
13540 push (@comboList2, '');
13541 foreach my $tag ($axmud::CLIENT->constColourTagList) {
13542  
13543 push (@comboList, $tag);
13544 push (@comboList2, 'ul_' . $tag);
13545 }
13546  
13547 foreach my $tag ($axmud::CLIENT->constBoldColourTagList) {
13548  
13549 push (@comboList, $tag);
13550 push (@comboList2, 'UL_' . $tag);
13551 }
13552  
13553 $self->triggerAttributesTab_setColours(
13554 $grid,
13555 'Text colour',
13556 'style_text',
13557 \@comboList,
13558 3,
13559 );
13560  
13561 $self->triggerAttributesTab_setColours(
13562 $grid,
13563 'Underlay colour',
13564 'style_underlay',
13565 \@comboList2,
13566 7,
13567 );
13568  
13569 # Tab complete
13570 return 1;
13571 }
13572  
13573 sub triggerAttributesTab_addRadioButtons {
13574  
13575 # Called by $self->triggerAttributes2Tab to add radio buttons for setting an attribute
13576 #
13577 # Expected arguments
13578 # $grid - The Gtk3::Grid
13579 # $labelText - The label text to use (e.g. 'Italics')
13580 # $attrib - The attibute to set (e.g. 'style_italics')
13581 # $row - The Gtk3::Grid row on which the radio buttons are drawn
13582 #
13583 # Return values
13584 # 'undef' on improper arguments
13585 # 1 otherwise
13586  
13587 my ($self, $grid, $labelText, $attrib, $row, $check) = @_;
13588  
13589 # Check for improper arguments
13590 if (
13591 ! defined $grid || ! defined $labelText || ! defined $attrib || ! defined $row
13592 || defined $check
13593 ) {
13594 return $axmud::CLIENT->writeImproper(
13595 $self->_objClass . '->triggerAttributesTab_addRadioButtons',
13596 @_,
13597 );
13598 }
13599  
13600 $self->addLabel($grid, $labelText,
13601 1, 2, $row, ($row + 1));
13602 my ($group, $radioButton) = $self->useRadioButton(
13603 $grid, undef,
13604 'Do not change', # Radio button name
13605 $attrib, # Attribute to set
13606 0, # Attribute set to this value when toggled
13607 TRUE, # Sensitive widget
13608 2, 4, $row, ($row + 1));
13609  
13610 ($group, $radioButton) = $self->useRadioButton(
13611 $grid, $group, 'Yes', $attrib, 1, TRUE,
13612 4, 5, $row, ($row + 1));
13613  
13614 ($group, $radioButton) = $self->useRadioButton(
13615 $grid, $group, 'No', $attrib, 2, TRUE,
13616 5, 6, $row, ($row + 1));
13617  
13618 return 1;
13619 }
13620  
13621 sub triggerAttributesTab_setColours {
13622  
13623 # Called by $self->triggerAttributes2Tab to add radio buttons for setting a colour attribute
13624 #
13625 # Expected arguments
13626 # $grid - The Gtk3::Grid
13627 # $labelText - The label text to use (e.g. 'Text colour')
13628 # $attrib - The attibute to set (e.g. 'style_text')
13629 # $comboListRef - Reference to a list of standard colour tags to display in a combobox
13630 # $row - The Gtk3::Grid row on which the radio buttons are drawn
13631 #
13632 # Return values
13633 # 'undef' on improper arguments
13634 # 1 otherwise
13635  
13636 my ($self, $grid, $labelText, $attrib, $comboListRef, $row, $check) = @_;
13637  
13638 # Check for improper arguments
13639 if (
13640 ! defined $grid || ! defined $labelText || ! defined $attrib || ! defined $row
13641 || defined $check
13642 ) {
13643 return $axmud::CLIENT->writeImproper(
13644 $self->_objClass . '->triggerAttributesTab_setColours',
13645 @_,
13646 );
13647 }
13648  
13649 $self->addLabel($grid, $labelText,
13650 7, 9, $row, ($row + 1));
13651 my $entry = $self->addEntry($grid, undef, FALSE,
13652 9, 12, $row, ($row + 1));
13653 $entry->set_text($self->editObj->ivShow('attribHash', $attrib));
13654  
13655 my $comboBox = $self->addComboBox($grid, undef, $comboListRef, '',
13656 TRUE, # No 'undef' value used
13657 7, 10, ($row + 1), ($row + 2));
13658  
13659 my $button = $self->addButton(
13660 $grid,
13661 'Set',
13662 'Set this standard colour tag as the ' . lc($labelText),
13663 undef,
13664 10, 12, ($row + 1), ($row + 2));
13665 $button->signal_connect('clicked' => sub {
13666  
13667 my $text = $comboBox->get_active_text();
13668  
13669 # If the user has selected the empty line at the top, set the attribute to an empty
13670 # string
13671 if (! $text) {
13672  
13673 $self->ivAdd('attribHash', $attrib, '');
13674  
13675 # Otherwise set the attribute to the specified value
13676 } else {
13677  
13678 $self->ivAdd('attribHash', $attrib, $text);
13679 $comboBox->set_active(0);
13680 }
13681  
13682 $entry->set_text($self->ivShow('attribHash', $attrib));
13683 });
13684  
13685 $self->addLabel($grid, 'xterm tag',
13686 7, 8, ($row + 2), ($row + 3));
13687 my $entry2 = $self->addEntryWithIcon($grid, undef, \&triggerAttributesTab_checkXTerm, 0, 0,
13688 8, 10, ($row + 2), ($row + 3));
13689 $entry2->set_icon_from_stock('secondary', 'gtk-yes'); # (Empty box is valid)
13690 my $button2 = $self->addButton(
13691 $grid,
13692 'Set',
13693 'Set this xterm tag as the ' . lc($labelText),
13694 undef,
13695 10, 12, ($row + 2), ($row + 3));
13696 $button2->signal_connect('clicked' => sub {
13697  
13698 my $text;
13699  
13700 if ($self->checkEntryIcon($entry2)) {
13701  
13702 $text = $entry2->get_text();
13703  
13704 # If the user has emptied the entry box, set the attribute to an empty string
13705 if (! $text) {
13706  
13707 $self->ivAdd('attribHash', $attrib, '');
13708  
13709 # Otherwise set the attribute to the specified value
13710 } else {
13711  
13712 $self->ivAdd('attribHash', $attrib, $text);
13713 }
13714  
13715 $entry->set_text($self->ivShow('attribHash', $attrib));
13716 $entry2->set_text('');
13717 }
13718 });
13719  
13720 $self->addLabel($grid, 'RGB tag',
13721 7, 8, ($row + 3), ($row + 4));
13722 my $entry3 = $self->addEntryWithIcon($grid, undef, \&triggerAttributesTab_checkRGB, 0, 0,
13723 8, 10, ($row + 3), ($row + 4));
13724 $entry3->set_icon_from_stock('secondary', 'gtk-yes'); # (Empty box is valid)
13725 my $button3 = $self->addButton(
13726 $grid,
13727 'Set',
13728 'Set this RGB tag as the ' . lc($labelText),
13729 undef,
13730 10, 12, ($row + 3), ($row + 4));
13731 $button3->signal_connect('clicked' => sub {
13732  
13733 my $text;
13734  
13735 if ($self->checkEntryIcon($entry3)) {
13736  
13737 $text = $entry3->get_text();
13738  
13739 # If the user has emptied the entry box, set the attribute to an empty string
13740 if (! $text) {
13741  
13742 $self->ivAdd('attribHash', $attrib, '');
13743  
13744 # Otherwise set the attribute to the specified value
13745 } else {
13746  
13747 $self->ivAdd('attribHash', $attrib, $text);
13748 }
13749  
13750 $entry->set_text($self->ivShow('attribHash', $attrib));
13751 $entry3->set_text('');
13752 }
13753 });
13754  
13755 return 1;
13756 }
13757  
13758 sub triggerAttributesTab_checkXTerm {
13759  
13760 # Called by $self->triggerAttributes2Tab to check the text in the Gtk3::Entry
13761 #
13762 # Expected arguments
13763 # $text - The contents of the Gtk3::Entry
13764 #
13765 # Return values
13766 # 'undef' on improper arguments or if $text is invalid
13767 # 1 if $text is valid
13768  
13769 my ($self, $text, $check) = @_;
13770  
13771 # Check for improper arguments
13772 if (! defined $text || defined $check) {
13773  
13774 return $axmud::CLIENT->writeImproper(
13775 $self->_objClass . '->triggerAttributesTab_checkXTerm',
13776 @_,
13777 );
13778 }
13779  
13780 # $text can be an xterm colour tag (in the range 'x0' to 'x255', or 'ux0' to 'ux255'; xterm
13781 # tags are case-insensitive
13782 # An empty entry box is also a valid value
13783 if (! $text) {
13784  
13785 return 1;
13786  
13787 } elsif ($text =~ m/^u?x([0-9]+)$/i) {
13788  
13789 # (Don't permit 'x000005', but do permit 'x005' or 'x5')
13790 if ($1 >= 0 && $1 <= 255 && length ($1) <= 3) {
13791 return 1;
13792 } else {
13793 return undef;
13794 }
13795  
13796 } else {
13797  
13798 return undef;
13799 }
13800 }
13801  
13802 sub triggerAttributesTab_checkRGB {
13803  
13804 # Called by $self->triggerAttributes2Tab to check the text in the Gtk3::Entry
13805 #
13806 # Expected arguments
13807 # $text - The contents of the Gtk3::Entry
13808 #
13809 # Return values
13810 # 'undef' on improper arguments or if $text is invalid
13811 # 1 if $text is valid
13812  
13813 my ($self, $text, $check) = @_;
13814  
13815 # Check for improper arguments
13816 if (! defined $text || defined $check) {
13817  
13818 return $axmud::CLIENT->writeImproper(
13819 $self->_objClass . '->triggerAttributesTab_checkRGB',
13820 @_,
13821 );
13822 }
13823  
13824 # $text can be an RGB colour tag (in the form '#xxxxxx' or '#uxxxxxx' where x is any
13825 # character in the range A-F, a-f, 0-9; RGB tags are case-insensitive
13826 # An empty entry box is also a valid value
13827 if (! $text) {
13828  
13829 return 1;
13830  
13831 } elsif ($text =~ m/^u?\#[A-F0-9]{6}$/i) {
13832  
13833 return 1;
13834  
13835 } else {
13836  
13837 return undef;
13838 }
13839 }
13840  
13841 sub aliasAttributesTab {
13842  
13843 # AliasAttributes tab
13844 #
13845 # Expected arguments
13846 # (none besides $self)
13847 #
13848 # Return values
13849 # 'undef' on improper arguments
13850 # 1 otherwise
13851  
13852 my ($self, $check) = @_;
13853  
13854 # Check for improper arguments
13855 if (defined $check) {
13856  
13857 return $axmud::CLIENT->writeImproper($self->_objClass . '->aliasAttributesTab', @_);
13858 }
13859  
13860 # Tab setup
13861 my $grid = $self->addTab(
13862 $self->notebook,
13863 '_Attributes',
13864 ['Alias attributes'],
13865 );
13866  
13867 # Alias attributes
13868 $self->addLabel($grid, '<b>Alias attributes</b>',
13869 0, 12, 0, 1);
13870  
13871 # Left column
13872 $self->useCheckButton($grid, 'Ignore case', 'ignore_case', TRUE,
13873 1, 6, 1, 2);
13874 $self->useCheckButton($grid, 'Keep checking aliases after a match', 'keep_checking', TRUE,
13875 1, 6, 2, 3);
13876  
13877 # Right column
13878 $self->useCheckButton($grid, 'Temporary alias', 'temporary', TRUE,
13879 7, 12, 1, 2);
13880 $self->addLabel($grid, 'Cooldown (in seconds)',
13881 7, 9, 2, 3);
13882 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
13883 9, 12, 2, 3,
13884 8, 8);
13885  
13886 # Tab complete
13887 return 1;
13888 }
13889  
13890 sub macroAttributesTab {
13891  
13892 # MacroAttributes tab
13893 #
13894 # Expected arguments
13895 # (none besides $self)
13896 #
13897 # Return values
13898 # 'undef' on improper arguments
13899 # 1 otherwise
13900  
13901 my ($self, $check) = @_;
13902  
13903 # Check for improper arguments
13904 if (defined $check) {
13905  
13906 return $axmud::CLIENT->writeImproper($self->_objClass . '->macroAttributesTab', @_);
13907 }
13908  
13909 # Tab setup
13910 my $grid = $self->addTab(
13911 $self->notebook,
13912 '_Attributes',
13913 ['Macro attributes'],
13914 );
13915  
13916 # Macro attributes
13917 $self->addLabel($grid, '<b>Macro attributes</b>',
13918 0, 12, 0, 1);
13919  
13920 # Left column
13921 $self->useCheckButton($grid, 'Temporary macro', 'temporary', TRUE,
13922 1, 6, 1, 2);
13923  
13924 # Right column
13925 $self->addLabel($grid, 'Cooldown (in seconds)',
13926 7, 9, 1, 2);
13927 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
13928 9, 12, 1, 2,
13929 8, 8);
13930  
13931 # Tab complete
13932 return 1;
13933 }
13934  
13935 sub timerAttributesTab {
13936  
13937 # TimerAttributes tab
13938 #
13939 # Expected arguments
13940 # (none besides $self)
13941 #
13942 # Return values
13943 # 'undef' on improper arguments
13944 # 1 otherwise
13945  
13946 my ($self, $check) = @_;
13947  
13948 # Check for improper arguments
13949 if (defined $check) {
13950  
13951 return $axmud::CLIENT->writeImproper($self->_objClass . '->timerAttributesTab', @_);
13952 }
13953  
13954 # Tab setup
13955 my $grid = $self->addTab(
13956 $self->notebook,
13957 '_Timers',
13958 ['Timer attributes'],
13959 );
13960  
13961 # Timer attributes
13962 $self->addLabel($grid, '<b>Timer attributes</b>',
13963 0, 12, 0, 1);
13964  
13965 # Left column
13966 $self->addLabel($grid, 'Repeat count (-1 unlimited)',
13967 1, 4, 1, 2);
13968 $self->useEntryWithIcon($grid, 'count', 'int', -1, undef,
13969 4, 6, 1, 2);
13970 $self->addLabel($grid, 'Initial delay (0 for no delay)',
13971 1, 4, 2, 3);
13972 $self->useEntryWithIcon($grid, 'initial_delay', 'float', 0, undef,
13973 4, 6, 2, 3);
13974 $self->useCheckButton($grid, 'Random delays', 'random_delay', TRUE,
13975 1, 6, 3, 4);
13976  
13977 # Right column
13978 $self->addLabel($grid, 'Minimum random delay',
13979 7, 10, 1, 2);
13980 $self->useEntryWithIcon($grid, 'random_min', 'float', 0, undef,
13981 10, 12, 1, 2);
13982 $self->useCheckButton($grid, 'Start after login', 'wait_login', TRUE,
13983 7, 12, 2, 3);
13984 $self->useCheckButton($grid, 'Temporary timer', 'temporary', TRUE,
13985 7, 12, 3, 4);
13986  
13987 # Tab complete
13988 return 1;
13989 }
13990  
13991 sub hookAttributesTab {
13992  
13993 # HookAttributes tab
13994 #
13995 # Expected arguments
13996 # (none besides $self)
13997 #
13998 # Return values
13999 # 'undef' on improper arguments
14000 # 1 otherwise
14001  
14002 my ($self, $check) = @_;
14003  
14004 # Check for improper arguments
14005 if (defined $check) {
14006  
14007 return $axmud::CLIENT->writeImproper($self->_objClass . '->hookAttributesTab', @_);
14008 }
14009  
14010 # Tab setup
14011 my $grid = $self->addTab(
14012 $self->notebook,
14013 '_Attributes',
14014 ['Hook attributes'],
14015 );
14016  
14017 # Hook attributes
14018 $self->addLabel($grid, '<b>Hook attributes</b>',
14019 0, 12, 0, 1);
14020  
14021 # Left column
14022 $self->useCheckButton($grid, 'Temporary hook', 'temporary', TRUE,
14023 1, 6, 1, 2);
14024  
14025 # Right column
14026 $self->addLabel($grid, 'Cooldown (in seconds)',
14027 7, 9, 1, 2);
14028 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
14029 9, 12, 1, 2,
14030 8, 8);
14031  
14032 # Tab complete
14033 return 1;
14034 }
14035  
14036 # 'dialogue' windows for simple scalars, lists and hashes
14037  
14038 sub promptScalar {
14039  
14040 # Creates a 'dialogue' window to prompt the user to view, enter (or edit) a scalar value
14041 # If the user supplies a value, sets the IV then closes the window
14042 #
14043 # Operates in two modes
14044 # Mode 1 - the supplied IV is a scalar, i.e.
14045 # $self->editObj->$iv = 'some_scalar_value'
14046 # $self->editHash->$iv = 'some_scalar_value'
14047 # - the value supplied by the user is saved in place of 'some_scalar_value'
14048 #
14049 # Mode 2 - the supplied IV is a hash, i.e.
14050 # $self->editObj->$iv = {some_hash}
14051 # $self->editHash->$iv = {some_hash}
14052 # - the calling function also supplies a key in {some_hash}
14053 # - the value supplied by the user is saved as the key's corresponding value
14054 #
14055 # Expected arguments
14056 # $iv - The IV to set in $self->editHash
14057 #
14058 # Optional arguments
14059 # $key - In mode 1, 'undef'; in mode 2, a key in {some_hash}
14060 # $deRefFlag
14061 # - In mode 1, 'undef'; in mode 2, TRUE if the key's corresponding value in
14062 # {some_hash} is stored as a scalar reference (only cage masks do this); FALSE
14063 # (or 'undef') if it's stored as a simple scalar
14064 # $slWidget
14065 # - In mode 1, 'undef'; in mode 2, 'undef' or the GA::Obj::SimpleList in which the
14066 # IV's data is being displayed (if specified, the simple list is updated when
14067 # this window is closed)
14068 # $readOnlyFlag
14069 # - If set to TRUE, the scalar is read-only (so can't be edited); otherwise set
14070 # to FALSE (or 'undef')
14071 # $callFunc
14072 # - If specified, $self->$funcName is called when the IV is updated instead of the
14073 # usual call to $self->updateListDataWithKey (useful if we don't want the
14074 # simple list sorted alphabetically, as normally happens); otherwise set to
14075 # 'undef'
14076 # @callFuncArgs
14077 # - Optional list of args to be passed if $callFunc is called; otherwise an empty
14078 # list
14079 #
14080 # Return values
14081 # 'undef' on improper arguments
14082 # 1 otherwise
14083  
14084 my ($self, $iv, $key, $deRefFlag, $slWidget, $readOnlyFlag, $callFunc, @callFuncArgs) = @_;
14085  
14086 # Local variables
14087 my (
14088 $title, $labelText, $outerHashRef, $value, $response,
14089 %outerHash,
14090 );
14091  
14092 # Check for improper arguments
14093 if (! defined $iv) {
14094  
14095 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptScalar', @_);
14096 }
14097  
14098 # Set the window title
14099 if ($readOnlyFlag) {
14100 $title = 'View Scalar';
14101 } else {
14102 $title = 'Edit Scalar';
14103 }
14104  
14105 # Show the 'dialogue' window
14106 my $dialogueWin;
14107 if (! $readOnlyFlag) {
14108  
14109 $dialogueWin = Gtk3::Dialog->new(
14110 $title,
14111 $self->winWidget,
14112 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
14113 'gtk-cancel' => 'reject',
14114 'gtk-ok' => 'accept',
14115 );
14116  
14117 } else {
14118  
14119 $dialogueWin = Gtk3::Dialog->new(
14120 $title,
14121 $self->winWidget,
14122 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
14123 'gtk-ok' => 'accept',
14124 );
14125 }
14126  
14127 $dialogueWin->set_position('center-always');
14128 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
14129  
14130 $dialogueWin->signal_connect('delete-event' => sub {
14131  
14132 $dialogueWin->destroy();
14133 $self->restoreFocus();
14134  
14135 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
14136 # the window is visibly closed)
14137 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptScalar');
14138 });
14139  
14140 # Add widgets to the 'dialogue' window
14141 my $vBox = $dialogueWin->get_content_area();
14142 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
14143 # Gtk3::VBox on the right, into which we put everything
14144 my $vBox2 = $self->addDialogueIcon($vBox);
14145  
14146 # Create a label, which will shortly show which IV is being edited (a second label,
14147 # $undefLabel, is sometimes used immediately below it)
14148 my $label = Gtk3::Label->new();
14149 $label->set_alignment(0, 0.5);
14150  
14151 # Create an entry, in which the user supplies a new value
14152 my $entry = Gtk3::Entry->new;
14153 if ($readOnlyFlag) {
14154  
14155 $entry->set_state('insensitive');
14156 }
14157  
14158 # Set the contents of the entry box, and prepare the label text
14159 if (! defined $key) {
14160  
14161 # Mode 1 - edit the value of $self->editObj->$iv or $self->editHash->$iv
14162 $labelText = 'Value of IV \'' . $iv . '\'';
14163  
14164 # If the IV hasn't yet been edited, use the original value
14165 if (! $self->ivExists('editHash', $iv)) {
14166  
14167 if (defined $self->editObj->{$iv}) {
14168  
14169 # Put the current value in the entry box
14170 $entry->set_text($self->editObj->{$iv});
14171  
14172 } else {
14173  
14174 # Add more text to the label, to show that the value is 'undef'
14175 $labelText .= ' <i>(currently \'undef\')</i>';
14176 }
14177  
14178 # If the IV has been edited, use the edited value
14179 } else {
14180  
14181 # Use an edited value
14182 if (defined $self->ivShow('editHash', $iv)) {
14183  
14184 $entry->set_text($self->ivShow('editHash', $iv));
14185  
14186 } else {
14187  
14188 # Add more text to the label, to show that the value is 'undef'
14189 $labelText .= ' <i>(currently \'undef\')</i>';
14190 }
14191 }
14192  
14193 } else {
14194  
14195 # Mode 2 - edit the scalar stored in a key-value pair; the pair is in the hash
14196 # stored as $self->editObj->$iv or $self->editHash->$iv
14197 $labelText = 'Value of key \'' . $key . '\' stored in IV \'' . $iv . '\'';
14198  
14199 # Get a copy of the hash being edited
14200 if (! $self->ivExists('editHash', $iv)) {
14201  
14202 %outerHash = $self->editObj->$iv;
14203  
14204 # If the IV has been edited, use the edited hash
14205 } else {
14206  
14207 $outerHashRef = $self->ivShow('editHash', $iv);
14208 %outerHash = %$outerHashRef;
14209 }
14210  
14211 if (exists $outerHash{$key}) {
14212  
14213 if (defined $outerHash{$key}) {
14214  
14215 # Put the current value of the key-value pair in the entry box
14216 $value = $outerHash{$key};
14217 if ($deRefFlag) {
14218  
14219 # Cage masks: $value is a scalar reference
14220 $entry->set_text($$value);
14221  
14222 } else {
14223  
14224 # Everything else: $value is a normal scalar
14225 $entry->set_text($value);
14226 }
14227  
14228 } else {
14229  
14230 # Add more text to the label, to show that the value is 'undef'
14231 $labelText .= ' <i>(currently \'undef\')</i>';
14232 }
14233 }
14234 }
14235  
14236 # Set the label text
14237 $label->set_markup($labelText);
14238  
14239 # Pack the label and entry box
14240 $vBox2->pack_start($label, TRUE, TRUE, $self->spacingPixels);
14241 $vBox2->pack_start($entry, TRUE, TRUE, $self->spacingPixels);
14242  
14243 # Optionally add a button strip in the lower area, containing a single button
14244 if (! $readOnlyFlag) {
14245  
14246 my $hBox = Gtk3::HBox->new(FALSE, 0);
14247 $vBox2->pack_start($hBox, TRUE, TRUE, $self->spacingPixels);
14248  
14249 # Create the 'use undef' button
14250 my $button3 = Gtk3::Button->new('Use \'undef\' value');
14251 $hBox->pack_end($button3, FALSE, FALSE, $self->spacingPixels);
14252  
14253 $button3->signal_connect('clicked' => sub {
14254  
14255 # Store an 'undef' scalar value
14256  
14257 # Mode 1 - edit the scalar stored in $self->editObj->$iv or $self->editHash->$iv
14258 if (! defined $key) {
14259  
14260 $self->ivAdd('editHash', $iv, undef);
14261  
14262 # Update the simple list displayed in the parent window, if a list was specified
14263 if ($slWidget) {
14264  
14265 $self->updateListDataWithKey($slWidget, $iv, undef);
14266 }
14267  
14268 # Mode 2 - edit the scalar stored in a key-value pair; the pair is in the hash
14269 # stored as $self->editObj->$iv or $self->editHash->$iv
14270 } else {
14271  
14272 # Update the hash stored in the IV with a new key-value pair. The key is $key,
14273 # the corresponding value is the new scalar
14274 $outerHash{$key} = undef;
14275  
14276 # Store the modified outer hash as the IV
14277 $self->ivAdd('editHash', $iv, \%outerHash);
14278  
14279 # Update the simple list displayed in the parent window, if a list was specified
14280 if ($slWidget) {
14281  
14282 $self->updateListDataWithKey($slWidget, $key, undef);
14283 }
14284 }
14285  
14286 # Call a function to re-display the simple list in the parent window, if a function
14287 # was specified
14288 if ($callFunc) {
14289  
14290 $self->$callFunc(@callFuncArgs);
14291 }
14292  
14293 # Close the window and return success value
14294 $dialogueWin->destroy();
14295 $self->restoreFocus();
14296  
14297 # (In case TTS is being used and another 'dialogue' window is about to open, make
14298 # sure the window is visibly closed)
14299 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptScalar');
14300  
14301 return 1;
14302 });
14303 }
14304  
14305 # Widget drawing complete
14306 $vBox->show_all();
14307  
14308 # Get the response
14309 $response = $dialogueWin->run();
14310 if ($response eq 'accept') {
14311  
14312 my $scalar;
14313  
14314 # Don't save anything for read-only values
14315 if (! $readOnlyFlag) {
14316  
14317 $scalar = $entry->get_text();
14318  
14319 # Mode 1 - edit the value stored in of $self->editObj->$iv or $self->editHash->$iv
14320 if (! defined $key) {
14321  
14322 # Store the edited scalar
14323 $self->ivAdd('editHash', $iv, $scalar);
14324  
14325 # Update the simple list displayed in the parent window, if a list was specified
14326 if ($slWidget) {
14327  
14328 $self->updateListDataWithKey($slWidget, $iv, $scalar);
14329 }
14330  
14331 # Mode 2 - edit the scalar stored in a key-value pair; the pair is in the hash
14332 # stored as $self->editObj->$iv or $self->editHash->$iv
14333 } else {
14334  
14335 # Update the hash stored in the IV with a new key-value pair. The key is $key,
14336 # the corresponding value is the new scalar
14337 if ($deRefFlag) {
14338  
14339 # Cage masks: $value is a scalar reference
14340 $value = \$scalar;
14341  
14342 } else {
14343  
14344 # Everything else: $value is a normal scalar
14345 $value = $scalar;
14346 }
14347  
14348 $outerHash{$key} = $value;
14349  
14350 # Store the modified outer hash as the IV
14351 $self->ivAdd('editHash', $iv, \%outerHash);
14352  
14353 # Update the simple list displayed in the parent window, if a list was specified
14354 if ($slWidget) {
14355  
14356 $self->updateListDataWithKey($slWidget, $key, $value);
14357 }
14358 }
14359  
14360 # Call a function to re-display the simple list in the parent window, if a function
14361 # was specified
14362 if ($callFunc) {
14363  
14364 $self->$callFunc(@callFuncArgs);
14365 }
14366 }
14367 }
14368  
14369 # Destroy the window
14370 $dialogueWin->destroy();
14371 $self->restoreFocus();
14372  
14373 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
14374 # window is visibly closed)
14375 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptScalar');
14376  
14377 # Operation complete
14378 return 1;
14379 }
14380  
14381 sub promptList {
14382  
14383 # Creates a 'dialogue' window to prompt the user to view, enter (or edit) a list of values
14384 # If the user supplies any values, sets the IV then closes the window
14385 #
14386 # Operates in two modes
14387 # Mode 1 - the supplied IV is a list, i.e.
14388 # $self->editObj->$iv = [some_list]
14389 # $self->editHash->$iv = [some_list]
14390 # - the values supplied by the user are saved in place of [some_list]
14391 #
14392 # Mode 2 - the supplied IV is a hash, i.e.
14393 # $self->editObj->$iv = {some_hash}
14394 # $self->editHash->$iv = {some_hash}
14395 # - the calling function also supplies a key in {some_hash}
14396 # - a reference to the list supplied by the user is saved as the key's
14397 # corresponding value
14398 #
14399 # Expected arguments
14400 # $iv - The IV to set in $self->editHash
14401 #
14402 # Optional arguments
14403 # $key - In mode 1, 'undef'; in mode 2, a key in {some_hash}
14404 # $slWidget
14405 # - In mode 1, 'undef'; in mode 2, 'undef' or the GA::Obj::SimpleList in which the
14406 # IV's data is being displayed (if specified, the simple list is updated when
14407 # this window is closed)
14408 # $readOnlyFlag
14409 # - If set to TRUE, the list is read-only (so can't be edited); otherwise set
14410 # to FALSE (or 'undef')
14411 # $callFunc
14412 # - If specified, $self->$funcName is called when the IV is updated instead of the
14413 # usual call to $self->updateListDataWithKey (useful if we don't want the
14414 # simple list sorted alphabetically, as normally happens); otherwise set to
14415 # 'undef'
14416 # @callFuncArgs
14417 # - Optional list of args to be passed if $callFunc is called; otherwise an empty
14418 # list
14419 #
14420 # Return values
14421 # 'undef' on improper arguments
14422 # 1 otherwise
14423  
14424 my ($self, $iv, $key, $slWidget, $readOnlyFlag, $callFunc, @callFuncArgs) = @_;
14425  
14426 # Local variables
14427 my (
14428 $title, $replaceListRef, $outerHashRef, $response,
14429 %outerHash,
14430 );
14431  
14432 # Check for improper arguments
14433 if (! defined $iv) {
14434  
14435 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptList', @_);
14436 }
14437  
14438 # Set the window title
14439 if ($readOnlyFlag) {
14440 $title = 'View List';
14441 } else {
14442 $title = 'Edit List';
14443 }
14444  
14445 # Show the 'dialogue' window
14446 my $dialogueWin;
14447 if (! $readOnlyFlag) {
14448  
14449 $dialogueWin = Gtk3::Dialog->new(
14450 $title,
14451 $self->winWidget,
14452 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
14453 'gtk-cancel' => 'reject',
14454 'gtk-ok' => 'accept',
14455 );
14456  
14457 } else {
14458  
14459 $dialogueWin = Gtk3::Dialog->new(
14460 $title,
14461 $self->winWidget,
14462 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
14463 'gtk-ok' => 'accept',
14464 );
14465 }
14466  
14467 $dialogueWin->set_position('center-always');
14468 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
14469  
14470 $dialogueWin->signal_connect('delete-event' => sub {
14471  
14472 $dialogueWin->destroy();
14473 $self->restoreFocus();
14474  
14475 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
14476 # the window is visibly closed)
14477 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptList');
14478 });
14479  
14480 # Add widgets to the 'dialogue' window
14481 my $vBox = $dialogueWin->get_content_area();
14482 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
14483 # Gtk3::VBox on the right, into which we put everything
14484 my $vBox2 = $self->addDialogueIcon($vBox);
14485  
14486 # Create a label, which will shortly show which IV is being edited
14487 my $label = Gtk3::Label->new();
14488 $vBox2->pack_start($label, TRUE, TRUE, $self->spacingPixels);
14489 $label->set_alignment(0, 0.5);
14490  
14491 # Create a textview, in which the user supplies a list of values
14492 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
14493 $vBox2->pack_start($scroll, TRUE, TRUE, $self->spacingPixels);
14494 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
14495 $scroll->set_policy('automatic', 'automatic');
14496 $scroll->set_size_request(200, 150); # Minimum size
14497 $scroll->set_border_width($self->spacingPixels);
14498  
14499 # Create a textview with default colours/fonts
14500 my $textView = Gtk3::TextView->new();
14501 $scroll->add($textView);
14502  
14503 my $buffer = Gtk3::TextBuffer->new();
14504 $textView->set_buffer($buffer);
14505  
14506 if ($readOnlyFlag) {
14507 $textView->set_editable(FALSE);
14508 } else {
14509 $textView->set_editable(TRUE);
14510 }
14511  
14512 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);
14513  
14514 # Set the contents of the label and the textview
14515 if (! defined $key) {
14516  
14517 # Mode 1 - edit the list stored in $self->editObj->$iv or $self->editHash->$iv
14518 $label->set_markup('List stored in IV \'' . $iv . '\'');
14519  
14520 # If the IV hasn't yet been edited, use the original stored list
14521 if (! $self->ivExists('editHash', $iv)) {
14522  
14523 $replaceListRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
14524 $buffer->set_text(join("\n", @$replaceListRef));
14525  
14526 # If the IV has been edited, use the edited list
14527 } else {
14528  
14529 $replaceListRef = $self->ivShow('editHash', $iv);
14530 $buffer->set_text(join("\n", @$replaceListRef));
14531 }
14532  
14533 } else {
14534  
14535 # Mode 2 - edit the list stored in a key-value pair; the pair is in the hash
14536 # stored as $self->editObj->$iv or $self->editHash->$iv
14537 $label->set_markup('List stored in key \'' . $key . '\' in IV \'' . $iv . '\'');
14538  
14539 # Get a copy of the hash being edited
14540 if (! $self->ivExists('editHash', $iv)) {
14541  
14542 $outerHashRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
14543 %outerHash = %$outerHashRef;
14544  
14545 } else {
14546  
14547 $outerHashRef = $self->ivShow('editHash', $iv);
14548 %outerHash = %$outerHashRef;
14549 }
14550  
14551 # Put the current contents of the list in the textview
14552 if (exists $outerHash{$key} && defined $outerHash{$key}) {
14553  
14554 $replaceListRef = $outerHash{$key};
14555 $buffer->set_text(join("\n", @$replaceListRef));
14556 }
14557 }
14558  
14559 # Widget drawing complete
14560 $vBox->show_all();
14561  
14562 # Get the response
14563 $response = $dialogueWin->run();
14564 if ($response eq 'accept') {
14565  
14566 my (
14567 $text,
14568 @dataList,
14569 );
14570  
14571 # Don't save anything for read-only values
14572 if (! $readOnlyFlag) {
14573  
14574 $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer);
14575  
14576 # Split the contents of the textview into a list of lines, separated by
14577 # newline characters
14578 @dataList = split("\n", $text);
14579  
14580 # Mode 1 - edit the list stored in of $self->editObj->$iv or $self->editHash->$iv
14581 if (! defined $key) {
14582  
14583 # Store the list we've been editing
14584 $self->ivAdd('editHash', $iv, \@dataList);
14585  
14586 # Update the simple list displayed in the parent window, if a list was specified
14587 if ($slWidget) {
14588  
14589 $self->updateListDataWithKey($slWidget, $iv, \@dataList);
14590 }
14591  
14592 # Mode 2 - edit the list stored in a key-value pair; the pair is in the hash
14593 # stored as $self->editObj->$iv or $self->editHash->$iv
14594 } else {
14595  
14596 # Update the hash stored in the IV with a new key-value pair. The key is
14597 # $key, the corresponding value is a reference to the list we've
14598 # been editing, @dataList
14599 $outerHash{$key} = \@dataList;
14600  
14601 # Store the modified outer hash as the IV
14602 $self->ivAdd('editHash', $iv, \%outerHash);
14603  
14604 # Update the simple list displayed in the parent window, if a list was specified
14605 if ($slWidget) {
14606  
14607 $self->updateListDataWithKey($slWidget, $key, \@dataList);
14608 }
14609 }
14610  
14611 # Call a function to re-display the simple list in the parent window, if a function
14612 # was specified
14613 if ($callFunc) {
14614  
14615 $self->$callFunc(@callFuncArgs);
14616 }
14617 }
14618 }
14619  
14620 # Destroy the window
14621 $dialogueWin->destroy();
14622 $self->restoreFocus();
14623  
14624 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
14625 # window is visibly closed)
14626 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptList');
14627  
14628 # Operation complete
14629 return 1;
14630 }
14631  
14632 sub promptHash {
14633  
14634 # Creates a 'dialogue' window to prompt the user to view, enter (or edit) a hash of
14635 # key-value pairs
14636 # If the user supplies any pairs, sets the IV then closes the window
14637 #
14638 # Operates in two modes
14639 # Mode 1 - the supplied IV is a hash, i.e.
14640 # $self->editObj->$iv = {some_hash}
14641 # $self->editHash->$iv = {some_hash}
14642 # - the key-value pairs supplied by the user are saved in place of {some_hash}
14643 #
14644 # Mode 2 - the supplied IV is a hash, i.e.
14645 # $self->editObj->$iv = {some_hash}
14646 # $self->editHash->$iv = {some_hash}
14647 # - the calling function also supplies a key in {some_hash}
14648 # - a reference to the hash supplied by the user is saved as the key's
14649 # corresponding value
14650 #
14651 # Expected arguments
14652 # $iv - The IV to set in $self->editObj
14653 #
14654 # Optional arguments
14655 # $key - In mode 1, 'undef'; in mode 2, a key in {some_hash}
14656 # $slWidget
14657 # - In mode 1, 'undef'; in mode 2, 'undef' or the GA::Obj::SimpleListin which the
14658 # IV's data is being displayed (if specified, the simple list is updated when
14659 # this window is closed)
14660 # $readOnlyFlag
14661 # - If set to TRUE, the scalar is read-only (so can't be edited); otherwise set to
14662 # FALSE (or 'undef')
14663 # $callFunc
14664 # - If specified, $self->$funcName is called when the IV is updated instead of the
14665 # usual call to $self->updateListDataWithKey (useful if we don't want the
14666 # simple list sorted alphabetically, as normally happens); otherwise set to
14667 # 'undef'
14668 # @callFuncArgs
14669 # - Optional list of args to be passed if $callFunc is called; otherwise an empty
14670 # list
14671 #
14672 # Return values
14673 # 'undef' on improper arguments
14674 # 1 otherwise
14675  
14676 my ($self, $iv, $key, $slWidget, $readOnlyFlag, $callFunc, @callFuncArgs) = @_;
14677  
14678 # Local variables
14679 my (
14680 $title, $response, $outerHashRef,
14681 %outerHash, %replaceHash, %innerHash,
14682 );
14683  
14684 # Check for improper arguments
14685 if (! defined $iv) {
14686  
14687 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptHash', @_);
14688 }
14689  
14690 # Set the window title
14691 if ($readOnlyFlag) {
14692 $title = 'View Hash';
14693 } else {
14694 $title = 'Edit Hash';
14695 }
14696  
14697 # Show the 'dialogue' window
14698 my $dialogueWin;
14699 if (! $readOnlyFlag) {
14700  
14701 $dialogueWin = Gtk3::Dialog->new(
14702 $title,
14703 $self->winWidget,
14704 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
14705 'gtk-cancel' => 'reject',
14706 'gtk-ok' => 'accept',
14707 );
14708  
14709 } else {
14710  
14711 $dialogueWin = Gtk3::Dialog->new(
14712 $title,
14713 $self->winWidget,
14714 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
14715 'gtk-ok' => 'accept',
14716 );
14717 }
14718  
14719 $dialogueWin->set_position('center-always');
14720 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
14721  
14722 $dialogueWin->signal_connect('delete-event' => sub {
14723  
14724 $dialogueWin->destroy();
14725 $self->restoreFocus();
14726  
14727 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
14728 # the window is visibly closed)
14729 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptHash');
14730 });
14731  
14732 # Add widgets to the 'dialogue' window
14733 my $vBox = $dialogueWin->get_content_area();
14734 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
14735 # Gtk3::VBox on the right, into which we put everything
14736 my $vBox2 = $self->addDialogueIcon($vBox);
14737  
14738 # Create a label, which will shortly show which IV is being edited
14739 my $label = Gtk3::Label->new();
14740 $vBox2->pack_start($label, TRUE, TRUE, $self->spacingPixels);
14741 $label->set_alignment(0, 0.5);
14742  
14743 # Create a scroller
14744 my $scroller = Gtk3::ScrolledWindow->new;
14745 $vBox2->pack_start($scroller, TRUE, TRUE, $self->spacingPixels);
14746 $scroller->set_policy('automatic', 'automatic');
14747 $scroller->set_size_request(200, 150); # Minimum size
14748  
14749 # Create a simple list with two columns representing a hash, for which the user
14750 # supplies key-value pairs
14751 my $slWidget2 = Games::Axmud::Obj::SimpleList->new(
14752 # Give the first column a minimum width; don't want the columns moving around too
14753 # much when the user enter new key-value pairs
14754 'Key ' => 'text',
14755 'Value' => 'text',
14756 );
14757 $scroller->add($slWidget2);
14758  
14759 # Set the contents of the label and the simple list. We don't want to overwrite the hash
14760 # until the user clicks the 'ok' button, so we'll edit a copy of the hash
14761 if (! defined $key) {
14762  
14763 # Mode 1 - edit the hash stored in $self->editObj->$iv or $self->editHash->$iv
14764 $label->set_markup('Hash stored in IV \'' . $iv . '\'');
14765 %outerHash = $self->promptHash_displayDataMode1($slWidget2, $iv);
14766 # Edit a copy, so that we can revert to the original copy if we want to
14767 %replaceHash = %outerHash;
14768  
14769 } else {
14770  
14771 # Mode 2 - edit the hash stored in a key-value pair; the pair is in the hash
14772 # stored as $self->editObj->$iv or $self->editHash->$iv
14773 $label->set_markup('Hash stored in key \'' . $key . "\'\nin IV \'" . $iv . "\'");
14774 %innerHash = $self->promptHash_displayDataMode2($slWidget2, $iv, $key);
14775 # Edit a copy, so that we can revert to the original copy if we want to
14776 %replaceHash = %innerHash;
14777 }
14778  
14779 # If the hash is editable, we have a lot more widgets to add
14780 if (! $readOnlyFlag) {
14781  
14782 # Add a grid containing entry boxes for new key-value pairs. The grid ensures that
14783 # the two entry boxes are aligned with each other
14784 my $grid = Gtk3::Grid->new();
14785 $vBox2->pack_start($grid, TRUE, TRUE, $self->spacingPixels);
14786  
14787 my $label2 = Gtk3::Label->new();
14788 $label2->set_alignment(0, 0.5);
14789 $label2->set_markup('Key');
14790 $label2->set_hexpand(TRUE);
14791 $grid->attach($label2, 0, 0, 1, 1);
14792  
14793 my $entry = Gtk3::Entry->new();
14794 $entry->set_hexpand(TRUE);
14795 $grid->attach($entry, 1, 0, 1, 1);
14796  
14797 my $label3 = Gtk3::Label->new();
14798 $label3->set_alignment(0, 0.5);
14799 $label3->set_markup('Value');
14800 $label3->set_hexpand(TRUE);
14801 $grid->attach($label3, 0, 1, 1, 1);
14802  
14803 my $entry2 = Gtk3::Entry->new();
14804 $entry2->set_hexpand(TRUE);
14805 $grid->attach($entry2, 1, 1, 1, 1);
14806  
14807 # Add a button strip containing editing buttons
14808 my $hBox = Gtk3::HBox->new(FALSE, 0);
14809 $vBox2->pack_start($hBox, TRUE, TRUE, $self->spacingPixels);
14810  
14811 # 'Add' button
14812 my $button = Gtk3::Button->new('Add');
14813 $hBox->pack_start($button, FALSE, FALSE, $self->spacingPixels);
14814 $button->set_tooltip_text('Add a key-value pair');
14815 $button->signal_connect('clicked' => sub {
14816  
14817 my ($thisKey, $thisValue);
14818  
14819 $thisKey = $entry->get_text();
14820 $thisValue = $entry2->get_text();
14821  
14822 # Update the hash we're editing...
14823 $replaceHash{$thisKey} = $thisValue;
14824 # ...and update the displayed simple list
14825 $self->updateListDataWithKey($slWidget2, $thisKey, $thisValue);
14826  
14827 # Empty the entry boxes
14828 $self->resetEntryBoxes($entry, $entry2);
14829 });
14830  
14831 # 'Undef' button
14832 my $button2 = Gtk3::Button->new('Add with \'undef\' value');
14833 $hBox->pack_start($button2, FALSE, FALSE, $self->spacingPixels);
14834 $button2->set_tooltip_text('Add a key-value pair, with the value set to \'undef\'');
14835 $button2->signal_connect('clicked' => sub {
14836  
14837 my $thisKey = $entry->get_text();
14838  
14839 # Update the hash we're editing...
14840 $replaceHash{$thisKey} = undef;
14841 # ...and update the displayed simple list
14842 $self->updateListDataWithKey($slWidget2, $thisKey, undef);
14843  
14844 # Empty the entry boxes
14845 $self->resetEntryBoxes($entry, $entry2);
14846 });
14847  
14848 # Add a second button strip containing editing buttons
14849 my $hBox2 = Gtk3::HBox->new(FALSE, 0);
14850 $vBox2->pack_start($hBox2, TRUE, TRUE, $self->spacingPixels);
14851  
14852 # 'Delete' button
14853 my $button3 = Gtk3::Button->new('Delete');
14854 $hBox2->pack_start($button3, FALSE, FALSE, $self->spacingPixels);
14855 $button3->set_tooltip_text('Delete the selected key-value pair');
14856 $button3->signal_connect('clicked' => sub {
14857  
14858 my (
14859 $thisKey,
14860 @selectList,
14861 );
14862  
14863 # Update the hash we're editing...
14864 ($thisKey) = $self->getSimpleListData($slWidget2, 0, 1);
14865 if (defined $thisKey) {
14866  
14867  
14868 delete $replaceHash{$thisKey};
14869 # ...and update the displayed simple list
14870 @selectList = $slWidget2->get_selected_indices();
14871 splice(@{$slWidget2->{data}}, $selectList[0], 1);
14872 }
14873 });
14874  
14875 # 'Reset' button
14876 my $button4 = Gtk3::Button->new('Reset');
14877 $hBox2->pack_start($button4, FALSE, FALSE, $self->spacingPixels);
14878 $button4->set_tooltip_text('Undo changes to the hash');
14879 $button4->signal_connect('clicked' => sub {
14880  
14881 # Update the hash we're editing...
14882 if (! defined $key) {
14883  
14884 # Mode 1
14885 $self->promptHash_displayDataMode1($slWidget2, $iv);
14886 %replaceHash = %outerHash;
14887  
14888 } else {
14889  
14890 # Mode 2
14891 $self->promptHash_displayDataMode2($slWidget2, $iv, $key);
14892 %replaceHash = %innerHash;
14893 }
14894  
14895 # ...and update the displayed simple list
14896 @{$slWidget2->{data}} = ();
14897  
14898 if (! defined $key) {
14899 $self->promptHash_displayDataMode1($slWidget2, $iv);
14900 } else {
14901 $self->promptHash_displayDataMode2($slWidget2, $iv, $key);
14902 }
14903 });
14904  
14905 # 'Clear' button
14906 my $button5 = Gtk3::Button->new('Clear');
14907 $hBox2->pack_start($button5, FALSE, FALSE, $self->spacingPixels);
14908 $button5->set_tooltip_text('Clear the hash');
14909 $button5->signal_connect('clicked' => sub {
14910  
14911 # Update the hash we're editing...
14912 %replaceHash = ();
14913 # ...and update the displayed simple list
14914 @{$slWidget2->{data}} = ();
14915 });
14916 }
14917  
14918 # Widget drawing complete
14919 $vBox->show_all();
14920  
14921 # Get the response
14922 $response = $dialogueWin->run();
14923 if ($response eq 'accept') {
14924  
14925 # Don't save anything for read-only values
14926 if (! $readOnlyFlag) {
14927  
14928 # Mode 1 - edit the hash stored in $self->editObj->$iv or $self->editHash->$iv
14929 if (! defined $key) {
14930  
14931 # Store the hash we've been editing
14932 $self->ivAdd('editHash', $iv, \%replaceHash);
14933  
14934 # Update the simple list displayed in the parent window, if a list was specified
14935 if ($slWidget) {
14936  
14937 $self->updateListDataWithKey($slWidget, $iv, \%replaceHash);
14938 }
14939  
14940 # Mode 2 - edit the hash stored in a key-value pair; the pair is in the hash stored
14941 # as $self->editObj->$iv or $self->editHash->$iv
14942 } else {
14943  
14944 # Get a copy of the hash stored in the IV
14945 if (! $self->ivExists('editHash', $iv)) {
14946  
14947 %outerHash = $self->editObj->$iv;
14948  
14949 # If the IV has been edited, use the edited hash
14950 } else {
14951  
14952 $outerHashRef = $self->ivShow('editHash', $iv);
14953 %outerHash = %$outerHashRef;
14954 }
14955  
14956 # Now update that hash with a new key-value pair. The key is $key, the
14957 # corresponding value is a reference to the hash we've been editing,
14958 # %replaceHash
14959 $outerHash{$key} = \%replaceHash;
14960  
14961 # Store the modified outer hash as the IV
14962 $self->ivAdd('editHash', $iv, \%outerHash);
14963  
14964 # Update the displayed list, if one was specified
14965 if ($slWidget) {
14966  
14967 $self->updateListDataWithKey($slWidget, $key, \%replaceHash);
14968 }
14969 }
14970  
14971 # Call a function to re-display the simple list, if one was specified
14972 if ($callFunc) {
14973  
14974 $self->$callFunc(@callFuncArgs);
14975 }
14976 }
14977 }
14978  
14979 # Destroy the window
14980 $dialogueWin->destroy();
14981 $self->restoreFocus();
14982  
14983 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
14984 # window is visibly closed)
14985 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptHash');
14986  
14987 # Operation complete
14988 return 1;
14989 }
14990  
14991 sub promptHash_displayDataMode1 {
14992  
14993 # Called by $self->promptHash when we want to edit a hash IV in $self->editObj or
14994 # $self->editHash
14995 # The calling function had created a GA::Obj::SimpleList; this function's job is to fill
14996 # it with data
14997 #
14998 # Expected arguments
14999 # $slWidget - The GA::Obj::SimpleList where the IV's data is displayed
15000 # $iv - The IV being edited
15001 #
15002 # Return values
15003 # An empty hash on improper arguments
15004 # Otherwise returns a copy of the hash being edited
15005  
15006 my ($self, $slWidget, $iv, $check) = @_;
15007  
15008 # Local variables
15009 my (
15010 $hashRef,
15011 %emptyHash, %dataHash,
15012 );
15013  
15014 # Check for improper arguments
15015 if (! defined $slWidget || ! defined $iv || defined $check) {
15016  
15017 $axmud::CLIENT->writeImproper(
15018 $self->_objClass . '->promptHash_displayDataMode1',
15019 @_,
15020 );
15021  
15022 return %emptyHash;
15023 }
15024  
15025 # If the IV hasn't yet been edited, use the original stored hash
15026 if (! $self->ivExists('editHash', $iv)) {
15027  
15028 $hashRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
15029 %dataHash = %$hashRef;
15030  
15031 # If the IV has been edited, use the edited hash
15032 } else {
15033  
15034 $hashRef = $self->ivShow('editHash', $iv);
15035 %dataHash = %$hashRef;
15036 }
15037  
15038 # Update the GA::Obj::SimpleList (which currently stores no data)
15039 foreach my $key (sort {lc($a) cmp lc($b)} (keys %dataHash)) {
15040  
15041 push (
15042 @{$slWidget->{data}},
15043 [$key, $dataHash{$key}],
15044 );
15045 }
15046  
15047 return %dataHash;
15048 }
15049  
15050 sub promptHash_displayDataMode2 {
15051  
15052 # Called by $self->promptHash when we want to edit a hash, stored as a reference in an IV of
15053 # $self->editObj or $self->editHash
15054 #
15055 # i.e. SomeObject->{myHash} = {
15056 # iv1 => value,
15057 # iv2 => value,
15058 # iv3 => hash_reference_to_edit,
15059 # }
15060 #
15061 # The calling function had created a GA::Obj::SimpleList to display
15062 # hash_reference_to_edit; this function's job is to fill it with data
15063 #
15064 # Expected arguments
15065 # $slWidget - The GA::Obj::SimpleList where the IV's data is displayed
15066 # $iv - The IV being edited ('myHash' in the example above)
15067 # $key - The IV is a hash. $key is a key in that hash; $key's corresponding value
15068 # is the reference to the hash which we display in the simple list ('iv3'
15069 # in the example above)
15070 #
15071 # Return values
15072 # An empty hash on improper arguments
15073 # Otherwise returns a copy of the hash being edited
15074  
15075 my ($self, $slWidget, $iv, $key, $check) = @_;
15076  
15077 # Local variables
15078 my (
15079 $hashRef, $dataHashRef,
15080 %emptyHash, %hash, %dataHash,
15081 );
15082  
15083 # Check for improper arguments
15084 if (! defined $slWidget || ! defined $iv || ! defined $key || defined $check) {
15085  
15086 $axmud::CLIENT->writeImproper(
15087 $self->_objClass . '->promptHash_displayDataMode2',
15088 @_,
15089 );
15090  
15091 return %emptyHash;
15092 }
15093  
15094 # If the IV hasn't yet been edited, use the original stored hash
15095 if (! $self->ivExists('editHash', $iv)) {
15096  
15097 $hashRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
15098 %hash = %$hashRef;
15099  
15100 # If the IV has been edited, use the edited hash
15101 } else {
15102  
15103 $hashRef = $self->ivShow('editHash', $iv);
15104 %hash = %$hashRef;
15105 }
15106  
15107 # Update the GA::Obj::SimpleList (which currently stores no data)
15108 if (exists $hash{$key} && defined $hash{$key}) {
15109  
15110 $dataHashRef = $hash{$key};
15111 %dataHash = %$dataHashRef;
15112  
15113 foreach my $key (sort {lc($a) cmp lc($b)} (keys %dataHash)) {
15114  
15115 push (
15116 @{$slWidget->{data}},
15117 [$key, $dataHash{$key}],
15118 );
15119 }
15120 }
15121  
15122 return %dataHash;
15123 }
15124  
15125 # General support functions
15126  
15127 sub sensitiseWidgets {
15128  
15129 # Sensitises a list of Gtk3 widgets
15130 #
15131 # Expected arguments
15132 # @list - The list of widgets to sensitise
15133 #
15134 # Return values
15135 # 'undef' on improper arguments
15136 # 1 otherwise
15137  
15138 my ($self, @list) = @_;
15139  
15140 # Check for improper arguments
15141 if (! @list) {
15142  
15143 return $axmud::CLIENT->writeImproper($self->_objClass . '->sensitiseWidgets', @_);
15144 }
15145  
15146 foreach my $widget (@list) {
15147  
15148 $widget->set_sensitive(TRUE);
15149 }
15150  
15151 return 1;
15152 }
15153  
15154 sub desensitiseWidgets {
15155  
15156 # Desensitises a list of Gtk3 widgets
15157 #
15158 # Expected arguments
15159 # @list - The list of widgets to desensitise
15160 #
15161 # Return values
15162 # 'undef' on improper arguments
15163 # 1 otherwise
15164  
15165 my ($self, @list) = @_;
15166  
15167 # Check for improper arguments
15168 if (! @list) {
15169  
15170 return $axmud::CLIENT->writeImproper($self->_objClass . '->desensitiseWidgets', @_);
15171 }
15172  
15173 foreach my $widget (@list) {
15174  
15175 $widget->set_sensitive(FALSE);
15176 }
15177  
15178 return 1;
15179 }
15180  
15181 # Standard callbacks
15182  
15183 sub buttonCancel {
15184  
15185 # 'Cancel' button callback
15186 #
15187 # Expected arguments
15188 # (none besides $self)
15189 #
15190 # Return values
15191 # 'undef' on improper arguments
15192 # 1 otherwise
15193  
15194 my ($self, $check) = @_;
15195  
15196 # Check for improper arguments
15197 if (defined $check) {
15198  
15199 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonCancel', @_);
15200 }
15201  
15202 # Close the window
15203 $self->winDestroy();
15204  
15205 return 1;
15206 }
15207  
15208 sub buttonOK {
15209  
15210 # 'OK' button callback
15211 #
15212 # Expected arguments
15213 # (none besides $self)
15214 #
15215 # Return values
15216 # 'undef' on improper arguments
15217 # 1 otherwise
15218  
15219 my ($self, $check) = @_;
15220  
15221 # Check for improper arguments
15222 if (defined $check) {
15223  
15224 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonOK', @_);
15225 }
15226  
15227 # Save changes
15228 $self->saveChanges();
15229  
15230 # Close the window
15231 $self->winDestroy();
15232  
15233 return 1;
15234 }
15235  
15236 sub buttonReset {
15237  
15238 # 'Reset' button callback
15239 #
15240 # Expected arguments
15241 # (none besides $self)
15242 #
15243 # Return values
15244 # 'undef' on improper arguments
15245 # 1 otherwise
15246  
15247 my ($self, $check) = @_;
15248  
15249 # Local variables
15250 my $number;
15251  
15252 # Check for improper arguments
15253 if (defined $check) {
15254  
15255 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonReset', @_);
15256 }
15257  
15258 # Remove all the existing tabs from the notebook
15259 $number = $self->notebook->get_n_pages();
15260 if ($number) {
15261  
15262 for (my $count = 0; $count < $number; $count++) {
15263  
15264 $self->notebook->remove_page(0);
15265 }
15266 }
15267  
15268 # Empty $self->editHash, destroying all the changes
15269 $self->ivEmpty('editHash');
15270  
15271 # Re-draw all the tabs
15272 $self->setupNotebook();
15273 # Render the changes
15274 $self->winShowAll($self->_objClass . '->buttonReset');
15275  
15276 return 1;
15277 }
15278  
15279 sub buttonSave {
15280  
15281 # 'Save' button callback
15282 #
15283 # Expected arguments
15284 # (none besides $self)
15285 #
15286 # Return values
15287 # 'undef' on improper arguments
15288 # 1 otherwise
15289  
15290 my ($self, $check) = @_;
15291  
15292 # Local variables
15293 my $number;
15294  
15295 # Check for improper arguments
15296 if (defined $check) {
15297  
15298 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonSave', @_);
15299 }
15300  
15301 # Save changes
15302 $self->saveChanges();
15303  
15304 # Reset the hash of functions to call when a child window is closed, ready for it to be
15305 # refilled
15306 $self->ivEmpty('childDestroyHash');
15307  
15308 # Remove all the tabs
15309 $number = $self->notebook->get_n_pages();
15310 if ($number) {
15311  
15312 for (my $count = 0; $count < $number; $count++) {
15313  
15314 $self->notebook->remove_page(0);
15315 }
15316 }
15317  
15318 # Re-draw all the tabs
15319 $self->setupNotebook();
15320 # Render the changes
15321 $self->winShowAll($self->_objClass . '->buttonSave');
15322  
15323 return 1;
15324 }
15325  
15326 ##################
15327 # Accessors - set
15328  
15329 ##################
15330 # Accessors - get
15331  
15332 sub hPaned
15333 { $_[0]->{hPaned} }
15334 sub scroller
15335 { $_[0]->{scroller} }
15336 sub treeStore
15337 { $_[0]->{treeStore} }
15338 sub treeView
15339 { $_[0]->{treeView} }
15340 sub vBox
15341 { $_[0]->{vBox} }
15342 sub notebook
15343 { $_[0]->{notebook} }
15344 sub hBox
15345 { $_[0]->{hBox} }
15346 sub okButton
15347 { $_[0]->{okButton} }
15348 sub cancelButton
15349 { $_[0]->{cancelButton} }
15350 sub resetButton
15351 { $_[0]->{resetButton} }
15352 sub saveButton
15353 { $_[0]->{saveButton} }
15354  
15355 sub gridSize
15356 { $_[0]->{gridSize} }
15357  
15358 sub editObj
15359 { $_[0]->{editObj} }
15360 sub tempFlag
15361 { $_[0]->{tempFlag} }
15362 sub currentFlag
15363 { $_[0]->{currentFlag} }
15364 sub editHash
15365 { my $self = shift; return %{$self->{editHash}}; }
15366 sub editConfigHash
15367 { my $self = shift; return %{$self->{editConfigHash}}; }
15368  
15369 sub indexPointer
15370 { $_[0]->{indexPointer} }
15371 sub innerNotebookHash
15372 { my $self = shift; return %{$self->{innerNotebookHash}}; }
15373 }
15374  
15375 { package Games::Axmud::Generic::EditWin;
15376  
15377 use strict;
15378 use warnings;
15379 # use diagnostics;
15380  
15381 use Glib qw(TRUE FALSE);
15382  
15383 our @ISA = qw(
15384 Games::Axmud::Generic::ConfigWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
15385 Games::Axmud
15386 );
15387  
15388 ##################
15389 # Constructors
15390  
15391 # sub new {} # Inherited from GA::Generic::ConfigWin
15392  
15393 ##################
15394 # Methods
15395  
15396 # Standard window object functions
15397  
15398 # sub winSetup {} # Inherited from GA::Generic::ConfigWin
15399  
15400 # sub winEnable {} # Inherited from GA::Generic::ConfigWin
15401  
15402 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
15403  
15404 # sub winDestroy {} # Inherited from GA::Generic::FreeWin
15405  
15406 # sub winShowAll {} # Inherited from GA::Generic::Win
15407  
15408 # sub drawWidgets {} # Inherited from GA::Generic::ConfigWin
15409  
15410 # sub redrawWidgets {} # Inherited from GA::Generic::Win
15411  
15412 # ->signal_connects
15413  
15414 # Other functions
15415  
15416 ##################
15417 # Accessors - set
15418  
15419 ##################
15420 # Accessors - get
15421 }
15422  
15423 { package Games::Axmud::Generic::FixedWin;
15424  
15425 use strict;
15426 use warnings;
15427 # use diagnostics;
15428  
15429 use Glib qw(TRUE FALSE);
15430  
15431 our @ISA = qw(
15432 Games::Axmud::Generic::GridWin Games::Axmud::Generic::Win Games::Axmud
15433 );
15434  
15435 ##################
15436 # Constructors
15437  
15438 sub new {
15439  
15440 # Called by GA::Obj::Workspace->createGridWin and ->createSimpleGridWin
15441 # Generic function to create a 'fixed' window
15442 #
15443 # Expected arguments
15444 # $number - Unique number for this window object
15445 # $winType - The window type, must be 'fixed'
15446 # $winName - The window name, must be 'fixed'
15447 # $workspaceObj
15448 # - The GA::Obj::Workspace object for the workspace in which this window is
15449 # created
15450 #
15451 # Optional arguments
15452 # $owner - The owner, if known ('undef' if not). Typically it's a GA::Session or a
15453 # task (inheriting from GA::Generic::Task); could also be GA::Client.
15454 # It should not be another window object
15455 # (inheriting from GA::Generic::Win). The owner should have its own
15456 # ->del_winObj function which is called when $self->winDestroy is
15457 # called
15458 # $session - The owner's session. If $owner is a GA::Session, that session. If
15459 # it's something else (like a task), the task's session. If $owner is
15460 # 'undef', so is $session
15461 # $workspaceGridObj
15462 # - The GA::Obj::WorkspaceGrid object into whose grid this window has been
15463 # placed. 'undef' in $workspaceObj->gridEnableFlag = FALSE
15464 # $areaObj - The GA::Obj::Area (a region of a workspace grid zone) which handles this
15465 # window. 'undef' in $workspaceObj->gridEnableFlag = FALSE
15466 # $winmap - Ignored if set
15467 #
15468 # Return values
15469 # 'undef' on improper arguments
15470 # Blessed reference to the newly-created object on success
15471  
15472 my (
15473 $class, $number, $winType, $winName, $workspaceObj, $owner, $session, $workspaceGridObj,
15474 $areaObj, $winmap, $check,
15475 ) = @_;
15476  
15477 # Check for improper arguments
15478 if (
15479 ! defined $class || ! defined $number || ! defined $winType || ! defined $winName
15480 || ! defined $workspaceObj || defined $check
15481 ) {
15482 return $axmud::CLIENT->writeImproper($class . '->new', @_);
15483 }
15484  
15485 # Check that the $winType is valid
15486 if ($winType ne 'fixed') {
15487  
15488 return $axmud::CLIENT->writeError(
15489 'Internal window error: invalid \'fixed\' window type \'' . $winType . '\'',
15490 $class . '->new',
15491 );
15492 }
15493  
15494 # Setup
15495 my $self = {
15496 _objName => 'fixed_win_' . $number,
15497 _objClass => $class,
15498 _parentFile => undef, # No parent file object
15499 _parentWorld => undef, # No parent file object
15500 _privFlag => TRUE, # All IVs are private
15501  
15502 # Standard window object IVs
15503 # --------------------------
15504  
15505 # Unique number for this window object
15506 number => $number,
15507 # The window category - 'grid' or 'free'
15508 winCategory => 'grid',
15509 # The window type, must be 'fixed'
15510 winType => $winType,
15511 # The window name, must be 'fixed'
15512 winName => $winName,
15513 # The GA::Obj::Workspace object for the workspace in which this window is created
15514 workspaceObj => $workspaceObj,
15515 # The owner, if known ('undef' if not). Typically it's a GA::Session or a task
15516 # (inheriting from GA::Generic::Task); could also be GA::Client. It should not be
15517 # another window object (inheriting from GA::Generic::Win). The owner must have its
15518 # own ->del_winObj function which is called when $self->winDestroy is called
15519 owner => $owner,
15520 # The owner's session ('undef' if not). If ->owner is a GA::Session, that session. If
15521 # it's something else (like a task), the task's sesssion. If ->owner is 'undef', so is
15522 # ->session
15523 session => $session,
15524 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
15525 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
15526 # displayed in a 'dialogue' window)
15527 pseudoCmdMode => 'win_error',
15528  
15529 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
15530 # parent 'main' window's Gtk3::Window
15531 # The code should use this IV when it wants to do something to the window itself
15532 # (minimise it, make it active, etc)
15533 winWidget => undef,
15534 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
15535 # the parent GA::Table::PseudoWin table object
15536 # The code should use this IV when it wants to add, modify or remove widgets inside the
15537 # window itself
15538 winBox => undef,
15539 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
15540 # FALSE if not
15541 enabledFlag => FALSE,
15542 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
15543 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
15544 visibleFlag => TRUE,
15545 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
15546 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
15547 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
15548 childFreeWinHash => {},
15549 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
15550 # window is informed via a call to $self->del_childFreeWin
15551 # When the child is destroyed, this window might want to call some of its own functions
15552 # to update various widgets and/or IVs, in which case this window adds an entry to
15553 # this hash; a hash in the form
15554 # $childDestroyHash{unique_number} = list_reference
15555 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
15556 # reference to a list in groups of 2, in the form
15557 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
15558 childDestroyHash => {},
15559  
15560 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
15561 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
15562 # area)
15563 packingBox => undef,
15564  
15565 # Standard IVs for 'grid' windows
15566  
15567 # The GA::Obj::WorkspaceGrid object into whose grid this window has been placed. 'undef'
15568 # in $workspaceObj->gridEnableFlag = FALSE
15569 workspaceGridObj => $workspaceGridObj,
15570 # The GA::Obj::Area object for this window. An area object is a part of a zone's
15571 # internal grid, handling a single window (this one). Set to 'undef' in
15572 # $workspaceObj->gridEnableFlag = FALSE
15573 areaObj => $areaObj,
15574 # For pseudo-windows (in which a window object is created, but its widgets are drawn
15575 # inside a GA::Table::PseudoWin table object), the table object created. 'undef' if
15576 # this window object is a real 'grid' window
15577 pseudoWinTableObj => undef,
15578 # The name of the GA::Obj::Winmap object (not used for 'map' windows)
15579 winmap => undef,
15580  
15581 # Standard IVs for 'fixed' windows
15582 # ...
15583 };
15584  
15585 # Bless the object into existence
15586 bless $self, $class;
15587  
15588 return $self;
15589 }
15590  
15591 ##################
15592 # Methods
15593  
15594 # Standard window object functions
15595  
15596 # sub winSetup {} # Inherited from GA::Generic::GridWin
15597  
15598 # sub winEnable {} # Inherited from GA::Generic::GridWin
15599  
15600 # sub winDisengage {} # Defined in window objects which inherit this one
15601  
15602 # sub winDestroy {} # Defined in window objects which inherit this one
15603  
15604 # sub winShowAll {} # Inherited from GA::Generic::Win
15605  
15606 # sub drawWidgets {} # Inherited from GA::Generic::Win
15607  
15608 # sub redrawWidgets {} # Inherited from GA::Generic::Win
15609  
15610 # ->signal_connects
15611  
15612 # Other functions
15613  
15614 ##################
15615 # Accessors - set
15616  
15617 ##################
15618 # Accessors - get
15619 }
15620  
15621 { package Games::Axmud::Generic::FreeWin;
15622  
15623 use strict;
15624 use warnings;
15625 # use diagnostics;
15626  
15627 use Glib qw(TRUE FALSE);
15628  
15629 our @ISA = qw(Games::Axmud::Generic::Win Games::Axmud);
15630  
15631 ##################
15632 # Constructors
15633  
15634 # sub new {} # Defined in window objects which inherit this one
15635  
15636 ##################
15637 # Methods
15638  
15639 # Standard window object functions
15640  
15641 sub winSetup {
15642  
15643 # Called by GA::Generic::Win->createFreeWin, after the call to $self->new
15644 # Creates the Gtk3::Window itself
15645 #
15646 # Expected arguments
15647 # (none besides $self)
15648 #
15649 # Return values
15650 # 'undef' on improper arguments or if the window can't be opened
15651 # 1 on success
15652  
15653 my ($self, $check) = @_;
15654  
15655 # Local variables
15656 my $iv;
15657  
15658 # Check for improper arguments
15659 if (defined $check) {
15660  
15661 return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
15662 }
15663  
15664 # Create the Gtk3::Window
15665 my $winWidget = Gtk3::Window->new('toplevel');
15666 if (! $winWidget) {
15667  
15668 return undef;
15669  
15670 } else {
15671  
15672 # Store the IV now, as subsequent code needs it
15673 $self->ivPoke('winWidget', $winWidget);
15674 $self->ivPoke('winBox', $winWidget);
15675 }
15676  
15677 # Set up ->signal_connects
15678 $self->setDeleteEvent(); # 'delete-event'
15679  
15680 # Set the window title
15681 $winWidget->set_title($self->title);
15682  
15683 # Set the window's default size and position
15684 $winWidget->set_default_size($self->widthPixels, $self->heightPixels);
15685 $winWidget->set_border_width($self->borderPixels);
15686 $winWidget->set_position('center');
15687  
15688 # Set the icon list for this window
15689 $iv = $self->winType . 'WinIconList';
15690 $winWidget->set_icon_list($axmud::CLIENT->desktopObj->{$iv});
15691  
15692 # Draw the widgets used by this window
15693 if (! $self->drawWidgets()) {
15694  
15695 return undef;
15696 }
15697  
15698 # The calling function can now call $self->winEnable to make the window visible
15699 return 1;
15700 }
15701  
15702 sub winEnable {
15703  
15704 # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup
15705 # After the Gtk3::Window has been setup and moved into position, makes it visible
15706 #
15707 # Expected arguments
15708 # (none besides $self)
15709 #
15710 # Return values
15711 # 'undef' on improper arguments
15712 # 1 on success
15713  
15714 my ($self, $check) = @_;
15715  
15716 # Check for improper arguments
15717 if (defined $check) {
15718  
15719 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
15720 }
15721  
15722 # Make the window appear on the desktop
15723 $self->winShowAll($self->_objClass . '->winEnable');
15724 $self->ivPoke('enabledFlag', TRUE);
15725  
15726 return 1;
15727 }
15728  
15729 sub winDisengage {
15730  
15731 # Should not be called, in general (provides compatibility with other types of windows,
15732 # whose window objects can be destroyed without closing the windows themselves)
15733 # If called, this function just calls $self->winDestroy and returns the result
15734 #
15735 # Expected arguments
15736 # (none besides $self)
15737 #
15738 # Return values
15739 # 'undef' on improper arguments or if the window can't be disengaged
15740 # 1 on success
15741  
15742 my ($self, $check) = @_;
15743  
15744 # Check for improper arguments
15745 if (defined $check) {
15746  
15747 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDisengage', @_);
15748 }
15749  
15750 return $self->winDestroy();
15751 }
15752  
15753 sub winDestroy {
15754  
15755 # Can be called by anything
15756 # Updates IVs
15757 #
15758 # Expected arguments
15759 # (none besides $self)
15760 #
15761 # Return values
15762 # 'undef' on improper arguments, if the window can't be destroyed or if it has already
15763 # been destroyed
15764 # 1 on success
15765  
15766 my ($self, $check) = @_;
15767  
15768 # Check for improper arguments
15769 if (defined $check) {
15770  
15771 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_);
15772 }
15773  
15774 if (! $self->winBox) {
15775  
15776 # Window already destroyed in a previous call to this function
15777 return undef;
15778 }
15779  
15780 # Close any 'free' windows for which this window is a parent
15781 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
15782  
15783 $winObj->winDestroy();
15784 }
15785  
15786 # Destroy the Gtk3::Window
15787 eval { $self->winBox->destroy(); };
15788 if ($@) {
15789  
15790 # Window can't be destroyed
15791 return undef;
15792  
15793 } else {
15794  
15795 $self->ivUndef('winWidget');
15796 $self->ivUndef('winBox');
15797 }
15798  
15799 # Inform the owner and the desktop object of this 'free' window's demise
15800 $axmud::CLIENT->desktopObj->del_freeWin($self);
15801 if ($self->owner) {
15802  
15803 $self->owner->del_childFreeWin($self);
15804 }
15805  
15806 return 1;
15807 }
15808  
15809 # sub winShowAll {} # Inherited from GA::Generic::Win
15810  
15811 # sub drawWidgets {} # Inherited from GA::Generic::Win
15812  
15813 # sub redrawWidgets {} # Inherited from GA::Generic::Win
15814  
15815 # ->signal_connects
15816  
15817 sub setDeleteEvent {
15818  
15819 # Called by $self->winSetup
15820 # Set up a ->signal_connect to watch out for the user manually closing the 'free' window
15821 #
15822 # Expected arguments
15823 # (none besides $self)
15824 #
15825 # Return values
15826 # 'undef' on improper arguments
15827 # 1 otherwise
15828  
15829 my ($self, $check) = @_;
15830  
15831 # Check for improper arguments
15832 if (defined $check) {
15833  
15834 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
15835 }
15836  
15837 $self->winBox->signal_connect('delete-event' => sub {
15838  
15839 # Prevent Gtk3 from taking action directly. Instead redirect the request to
15840 # $self->winDestroy
15841 return $self->winDestroy();
15842 });
15843  
15844 return 1;
15845 }
15846  
15847 # Other functions
15848  
15849 ##################
15850 # Accessors - set
15851  
15852 ##################
15853 # Accessors - get
15854  
15855 sub widthPixels
15856 { $_[0]->{widthPixels} }
15857 sub heightPixels
15858 { $_[0]->{heightPixels} }
15859 sub borderPixels
15860 { $_[0]->{borderPixels} }
15861 sub spacingPixels
15862 { $_[0]->{spacingPixels} }
15863  
15864 sub title
15865 { $_[0]->{title} }
15866 sub configHash
15867 { my $self = shift; return %{$self->{configHash}}; }
15868 sub packingBox
15869 { $_[0]->{packingBox} }
15870 }
15871  
15872 { package Games::Axmud::Generic::GridWin;
15873  
15874 use strict;
15875 use warnings;
15876 # use diagnostics;
15877  
15878 use Glib qw(TRUE FALSE);
15879  
15880 our @ISA = qw(Games::Axmud::Generic::Win Games::Axmud);
15881  
15882 ##################
15883 # Constructors
15884  
15885 # sub new {} # Defined in window objects which inherit this one
15886  
15887 ##################
15888 # Methods
15889  
15890 # Standard window object functions
15891  
15892 sub winSetup {
15893  
15894 # Called by GA::Obj::Workspace->createGridWin or ->createSimpleGridWin
15895 # This generic function merely creates a Gtk3::Window
15896 # Your own window object code should either create a function based on
15897 # GA::Win::Internal->winSetup, or your code should inherit that function directly
15898 #
15899 # Expected arguments
15900 # (none besides $self)
15901 #
15902 # Optional arguments
15903 # $title - The window title or 'undef'. Ignored in this generic function
15904 # $listRef - Reference to a list of functions to call, just after the Gtk3::Window is
15905 # created (can be used to set up further ->signal_connects, if this
15906 # window needs them)
15907 #
15908 # Return values
15909 # 'undef' on improper arguments or if the window can't be opened
15910 # 1 on success
15911  
15912 my ($self, $title, $listRef, $check) = @_;
15913  
15914 # Local variables
15915 my $iv;
15916  
15917 # Check for improper arguments
15918 if (defined $check) {
15919  
15920 return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
15921 }
15922  
15923 # Don't create a new window, if it already exists
15924 if ($self->enabledFlag) {
15925  
15926 return undef;
15927 }
15928  
15929 # Create the Gtk3::Window
15930 my $winWidget = Gtk3::Window->new('toplevel');
15931 if (! $winWidget) {
15932  
15933 return undef;
15934  
15935 } else {
15936  
15937 # Store the IV now, as everything needs it
15938 $self->ivPoke('winWidget', $winWidget);
15939 $self->ivPoke('winBox', $winWidget);
15940 }
15941  
15942 # Set up ->signal_connects specified by the calling function, if any
15943 if ($listRef) {
15944  
15945 foreach my $func (@$listRef) {
15946  
15947 $self->$func();
15948 }
15949 }
15950  
15951 # Set the icon list for this window
15952 $iv = $self->winType . 'WinIconList';
15953 $winWidget->set_icon_list($axmud::CLIENT->desktopObj->{$iv});
15954  
15955 # Draw the widgets used by this window
15956 if (! $self->drawWidgets($winWidget)) {
15957  
15958 return undef;
15959 }
15960  
15961 # The calling function can now move the window into position, before calling
15962 # $self->winEnable to make it visible, and to set up any more ->signal_connects()
15963 return 1;
15964 }
15965  
15966 sub winEnable {
15967  
15968 # Called by GA::Obj::Workspace->createGridWin or ->createSimpleGridWin
15969 # This generic function merely makes the Gtk3::Window visible
15970 # Your own window object code should either create a function based on
15971 # GA::Win::Internal->winEnable, or your code should inherit that function directly
15972 #
15973 # Expected arguments
15974 # (none besides $self)
15975 #
15976 # Optional arguments
15977 # $listRef - Reference to a list of functions to call, just after the Gtk3::Window is
15978 # created (can be used to set up further ->signal_connects, if this
15979 # window needs them)
15980 #
15981 # Return values
15982 # 'undef' on improper arguments
15983 # 1 on success
15984  
15985 my ($self, $title, $listRef, $check) = @_;
15986  
15987 # Check for improper arguments
15988 if (defined $check) {
15989  
15990 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
15991 }
15992  
15993 # Make the window appear on the desktop
15994 $self->winShowAll($self->_objClass . '->winEnable');
15995 $self->ivPoke('enabledFlag', TRUE);
15996  
15997 # For windows about to be placed on a grid, briefly minimise the window so it doesn't
15998 # appear in the centre of the desktop before being moved to its correct workspace, size
15999 # and position
16000 if ($self->workspaceGridObj && $self->winWidget eq $self->winBox) {
16001  
16002 $self->minimise();
16003 }
16004  
16005 # Set up ->signal_connects specified by the calling function, if any
16006 if ($listRef) {
16007  
16008 foreach my $func (@$listRef) {
16009  
16010 $self->$func();
16011 }
16012 }
16013  
16014 return 1;
16015 }
16016  
16017 # sub winDisengage {} # Defined in window objects which inherit this one
16018  
16019 # sub winDestroy {} # Defined in window objects which inherit this one
16020  
16021 # sub winShowAll {} # Inherited from GA::Win::Generic
16022  
16023 # sub drawWidgets {} # Inherited from GA::Win::Generic
16024  
16025 # sub redrawWidgets {} # Inherited from GA::Win::Generic
16026  
16027 # ->signal_connects
16028  
16029 sub setDeleteEvent {
16030  
16031 # Called by GA::Obj::Workspace->createGridWin (for 'external' windows only)
16032 # Called by $self->winSetup (for other 'grid' windows)
16033 # This generic function doesn't actually create any ->signal_connects
16034 #
16035 # Expected arguments
16036 # (none besides $self)
16037 #
16038 # Return values
16039 # 'undef' on improper arguments
16040 # 1 otherwise
16041  
16042 my ($self, $check) = @_;
16043  
16044 # Check for improper arguments
16045 if (defined $check) {
16046  
16047 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
16048 }
16049  
16050 # (Do nothing)
16051  
16052 return 1;
16053 }
16054  
16055 sub setKeyPressEvent {
16056  
16057 # Called by $self->winSetup
16058 # This generic function doesn't actually create any ->signal_connects
16059 #
16060 # Expected arguments
16061 # (none besides $self)
16062 #
16063 # Return values
16064 # 'undef' on improper arguments
16065 # 1 otherwise
16066  
16067 my ($self, $check) = @_;
16068  
16069 # Check for improper arguments
16070 if (defined $check) {
16071  
16072 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyPressEvent', @_);
16073 }
16074  
16075 # (Do nothing)
16076  
16077 return 1;
16078 }
16079  
16080 sub setKeyReleaseEvent {
16081  
16082 # Called by $self->winSetup
16083 # This generic function doesn't actually create any ->signal_connects
16084 #
16085 # Expected arguments
16086 # (none besides $self)
16087 #
16088 # Return values
16089 # 'undef' on improper arguments
16090 # 1 otherwise
16091  
16092 my ($self, $check) = @_;
16093  
16094 # Check for improper arguments
16095 if (defined $check) {
16096  
16097 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyReleaseEvent', @_);
16098 }
16099  
16100 # (Do nothing)
16101  
16102 return 1;
16103 }
16104  
16105 sub setConfigureEvent {
16106  
16107 # Called by $self->winEnable
16108 # This generic function doesn't actually create any ->signal_connects
16109 #
16110 # Expected arguments
16111 # (none besides $self)
16112 #
16113 # Return values
16114 # 'undef' on improper arguments
16115 # 1 otherwise
16116  
16117 my ($self, $check) = @_;
16118  
16119 # Check for improper arguments
16120 if (defined $check) {
16121  
16122 return $axmud::CLIENT->writeImproper($self->_objClass . '->setConfigureEvent', @_);
16123 }
16124  
16125 # (Do nothing)
16126  
16127 return 1;
16128 }
16129  
16130 sub setWindowStateEvent {
16131  
16132 # Called by $self->winEnable
16133 # This generic function doesn't actually create any ->signal_connects
16134 #
16135 # Expected arguments
16136 # (none besides $self)
16137 #
16138 # Return values
16139 # 'undef' on improper arguments
16140 # 1 otherwise
16141  
16142 my ($self, $check) = @_;
16143  
16144 # Check for improper arguments
16145 if (defined $check) {
16146  
16147 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWindowStateEvent', @_);
16148 }
16149  
16150 # (Do nothing)
16151  
16152 return 1;
16153 }
16154  
16155 sub setWindowClosedEvent {
16156  
16157 # Called by GA::Obj::Workspace->createGridWin (for 'external' windows only)
16158 # This generic function doesn't actually create any ->signal_connects
16159 #
16160 # Expected arguments
16161 # (none besides $self)
16162 #
16163 # Return values
16164 # 'undef' on improper arguments
16165 # 1 otherwise
16166  
16167 my ($self, $check) = @_;
16168  
16169 # Check for improper arguments
16170 if (defined $check) {
16171  
16172 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWindowClosedEvent', @_);
16173 }
16174  
16175 # (Do nothing)
16176  
16177 return 1;
16178 }
16179  
16180 # Other functions
16181  
16182 ##################
16183 # Accessors - set
16184  
16185 sub set_areaObj {
16186  
16187 my ($self, $areaObj, $check) = @_;
16188  
16189 # Check for improper arguments
16190 if (defined $check) {
16191  
16192 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_areaObj', @_);
16193 }
16194  
16195 $self->ivPoke('areaObj', $areaObj);
16196  
16197 return 1;
16198 }
16199  
16200 sub set_workspaceGridObj {
16201  
16202 my ($self, $workspaceGridObj, $check) = @_;
16203  
16204 # Check for improper arguments
16205 if (defined $check) {
16206  
16207 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_workspaceGridObj', @_);
16208 }
16209  
16210 $self->ivPoke('workspaceGridObj', $workspaceGridObj);
16211  
16212 return 1;
16213 }
16214  
16215 ##################
16216 # Accessors - get
16217  
16218 sub workspaceGridObj
16219 { $_[0]->{workspaceGridObj} }
16220 sub areaObj
16221 { $_[0]->{areaObj} }
16222 sub pseudoWinTableObj
16223 { $_[0]->{pseudoWinTableObj} }
16224 sub winmap
16225 { $_[0]->{winmap} }
16226 }
16227  
16228 { package Games::Axmud::Generic::Interface;
16229  
16230 use strict;
16231 use warnings;
16232 # use diagnostics;
16233  
16234 use Glib qw(TRUE FALSE);
16235  
16236 our @ISA = qw(Games::Axmud);
16237  
16238 ##################
16239 # Constructors
16240  
16241 ##################
16242 # Methods
16243  
16244 sub modifyAttribs {
16245  
16246 # Called by GA::Generic::Cmd->modifyInterface (caused by ';modifytrigger', etc)
16247 # Modifies this object's IVs (the calling function modifies attributes on the corresponding
16248 # inactive interface)
16249 #
16250 # Expected arguments
16251 # $session - The calling function's GA::Session
16252 # %attribHash - A hash of attributes, in the form
16253 # (attribute, value, attribute, value...)
16254 # - The keys can match any of the keys in $self->attribHash, or the
16255 # standard attributes 'name', 'stimulus', 'response', 'enabled'
16256 #
16257 # Return values
16258 # 'undef' on improper arguments or if any of the keys in %attribHash are unrecognised
16259 # attributes
16260 # 1 otherwise
16261  
16262 my ($self, $session, %attribHash) = @_;
16263  
16264 # Local variables
16265 my $modelObj;
16266  
16267 # Check for improper arguments
16268 if (! defined $session) {
16269  
16270 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyAttribs', @_);
16271 }
16272  
16273 # If an empty hash was supplied, then of course we do nothing (but still show 1 for success)
16274 if (! %attribHash) {
16275  
16276 return 1;
16277 }
16278  
16279 # Get the corresponding interface model object
16280 $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $self->category);
16281  
16282 # Check that every key in %attribHash is valid, before we start modifying any values
16283 foreach my $attrib (keys %attribHash) {
16284  
16285 my ($type, $value);
16286  
16287 if (
16288 $attrib ne 'name' && $attrib ne 'stimulus' && $attrib ne 'response'
16289 && $attrib ne 'enabled'
16290 && ! $self->ivExists('attribHash', $attrib)
16291 ) {
16292 return $self->writeError(
16293 'Unrecognised attribute \'' . $attrib . '\' for interface category \''
16294 . $self->category . '\'',
16295 $self->_objClass . '->modifyAttribs',
16296 );
16297 }
16298  
16299 # Check the value is valid
16300 $type = $modelObj->ivShow('attribTypeHash', $attrib);
16301 $value = $self->checkAttribValue($session, $attrib, $attribHash{$attrib}, $type);
16302 if (! defined $value) {
16303  
16304 # Error message already displayed
16305 return undef;
16306  
16307 } else {
16308  
16309 # ->checkAttribValue modifies some $values (e.g. converts booleans to TRUE or FALSE)
16310 $attribHash{$attrib} = $value;
16311 }
16312 }
16313  
16314 # Modify stored attributes
16315 foreach my $key (keys %attribHash) {
16316  
16317 my $value = $attribHash{$key};
16318  
16319 # Standard attributes
16320 if ($key eq 'name') {
16321  
16322 $self->ivPoke('name', $value);
16323  
16324 } elsif ($key eq 'stimulus') {
16325  
16326 $self->ivPoke('stimulus', $value);
16327  
16328 } elsif ($key eq 'response') {
16329  
16330 $self->ivPoke('response', $value);
16331  
16332 } elsif ($key eq 'enabled') {
16333  
16334 if ($value) {
16335 $self->ivPoke('enabledFlag', TRUE);
16336 } else {
16337 $self->ivPoke('enabledFlag', FALSE);
16338 }
16339  
16340 # Category-dependent attributes
16341 } else {
16342  
16343 $self->ivAdd('attribHash', $key, $value);
16344 }
16345 }
16346  
16347 return 1;
16348 }
16349  
16350 sub checkAttribValue {
16351  
16352 # Called by GA::Generic::Interface->set_attribHash
16353 # Called by GA::Interface::Active->modifyAttributes
16354 # Called by GA::Generic::Cmd->addInterface
16355 #
16356 # Given an interface attribute, its corresponding value and the attribute type, checks that
16357 # the value is valid. Also modifies the value in some circumstances (e.g. for the
16358 # 'boolean' type, converts it to TRUE or FALSE)
16359 #
16360 # Expected arguments
16361 # $session - The calling function's GA::Session
16362 # $attrib - The name of the attribute
16363 # $value - The corresponding value
16364 # $type - The attribute type, one of 'boolean', 'colour', 'hook_event',
16365 # 'instruction', 'interval', 'keycode', 'mode', 'number', 'pattern',
16366 # 'repeat_count', 'string', 'style', 'substitution' or 'underlay'
16367 #
16368 # Return values
16369 # 'undef' on improper arguments, if $value isn't valid or if $type is unrecognised
16370 # Otherwise, returns $value (possibly after being modified)
16371  
16372 my ($self, $session, $attrib, $value, $type, $check) = @_;
16373  
16374 # Local variables
16375 my ($char, $modelObj);
16376  
16377 # Check for improper arguments
16378 if (
16379 ! defined $session || ! defined $attrib || ! defined $value || ! defined $type
16380 || defined $check
16381 ) {
16382 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkAttribValue', @_);
16383 }
16384  
16385 if ($type eq 'boolean') {
16386  
16387 # Convert $value to TRUE of FALSE
16388 $char = substr ($value, 0, 1);
16389  
16390 if (
16391 ! $value # zero (or an empty string)
16392 || $char eq 'f' || $char eq 'F' # any word beginning with 'f'/'F'
16393 ) {
16394 return FALSE;
16395  
16396 } elsif (
16397 $value eq '1' # one
16398 || $char eq 't' || $char eq 'T' # any word beginning with 't'/'T'
16399 ) {
16400 return TRUE;
16401  
16402 } else {
16403  
16404 return $session->writeWarning(
16405 'Invalid attribute value for \'' . $attrib . '\' (not a TRUE/FALSE value)',
16406 $self->_objClass . '->checkAttribValue',
16407 );
16408 }
16409  
16410 } elsif ($type eq 'colour' || $type eq 'underlay') {
16411  
16412 # Must check it's a valid Axmud colour tag (standard, xterm or RGB), or an empty string
16413 if ($value eq '') {
16414  
16415 # $value is valid
16416 return $value;
16417  
16418 } elsif ($value eq '0') {
16419  
16420 # ;addtrigger and ;modifytrigger use 0 in place of an empty string
16421 return '';
16422  
16423 } else {
16424  
16425 if ($type eq 'colour' && ! $axmud::CLIENT->checkTextTags($value)) {
16426  
16427 return $session->writeWarning(
16428 'Invalid attribute value for \'' . $attrib . '\' (not a valid standard or'
16429 . ' xterm text colour tag)',
16430 $self->_objClass . '->checkAttribValue',
16431 );
16432  
16433 } elsif (
16434 $type eq 'underlay'
16435 && ! $axmud::CLIENT->checkUnderlayTags($value)
16436 ) {
16437 return $session->writeWarning(
16438 'Invalid attribute value for \'' . $attrib . '\' (not a valid standard or'
16439 . ' xterm underlay colour tag)',
16440 $self->_objClass . '->checkAttribValue',
16441 );
16442  
16443 } else {
16444  
16445 # $value is valid
16446 return $value;
16447 }
16448 }
16449  
16450 } elsif ($type eq 'hook_event') {
16451  
16452 # Must check it's a valid hook event. Get the hook interface model
16453 $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', 'hook');
16454 # Check the hook event exists in the hash or, if not, check that it's a valid name for
16455 # a custom hook event
16456 if (
16457 ! $modelObj->ivExists('hookEventHash', $value)
16458 && ! ($value =~ m/^\_[A-Za-z0-9]/)
16459 ) {
16460 return $session->writeWarning(
16461 'Invalid attribute value for \'' . $attrib . '\' (not a valid hook event)',
16462 $self->_objClass . '->checkAttribValue',
16463 );
16464  
16465 } else {
16466  
16467 # $value is valid
16468 return $value;
16469 }
16470  
16471 } elsif ($type eq 'interval') {
16472  
16473 # CHeck the value. Valid values are
16474 # - A positive number
16475 # - A 24-hour clock time, in the form HH::MM (00:00-23:59)
16476 # - A clock time in the form 99:MM (99:00-99:59), for timers that fire once every hour
16477 # at MM minutes past the hour
16478 if (
16479 ( ! $axmud::CLIENT->floatCheck($value, 0) || $value == 0)
16480 && ! ($value =~ m/^([01]?[0-9]|2[0-3])\:[0-5][0-9]$/)
16481 && ! ($value =~ m/^99\:[0-5][0-9]$/)
16482 ) {
16483 return $session->writeWarning(
16484 'Invalid attribute value for \'' . $attrib . '\' (not an interval above 0, a'
16485 . ' 24-hour clock time in the form HH:MM, or an hourly timer in the form'
16486 . ' 99:MM)',
16487 $self->_objClass . '->checkAttribValue',
16488 );
16489  
16490 } else {
16491  
16492 # $value is valid
16493 return $value;
16494 }
16495  
16496 } elsif ($type eq 'keycode') {
16497  
16498 my ($modValue, $shiftFlag);
16499  
16500 # Remove modifiers, so we can accept 'f1', 'ctrl f1', 'alt f1', 'shift alt f1', etc
16501 # (but we don't accept either 'shift f1' or 'alt-gr f1')
16502 # For keypresses that aren't Axmud standard keycodes (like the letter 'a', for example),
16503 # we accept 'ctrl a', etc but we don't accept 'a' (so that the user can type normally)
16504 $modValue = $value;
16505 if ($modValue =~ s/(shift\s+|alt_gr\s+)//g) {
16506  
16507 $shiftFlag = TRUE;
16508 }
16509  
16510 if (
16511 $modValue =~ s/(alt\s+|ctrl\s+)//g
16512 && (
16513 $axmud::CLIENT->ivExists('constKeycodeHash', $modValue)
16514 || length ($modValue) == 1
16515 )
16516 ) {
16517 # value is $valid
16518 return $value;
16519  
16520 # Otherwise just check it's a valid standard keycode
16521 } elsif ($shiftFlag || ! $axmud::CLIENT->ivExists('constKeycodeHash', $modValue)) {
16522  
16523 return $session->writeWarning(
16524 'Invalid attribute value for \'' . $attrib . '\' (not ' . $axmud::NAME_ARTICLE
16525 . ' standard keycode)',
16526 $self->_objClass . '->checkAttribValue',
16527 );
16528  
16529 } else {
16530  
16531 # $value is valid
16532 return $value;
16533 }
16534  
16535 } elsif ($type eq 'mode') {
16536  
16537 # Must check it's a valid trigger style mode: -2, -1, 0 or a positive integer
16538 if (! $axmud::CLIENT->intCheck($value, -2)) {
16539  
16540 return $session->writeWarning(
16541 'Invalid attribute value for \'' . $attrib . '\' (not a trigger style mode)',
16542 $self->_objClass . '->checkAttribValue',
16543 );
16544  
16545 } else {
16546  
16547 # $value is valid
16548 return $value;
16549 }
16550  
16551 } elsif ($type eq 'number') {
16552  
16553 # Check it's a positive number or 0
16554 if (! $axmud::CLIENT->floatCheck($value, 0)) {
16555  
16556 return $session->writeWarning(
16557 'Invalid attribute value for \'' . $attrib . '\' (not a number, 0 or above)',
16558 $self->_objClass . '->checkAttribValue',
16559 );
16560  
16561 } else {
16562  
16563 # $value is valid
16564 return $value;
16565 }
16566  
16567 } elsif ($type eq 'repeat_count') {
16568  
16569 # Check it's a real positive integer, or the value -1
16570 if (! $axmud::CLIENT->intCheck($value, -1) || $value == 0) {
16571  
16572 return $session->writeWarning(
16573 'Invalid attribute value for \'' . $attrib . '\' (not a repeat count)',
16574 $self->_objClass . '->checkAttribValue',
16575 );
16576  
16577 } else {
16578  
16579 # $value is valid
16580 return $value;
16581 }
16582  
16583 } elsif ($type eq 'style') {
16584  
16585 # Must check it's a valid trigger style: 0, 1 or 2
16586 if ($value ne '0' && $value ne '1' && $value ne '2') {
16587  
16588 return $session->writeWarning(
16589 'Invalid attribute value for \'' . $attrib . '\' (not a trigger style)',
16590 $self->_objClass . '->checkAttribValue',
16591 );
16592  
16593 } else {
16594  
16595 # $value is valid
16596 return $value;
16597 }
16598  
16599 } elsif ($type eq 'pattern') {
16600  
16601 # Check it's a valid regex
16602 if (defined $axmud::CLIENT->regexCheck($value)) {
16603  
16604 return $session->writeWarning(
16605 'Invalid attribute value for \'' . $attrib . '\' (not a valid pattern/regular'
16606 . ' expression)',
16607 $self->_objClass . '->checkAttribValue',
16608 );
16609  
16610 } else {
16611  
16612 # $value is valid
16613 return $value;
16614 }
16615  
16616 } elsif ($type eq 'instruction' || $type eq 'string' || $type eq 'substitution') {
16617  
16618 # All values of $value are valid
16619 return $value;
16620  
16621 } else {
16622  
16623 # Unrecognised $type
16624 return $session->writeWarning(
16625 'Invalid attribute type \'' . $type . '\'',
16626 $self->_objClass . '->checkAttribValue',
16627 );
16628 }
16629 }
16630  
16631 ##################
16632 # Accessors - set
16633  
16634 sub set_attribHash {
16635  
16636 # Called by GA::Generic::Cmd->addInterface
16637 #
16638 # Expected arguments
16639 # $session - The calling function's GA::Session
16640 #
16641 # Return values
16642 # 'undef' on improper arguments
16643 # 1 otherwise
16644  
16645 my ($self, $session, @list) = @_;
16646  
16647 # Local variables
16648 my (
16649 $modelObj,
16650 %attribHash,
16651 );
16652  
16653 # Check for improper arguments
16654 if (! defined $session || ! @list) {
16655  
16656 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_attribHash', @_);
16657 }
16658  
16659 # Get the corresponding interface model object
16660 $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $self->category);
16661  
16662 # @list is in the form (attribute, value, attribute, value...)
16663 do {
16664  
16665 my ($attrib, $value, $type, $checkValue);
16666  
16667 $attrib = shift @list;
16668 $value = shift @list;
16669  
16670 # Check that the attribute exists for this category of interface
16671 if ($modelObj->ivExists('attribTypeHash', $attrib)) {
16672  
16673 # It exists. Check that $value is the right kind of value
16674 $type = $modelObj->ivShow('attribTypeHash', $attrib);
16675 $checkValue = $self->checkAttribValue($session, $attrib, $value, $type);
16676 if (! defined $checkValue) {
16677  
16678 # Error message already displayed
16679 return undef;
16680  
16681 } else {
16682  
16683 # The value may have been modified (e.g. 1 becomes TRUE)
16684 $attribHash{$attrib} = $checkValue;
16685 }
16686 }
16687  
16688 } until (! @list);
16689  
16690 # Add key-value pairs to $self->attribHash, one at a time
16691 foreach my $key (keys %attribHash) {
16692  
16693 $self->ivAdd('attribHash', $key, $attribHash{$key});
16694 }
16695  
16696 return 1;
16697 }
16698  
16699 sub set_beforeAfterHashes {
16700  
16701 # Called by GA::Generic::Cmd->addInterface, ->modifyInterface
16702 #
16703 # Expected arguments
16704 # $session - The calling function's GA::Session
16705 # $beforeHashRef - Reference to a hash, whose key-value pairs should be added to
16706 # $self->beforeHash
16707 # $afterHashRef - Reference to a hash, whose key-value pairs should be added to
16708 # $self->afterHash
16709 #
16710 # Optional arguments (when called by ->modifyInterface)
16711 # $beforeRemoveHashRef - Reference to a hash, whose key-value pairs should be added to
16712 # $self->beforeHash
16713 # $afterRemoveHashRef - Reference to a hash, whose key-value pairs should be added to
16714 # $self->afterHash
16715 #
16716 # Return values
16717 # 'undef' on improper arguments
16718 # 1 otherwise
16719  
16720 my (
16721 $self, $session, $beforeHashRef, $afterHashRef,
16722 $beforeRemoveHashRef, $afterRemoveHashRef,
16723 $check,
16724 ) = @_;
16725  
16726 # Check for improper arguments
16727 if (
16728 ! defined $session || ! defined $beforeHashRef || ! defined $afterHashRef
16729 || defined $check
16730 ) {
16731 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_beforeAfterHashes', @_);
16732 }
16733  
16734 foreach my $name (keys %$beforeHashRef) {
16735  
16736 $self->ivAdd('beforeHash', $name, undef);
16737 }
16738  
16739 foreach my $name (keys %$afterHashRef) {
16740  
16741 $self->ivAdd('afterHash', $name, undef);
16742 }
16743  
16744 if ($beforeRemoveHashRef) {
16745  
16746 foreach my $name (keys %$beforeRemoveHashRef) {
16747  
16748 if ($self->ivExists('beforeHash', $name)) {
16749  
16750 $self->ivDelete('beforeHash', $name);
16751 }
16752 }
16753 }
16754  
16755 if ($afterRemoveHashRef) {
16756  
16757 foreach my $name (keys %$afterRemoveHashRef) {
16758  
16759 if ($self->ivExists('afterHash', $name)) {
16760  
16761 $self->ivDelete('afterHash', $name);
16762 }
16763 }
16764 }
16765  
16766 return 1;
16767 }
16768  
16769 ##################
16770 # Accessors - get
16771 }
16772  
16773 { package Games::Axmud::Generic::InterfaceCage;
16774  
16775 use strict;
16776 use warnings;
16777 # use diagnostics;
16778  
16779 use Glib qw(TRUE FALSE);
16780  
16781 our @ISA = qw(Games::Axmud::Generic::Cage Games::Axmud);
16782  
16783 ##################
16784 # Constructors
16785  
16786 sub new {
16787  
16788 # Inherited by GA::Cage::Trigger->new, etc
16789 # Creates a new instance of a trigger, alias, macro, timer or hook cage
16790 #
16791 # Expected arguments
16792 # $session - The calling function's GA::Session (not stored as an IV)
16793 # $profName - The parent profile's name (e.g. matches the object's ->name)
16794 # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc)
16795 #
16796 # Return values
16797 # 'undef' on improper arguments or if the cage already seems to exist
16798 # Blessed reference to the newly-created object on success
16799  
16800 my ($class, $session, $profName, $profCategory, $check) = @_;
16801  
16802 # Local variables
16803 my (
16804 $cageType, $name,
16805 @typeList,
16806 );
16807  
16808 # Check for improper arguments
16809 if (
16810 ! defined $session || ! defined $profName || ! defined $profCategory
16811 || defined $check
16812 ) {
16813 return $axmud::CLIENT->writeImproper($class . '->new', @_);
16814 }
16815  
16816 # Is this a trigger, alias, macro, timer or hook cage?
16817 @typeList = ('Trigger', 'Alias', 'Macro', 'Timer', 'Hook');
16818 OUTER: foreach my $item (@typeList) {
16819  
16820 if (index ($class, $item) > -1) {
16821  
16822 $cageType = lc($item);
16823 last OUTER;
16824 }
16825 }
16826  
16827 # Compose the cage's unique name
16828 $name = $cageType . '_' . $profCategory . '_' . $profName;
16829  
16830 # Check that $name is valid and not already in use by another profile
16831 if (! $axmud::CLIENT->nameCheck($name, 42)) {
16832  
16833 return $session->writeError(
16834 'Registry naming error: invalid name \'' . $name . '\'',
16835 $class . '->new',
16836 );
16837  
16838 } elsif ($session->ivExists('cageHash', $name)) {
16839  
16840 return $session->writeError(
16841 'Registry naming error: cage \'' . $name . '\' already exists',
16842 $class . '->new',
16843 );
16844 }
16845  
16846 # Setup
16847 my $self = {
16848 _objName => $name,
16849 _objClass => $class,
16850 _parentFile => 'otherprof',
16851 _parentWorld => $session->currentWorld->name,
16852 _privFlag => FALSE, # All IVs are public
16853  
16854 # Standard cage IVs
16855 # -----------------
16856  
16857 name => $name,
16858 cageType => $cageType,
16859 standardFlag => TRUE, # This is a built-in Axmud cage
16860 profName => $profName,
16861 profCategory => $profCategory,
16862  
16863 # Interface cage IVs
16864 # ------------------
16865  
16866 # Hash of interfaces in the form
16867 # $interfaceHash{interface_name} = blessed_reference_to_interface_object
16868 interfaceHash => {},
16869 };
16870  
16871 # Bless the object into existence
16872 bless $self, $class;
16873 return $self;
16874 }
16875  
16876 sub clone {
16877  
16878 # Creates a clone of an trigger, alias, macro, timer or hook cage
16879 #
16880 # Expected arguments
16881 # $session - The calling function's GA::Session (not stored as an IV)
16882 # $profName - The parent profile's name (e.g. matches the object's ->name)
16883 # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc)
16884 #
16885 # Return values
16886 # 'undef' on improper arguments or if the cage already seems to exist
16887 # Blessed reference to the newly-created object on success
16888  
16889 my ($self, $session, $profName, $profCategory, $check) = @_;
16890  
16891 # Local variables
16892 my (
16893 $name,
16894 %hash, %cloneHash,
16895 );
16896  
16897 # Check for improper arguments
16898 if (
16899 ! defined $session || ! defined $profName || ! defined $profCategory
16900 || defined $check
16901 ) {
16902 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
16903 }
16904  
16905 # Compose the cage's unique name
16906 $name = $self->cageType . '_' . $profCategory . '_' . $profName;
16907  
16908 # Check that $name is valid and not already in use by another profile
16909 if (! $axmud::CLIENT->nameCheck($name, 42)) {
16910  
16911 return $axmud::CLIENT->writeError(
16912 'Registry naming error: invalid name \'' . $name . '\'',
16913 $self->_objClass . '->clone',
16914 );
16915  
16916 } elsif ($session->ivExists('cageHash', $name)) {
16917  
16918 return $axmud::CLIENT->writeError(
16919 'Registry naming error: cage \'' . $name . '\' already exists',
16920 $self->_objClass . '->clone',
16921 );
16922 }
16923  
16924 # Setup
16925 my $clone = {
16926 _objName => $name,
16927 _objClass => $self->_objClass,
16928 _parentFile => 'otherprof',
16929 _parentWorld => undef,
16930 _privFlag => FALSE, # All IVs are public
16931  
16932 # Standard cage IVs
16933 # -----------------
16934  
16935 name => $name,
16936 cageType => $self->cageType,
16937 standardFlag => TRUE, # This is a built-in Axmud cage
16938 profName => $profName,
16939 profCategory => $profCategory,
16940  
16941 # Command cage IVs
16942 # ----------------
16943  
16944 interfaceHash => {$self->interfaceHash}, # Set below
16945 };
16946  
16947 # Bless the cloned object into existence
16948 bless $clone, $self->_objClass;
16949  
16950 # $self->interfaceHash contains a collection of blessed references to trigger/alias/macro/
16951 # timer/hook objects, each of which must be cloned, too
16952 %hash = $self->interfaceHash;
16953 if (%hash) {
16954  
16955 foreach my $interfaceName (keys %hash) {
16956  
16957 my ($interfaceObj, $newObj);
16958  
16959 $interfaceObj = $hash{$interfaceName};
16960 $newObj = $interfaceObj->clone($profName);
16961 if (! $newObj) {
16962  
16963 $session->writeWarning(
16964 'Error cloning the ' . $self->cageType . ' interface object while cloning'
16965 . ' the ' . $self->cageType . ' cage for the profile \'' . $profName . '\'',
16966 $self->_objClass . '->clone',
16967 );
16968  
16969 } else {
16970  
16971 $cloneHash{$newObj->name} = $newObj;
16972 }
16973 }
16974  
16975 if (%cloneHash) {
16976  
16977 # Set this object's IV
16978 $clone->{interfaceHash} = \%cloneHash;
16979 }
16980 }
16981  
16982 return $clone;
16983 }
16984  
16985 ##################
16986 # Methods
16987  
16988 ##################
16989 # Accessors - set
16990  
16991 ##################
16992 # Accessors - get
16993  
16994 # NB These methods set/return the cage's ACTUAL interface hash. To get/set values from this hash
16995 # AND/OR its inferiors, use the generic cage's ->ivXXX functions
16996 sub interfaceHash
16997 { my $self = shift; return %{$self->{interfaceHash}}; }
16998 }
16999  
17000 { package Games::Axmud::Generic::InterfaceModel;
17001  
17002 use strict;
17003 use warnings;
17004 # use diagnostics;
17005  
17006 use Glib qw(TRUE FALSE);
17007  
17008 our @ISA = qw(Games::Axmud);
17009  
17010 ##################
17011 # Constructors
17012  
17013 ##################
17014 # Methods
17015  
17016 ##################
17017 # Accessors - set
17018  
17019 ##################
17020 # Accessors - get
17021  
17022 sub category
17023 { $_[0]->{category} }
17024  
17025 sub stimulusName
17026 { $_[0]->{stimulusName} }
17027 sub responseName
17028 { $_[0]->{responseName} }
17029  
17030 sub optionalAttribHash
17031 { my $self = shift; return %{$self->{optionalAttribHash}}; }
17032 sub attribTypeHash
17033 { my $self = shift; return %{$self->{attribTypeHash}}; }
17034 sub compulsorySwitchHash
17035 { my $self = shift; return %{$self->{compulsorySwitchHash}}; }
17036 sub optionalSwitchHash
17037 { my $self = shift; return %{$self->{optionalSwitchHash}}; }
17038 }
17039  
17040 { package Games::Axmud::Generic::MapWin;
17041  
17042 use strict;
17043 use warnings;
17044 # use diagnostics;
17045  
17046 use Glib qw(TRUE FALSE);
17047  
17048 our @ISA = qw(
17049 Games::Axmud::Generic::GridWin Games::Axmud::Generic::Win Games::Axmud
17050 );
17051  
17052 ##################
17053 # Constructors
17054  
17055 # sub new {} # Defined in window objects which inherit this one
17056  
17057 ##################
17058 # Methods
17059  
17060 # Standard window object functions
17061  
17062 # sub winSetup {} # Inherited from GA::Generic::GridWin
17063  
17064 # sub winEnable {} # Inherited from GA::Generic::GridWin
17065  
17066 # sub winDisengage {} # Defined in window objects which inherit this one
17067  
17068 # sub winDestroy {} # Defined in window objects which inherit this one
17069  
17070 # sub winShowAll {} # Inherited from GA::Generic::Win
17071  
17072 # sub drawWidgets {} # Inherited from GA::Generic::Win
17073  
17074 # sub redrawWidgets {} # Inherited from GA::Generic::Win
17075  
17076 # Standard 'map' window object functions
17077  
17078 # sub winReset {} # Defined in window objects which inherit this one
17079  
17080 # sub winUpdate {} # Defined in window objects which inherit this one
17081  
17082 # ->signal_connects
17083  
17084 # Other functions
17085  
17086 ##################
17087 # Accessors - set
17088  
17089 ##################
17090 # Accessors - get
17091 }
17092  
17093 { package Games::Axmud::Generic::Mcp;
17094  
17095 use strict;
17096 use warnings;
17097 # use diagnostics;
17098  
17099 use Glib qw(TRUE FALSE);
17100  
17101 our @ISA = qw(Games::Axmud);
17102  
17103 ##################
17104 # Constructors
17105  
17106 sub new {
17107  
17108 # Called by GA::Client->createSupportedMcpPackages and ->addPluginMcpPackages to create an
17109 # MCP package object, which handles one or more MCP messages
17110 #
17111 # Objects that inherit from this one should include at least their own ->msg function (but
17112 # should use the inherited version of all other functions in this generic object,
17113 # including ->new and ->clone)
17114 #
17115 # Expected arguments
17116 # $name - The name of the GCP package, e.g. 'mcp-negotiate-can'. Must conform to
17117 # MCP's package name rules (see the MCP spec for more information)
17118 #
17119 # Optional aguments
17120 # $minVersion - The minimum package version supported (e.g. 1.0, 2.0 etc). If not
17121 # specified or not a valid number (any decimal number greater than 0),
17122 # 1.0 is used
17123 # $maxVersion - The maximum package version supported (e.g. 1.0, 2.0 etc). If not
17124 # specified or not a valid number (any decimal number greater than 0),
17125 # 1.0 is used
17126 # $plugin - For MCP packages defined by a plugin, the plugin's main package
17127 # (declared in the file header). For Axmud-supported MCP packages,
17128 # should be 'undef'
17129 # @supplantList - An optional list of MCP package names for which Axmud should prefer to
17130 # use this MCP package, if the world supports both. Standard MCP
17131 # packages like 'mcp-negotiate' cannot be supplanted (specifically,
17132 # any package whose name begins 'mcp-' cannot be supplanted; the name
17133 # is ignored if present in this list)
17134 #
17135 # Return values
17136 # 'undef' on improper arguments
17137 # Blessed reference to the newly-created object on success
17138  
17139 my ($class, $name, $minVersion, $maxVersion, $plugin, @supplantList) = @_;
17140  
17141 # Local variables
17142 my (
17143 @modList,
17144 %checkHash,
17145 );
17146  
17147 # Check for improper arguments
17148 if (! defined $class || ! defined $name) {
17149  
17150 return $axmud::CLIENT->writeImproper($class . '->new', @_);
17151 }
17152  
17153 # Set the minimum/maximum versions, if not specified or if invalid values specified
17154 if (
17155 ! defined $minVersion
17156 || $minVersion eq '0'
17157 || ! $axmud::CLIENT->floatCheck($minVersion, 0)
17158 ) {
17159 $minVersion = '1.0';
17160 }
17161  
17162 if (
17163 ! defined $maxVersion
17164 || $maxVersion eq '0'
17165 || ! $axmud::CLIENT->floatCheck($maxVersion, 0)
17166 ) {
17167 $maxVersion = '1.0';
17168 }
17169  
17170 # Remove any 'official' packages (and any duplicate package names)from @supplantList
17171 foreach my $item (@supplantList) {
17172  
17173 if (! exists $checkHash{$item} && substr($item, 0, 4) ne 'mcp-') {
17174  
17175 push (@modList, $item);
17176 $checkHash{$item} = undef;
17177 }
17178 }
17179  
17180 # Setup
17181 my $self = {
17182 _objName => $name,
17183 _objClass => $class,
17184 _parentFile => undef,
17185 _parentWorld => undef,
17186 _privFlag => TRUE, # All IVs are private
17187  
17188 # IVs
17189 # ---
17190  
17191 # The name of the GCP package, e.g. 'mcp-negotiate-can'. Must conform to MCP's package
17192 # name rules (see the MCP spec for more information)
17193 name => $name,
17194 # For MCP packages defined by a plugin, the plugin's main package (declared in the file
17195 # header). For Axmud-supported MCP packages, should be 'undef'
17196 plugin => $plugin,
17197 # An optional list of MCP package names for which Axmud should prefer to use this MCP
17198 # package, if the world supports both
17199 supplantList => [@modList],
17200  
17201 # The minimum package version supported (e.g. 1.0, 2.0 etc)
17202 minVersion => $minVersion,
17203 # The maximum package version supported (e.g. 1.0, 2.0 etc)
17204 maxVersion => $maxVersion,
17205 # The highest version that's supported by both the server and client (set by
17206 # a call to $self->set_useVersion from GA::Session->detectMCP or
17207 # ->processMcpMsg)
17208 useVersion => undef,
17209  
17210 # Any values which particular kinds of MCP package need to store, can be stored in this
17211 # hash
17212 dataHash => {},
17213 };
17214  
17215 # Bless the object into existence
17216 bless $self, $class;
17217 return $self;
17218 }
17219  
17220 sub clone {
17221  
17222 # Called by GA::Session->detectMCP to clone an MCP package object stored in
17223 # GA::Client->mcpPackageHash (with default settings, and whose code is never executed)
17224 # into an MCP package object stored in GA::Session->mcpPackageHash (with custom settings,
17225 # and whose code can be executed when MCP messages are received)
17226 #
17227 # Expected arguments
17228 # $session - The GA::Session which will store the cloned MCP package object
17229 #
17230 # Return values
17231 # 'undef' on improper arguments
17232 # Blessed reference to the newly-created object on success
17233  
17234 my ($self, $session, $check) = @_;
17235  
17236 # Check for improper arguments
17237 if (! defined $session || defined $check) {
17238  
17239 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
17240 }
17241  
17242 # Setup
17243 my $clone = {
17244 _objName => $self->_objName,
17245 _objClass => $self->_objClass,
17246 _parentFile => undef,
17247 _parentWorld => $session->currentWorld->name,
17248 _privFlag => TRUE, # All IVs are private
17249  
17250 name => $self->name,
17251 plugin => $self->plugin,
17252 supplantList => [$self->supplantList],
17253 minVersion => $self->minVersion,
17254 maxVersion => $self->maxVersion,
17255 useVersion => undef,
17256  
17257 dataHash => {},
17258 };
17259  
17260 # Bless the cloned object into existence
17261 bless $clone, $self->_objClass;
17262 return $clone;
17263 }
17264  
17265 ##################
17266 # Methods
17267  
17268 sub msg {
17269  
17270 # Called by GA::Session->processMcpMsg
17271 # This generic function does nothing, except to check that the message belongs to this
17272 # package
17273 #
17274 # Expected arguments
17275 # $session - The calling GA::Session
17276 # $msg - The MCP message name, e.g. 'mcp-negotiate-can'
17277 #
17278 # Optional arguments
17279 # %hash - A hash of key-value pairs which accompany the MCP message (may be an
17280 # empty hash)
17281 #
17282 # Return values
17283 # 'undef' on improper arguments or if there's an error processing the message
17284 # 1 if the message is processed successfully
17285  
17286 my ($self, $session, $msg, %hash) = @_;
17287  
17288 # Local variables
17289 my $name;
17290  
17291 # Check for improper arguments
17292 if (! defined $session || ! defined $msg) {
17293  
17294 return $axmud::CLIENT->writeImproper($self->_objClass . '->msg', @_);
17295 }
17296  
17297 # Check that the MCP message actually belongs to this package
17298 $name = $self->name;
17299 if (! ($msg =~ m/^$name\-/)) {
17300  
17301 return undef;
17302 }
17303  
17304 # (Add your own code here)
17305  
17306 return 1;
17307 }
17308  
17309 ##################
17310 # Accessors - set
17311  
17312 sub add_scalar {
17313  
17314 # Can be called by anything to add a key-value pair to $self->dataHash, using a scalar value
17315 # (which can be 'undef')
17316 # The scalar value is stored as a scalar value and can be retrieved with a call to
17317 # $self->get_scalar()
17318  
17319 my ($self, $key, $scalar, $check) = @_;
17320  
17321 # Check for improper arguments
17322 if (! defined $key || defined $check) {
17323  
17324 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_scalar', @_);
17325 }
17326  
17327 $self->ivPoke('dataHash', $key, $scalar);
17328  
17329 return 1;
17330 }
17331  
17332 sub get_scalar {
17333  
17334 my ($self, $key, $check) = @_;
17335  
17336 # Check for improper arguments
17337 if (! defined $key || defined $check) {
17338  
17339 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_scalar', @_);
17340 }
17341  
17342 return $self->ivShow('dataHash', $key);
17343 }
17344  
17345 sub add_list {
17346  
17347 # Can be called by anything to add a key-value pair to $self->dataHash, using a list value
17348 # (which can be an empty list)
17349 # The list value is stored as a list reference and can be retrieved with a call to
17350 # $self->get_list()
17351  
17352 my ($self, $key, @list) = @_;
17353  
17354 # Check for improper arguments
17355 if (! defined $key) {
17356  
17357 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_list', @_);
17358 }
17359  
17360 $self->ivPoke('dataHash', $key, \@list);
17361  
17362 return 1;
17363 }
17364  
17365 sub get_list {
17366  
17367 my ($self, $key, $check) = @_;
17368  
17369 # Local variables
17370 my $listRef;
17371  
17372 # Check for improper arguments
17373 if (! defined $key || defined $check) {
17374  
17375 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_list', @_);
17376 }
17377  
17378 $listRef = $self->ivShow('dataHash', $key);
17379 if (ref $listRef eq 'ARRAY') {
17380  
17381 return @$listRef;
17382  
17383 } else {
17384  
17385 # Emergency failsafe - return the reference itself
17386 return $listRef;
17387 }
17388 }
17389  
17390 sub add_hash {
17391  
17392 # Can be called by anything to add a key-value pair to $self->dataHash, using a hash value
17393 # (which can be empty hash)
17394 # The hash value is stored as a hash reference (and can be retrieved with a call to
17395 # $self->get_hash()
17396  
17397 my ($self, $key, %hash) = @_;
17398  
17399 # Check for improper arguments
17400 if (! defined $key) {
17401  
17402 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_hash', @_);
17403 }
17404  
17405 $self->ivPoke('dataHash', $key, \%hash);
17406  
17407 return 1;
17408 }
17409  
17410 sub get_hash {
17411  
17412 my ($self, $key, $check) = @_;
17413  
17414 # Local variables
17415 my $hashRef;
17416  
17417 # Check for improper arguments
17418 if (! defined $key || defined $check) {
17419  
17420 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_hash', @_);
17421 }
17422  
17423 $hashRef = $self->ivShow('dataHash', $key);
17424 if (ref $hashRef eq 'HASH') {
17425  
17426 return %$hashRef;
17427  
17428 } else {
17429  
17430 # Emergency failsafe - return the reference itself
17431 return $hashRef;
17432 }
17433 }
17434  
17435 sub del_key {
17436  
17437 my ($self, $key, $check) = @_;
17438  
17439 # Check for improper arguments
17440 if (! defined $key || defined $check) {
17441  
17442 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_key', @_);
17443 }
17444  
17445 $self->ivDelete('dataHash', $key);
17446  
17447 return 1;
17448 }
17449  
17450 sub set_useVersion {
17451  
17452 my ($self, $version, $check) = @_;
17453  
17454 # Check for improper arguments
17455 if (! defined $version || defined $check) {
17456  
17457 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_useVersion', @_);
17458 }
17459  
17460 $self->ivPoke('useVersion', $version);
17461  
17462 return 1;
17463 }
17464  
17465 ##################
17466 # Accessors - get
17467  
17468 sub name
17469 { $_[0]->{name} }
17470 sub plugin
17471 { $_[0]->{plugin} }
17472 sub supplantList
17473 { my $self = shift; return @{$self->{supplantList}}; }
17474  
17475 sub minVersion
17476 { $_[0]->{minVersion} }
17477 sub maxVersion
17478 { $_[0]->{maxVersion} }
17479 sub useVersion
17480 { $_[0]->{useVersion} }
17481  
17482 sub dataHash
17483 { my $self = shift; return %{$self->{dataHash}}; }
17484 }
17485  
17486 { package Games::Axmud::Generic::ModelObj;
17487  
17488 use strict;
17489 use warnings;
17490 # use diagnostics;
17491  
17492 use Glib qw(TRUE FALSE);
17493  
17494 our @ISA = qw(Games::Axmud);
17495  
17496 ##################
17497 # Constructors
17498  
17499 sub new {
17500  
17501 # Prepare a new instance of the generic model object (which is never blessed into existence)
17502 # NB Room model objects do inherit from this object, but don't call this function; they
17503 # initialise all of their own IVs
17504 # NB Exit model objects don't inherit from this object
17505 #
17506 # Expected arguments
17507 # $session - The parent GA::Session (not stored as an IV)
17508 # $name - A name for the object. For room objects, this is the same as the room's
17509 # brief description. For regions, ->name is the only place $name is
17510 # stored. For everything else, ->noun is also set to ->name
17511 # - (NB If $name is longer than 32 characters, it is shortened)
17512 # $category - 'region', 'room', 'weapon', 'armour', 'garment', 'char', 'minion',
17513 # 'sentient', 'creature', 'portable', 'decoration' or 'custom' (but room
17514 # model objects don't call this function)
17515 #
17516 # Return values
17517 # 'undef' on improper arguments
17518 # Otherwise returns $self, a hash that will be blessed into existence by the inheriting
17519 # object
17520  
17521 my ($class, $session, $name, $category, $check) = @_;
17522  
17523 # Check for improper arguments
17524 if (
17525 ! defined $class || ! defined $session || ! defined $name || ! defined $category
17526 || defined $check
17527 ) {
17528 return $axmud::CLIENT->writeImproper($class . '->new', @_);
17529 }
17530  
17531 # Check that $category is valid
17532 if (! $axmud::CLIENT->ivExists('constModelTypeHash', $category)) {
17533  
17534 return $axmud::CLIENT->writeError(
17535 'Invalid model object category \'' . $category . '\'',
17536 $class . '->new',
17537 );
17538 }
17539  
17540 # If $name is longer than 32 characters, shorten it (and add an ellipsis)
17541 if (length ($name) > 32) {
17542  
17543 $name = substr($name, 0, 29) . '...';
17544 }
17545  
17546 # Setup
17547 my $self = {
17548 _objName => $name,
17549 _objClass => $class,
17550 _parentFile => undef, # Set by the calling function
17551 _parentWorld => undef, # Set by the calling function
17552 _privFlag => FALSE, # All IVs are public
17553  
17554 # NB If any of these IVs are changed, GA::Generic::ModelObj->convertCategory must be
17555 # changed, too
17556  
17557 # Group 1 IVs (all objects)
17558 # -------------------------
17559  
17560 # The object's actual name, e.g. 'orc' (can include spaces)
17561 name => $name,
17562 # What kind of object this is ('char', 'portable', 'custom' etc)
17563 category => $category,
17564 # Flag set to TRUE if this object is in $session's world model (in which case, the
17565 # object is a 'model object')
17566 # Flag set to FALSE if this object is not in $session's world model (in which case, the
17567 # object is a 'non-model object')
17568 # All objects which call this function have their ->modelFlag set to FALSE, initially
17569 modelFlag => FALSE,
17570 # For model objects, a unique number ('undef' for non-model objects)
17571 number => undef,
17572 # Number of the model object of the room where this object is found, the shop where this
17573 # object is bought, the NPC from which this object is liberated, or the region in
17574 # which this object wanders ('undef' for non-model objects, or if there is nothing
17575 # resembling a parent)
17576 parent => undef,
17577 # Hash of numbers of model objects for which this is the ->parent. Hash in the form
17578 # $childHash{number} = 'undef'
17579 childHash => {},
17580  
17581 # These variables are the same for each kind of object (the same for all weapons, the
17582 # same for all decorations, etc)
17583  
17584 # Flag set to FALSE if this object is an abstract concept ('region' and 'room', possibly
17585 # 'custom'), TRUE if this object is a concrete thing (everything else, possibly
17586 # including 'custom')
17587 concreteFlag => FALSE,
17588 # Flag set to TRUE if this object is alive, FALSE if not
17589 aliveFlag => FALSE,
17590 # Flag set to TRUE if this object is sentient (capable of speech, in theory), FALSE if
17591 # not
17592 sentientFlag => FALSE,
17593 # Flag set to TRUE if the object can be carried (in theory), FALSE if not
17594 portableFlag => FALSE,
17595 # Flag set to TRUE if the object can be bought and sold (in theory), FALSE if not
17596 saleableFlag => FALSE,
17597  
17598 # Private properties for this object, in a customisable hash
17599 privateHash => {},
17600  
17601 # If the world's source code is available on the user's computer (i.e. the world model
17602 # object's ->mudlibPath IV is set), and if the file matching this object is known,
17603 # the path to that file (relative to the directory stored in ->mudLibPath)
17604 sourceCodePath => undef,
17605 # Notes on this object, if the user wants to add them. Each value in the list is a
17606 # separate line for display
17607 notesList => [],
17608 };
17609  
17610 # Group 2 IVs (all objects except 'region' and 'room')
17611 # ----------------------------------------------------
17612  
17613 if ($category ne 'region' && $category ne 'room') {
17614  
17615 # A word string most likely to be the main noun (usually a single word, e.g. 'sword')
17616 $self->{noun} = undef,
17617 # A possible description of the object. For example, with 'a huge hairy orc', possible
17618 # noun tags include 'orc', 'hairy orc', 'huge hairy orc' and 'huge hairy orc'
17619 # Is set as required; the default setting is the same as $self->noun
17620 $self->{nounTag} = undef,
17621 # List of other words which are known to be nouns for this object
17622 $self->{otherNounList} = [],
17623 # List of other words which are known to be adjectives describing this object
17624 $self->{adjList} = [],
17625 # List of pseudo-adjectives (single words like 'suspicious' reduced from a longer string
17626 # like 'slightly suspicious-looking') describing this object
17627 $self->{pseudoAdjList} = [],
17628 # List of root adjectives describing this object (for languages that use declined
17629 # adjectives; English isn't one of them)
17630 $self->{rootAdjList} = [],
17631 # Words describing the object which aren't known nouns or adjectives
17632 $self->{unknownWordList} = [],
17633 # A number representing how many there of this object there are; usually set to 1
17634 $self->{multiple} = 1,
17635 # How the object appears in verbose room descriptions, minus any initial articles
17636 $self->{baseString} = undef,
17637 # Description for the object, if known (e.g. 'A magnificent gleaming sword, perfect for
17638 # chopping up trolls')
17639 $self->{descrip} = undef,
17640  
17641 # Two IVs for non-model objects used with the Inventory task (set to 'undef' when used
17642 # by anything else)
17643  
17644 # If this object is contained in another one, the model number of the container
17645 $self->{container} = undef,
17646 # How this object is possessed ('wield', 'hold', 'wear', 'carry', 'sack', 'misc')
17647 $self->{inventoryType} = undef,
17648 }
17649  
17650 # Group 3 IVs ('character', 'minion', 'sentient', 'creature' and optionally 'custom')
17651 # -----------------------------------------------------------------------------------
17652  
17653 # (Group 3 IVs are for available for use in any code you write to handle attacks)
17654 if (
17655 $category eq 'character' || $category eq 'minion' || $category eq 'sentient'
17656 || $category eq 'creature' || $category eq 'custom'
17657 ) {
17658 # The current status of the fight with this object:
17659 # 'waiting' - the fight hasn't started yet (but will soon)
17660 # 'alive' - the target is alive
17661 # 'kill' - the target is dead
17662 # 'flee' - the target has run away in a direction that can be followed
17663 # 'escape' - the target has run away, and can't be pursued for some reason
17664 # The current status of the interaction with this object:
17665 # 'waiting' - the interaction hasn't started yet (but will soon)
17666 # 'interact' - the target is interacting (and alive)
17667 # 'finish' - the interaction has finished
17668 # 'flee' - the target has run away in a direction that can be followed
17669 # 'escape' - the target has run away, and can't be pursued for some reason
17670 $self->{targetStatus} = undef;
17671 # What kind of attack this attack: 'fight' for a fight, and 'interaction' for an
17672 # interaction
17673 $self->{targetType} = undef;
17674 # For targets who move after a fight starts. The path from the original location to the
17675 # target's presumed current location, e.g. 'n;nw;w'
17676 $self->{targetPath} = undef;
17677 # For targets who move after a fight starts. The target's presumed location in the
17678 # world (the world model number of a room). Set to 'undef' if unknown
17679 $self->{targetRoomNum} = undef;
17680  
17681 # Is the object listed separately when the user types a look/glance command, or is it
17682 # only apparent that the object exists from a description of something else? (Group 4
17683 # IV for inanimate objects)
17684 # Flag set to TRUE if the object is listed separately, FALSE if not
17685 $self->{explicitFlag} = TRUE;
17686  
17687 # Flag that can be set to TRUE, if your code needs to remember which objects in a room
17688 # have been attacked
17689 $self->{alreadyAttackedFlag}
17690 = FALSE;
17691 }
17692  
17693 # Group 4 IVs ('weapon', 'armour', 'garment', 'portable', 'decoration', optionally 'custom')
17694 # ------------------------------------------------------------------------------------------
17695  
17696 if (
17697 $category eq 'weapon' || $category eq 'armour' || $category eq 'garment'
17698 || $category eq 'portable' || $category eq 'decoration' || $category eq 'custom'
17699 ) {
17700 # Is the object listed separately when the user types a look/glance command, or is it
17701 # only apparent that the object exists from a description of something else? (Group 3
17702 # IV for living beings)
17703 # Flag set to TRUE if the object is listed separately, FALSE if not
17704 $self->{explicitFlag} = TRUE;
17705  
17706 # Object's weight (if known)
17707 $self->{weight} = undef;
17708 # Character's stat bonuses or penalties when using this object
17709 $self->{bonusHash} = {};
17710  
17711 # Condition of the object (a number in the range 0-100; 'undef' if unknown, or if not
17712 # used in this world)
17713 $self->{condition} = undef;
17714 # The Condition task uses this flag to help it set an object's current condition
17715 $self->{conditionChangeFlag}
17716 = FALSE;
17717 # Flag set to TRUE if this object is fixable/repairable), FALSE if not (or if unknown)
17718 $self->{fixableFlag} = FALSE;
17719  
17720 # Flag set to TRUE if sellable, FALSE if not (or if unknown). This flag tells you
17721 # whether this particular object can be sold; $self->saleableFlag, a group 1 IV, tells
17722 # you whether objects of this ->category can be sold, or not)
17723 $self->{sellableFlag} = FALSE;
17724 # The highest value of the object that's been noticed when buying it ('undef' if value
17725 # unknown)
17726 $self->{buyValue} = undef;
17727 # The highest value of the object that's been noticed when selling it ('undef' if value
17728 # unknown)
17729 $self->{sellValue} = undef;
17730  
17731 # Flag set to TRUE if this object can only be used by certain guilds, races or indeed
17732 # characters
17733 $self->{exclusiveFlag} = FALSE;
17734 # A hash of guilds, races, named chars etc allowed to use this object. Hash in the form
17735 # ->exclusionHash{profile_name) = undef
17736 $self->{exclusiveHash} = {};
17737 }
17738  
17739 # The generic model object is never actually blessed into existence
17740 return $self;
17741 }
17742  
17743 ##################
17744 # Methods
17745  
17746 ##################
17747 # Accessors - set
17748  
17749 ##################
17750 # Accessors - get
17751  
17752 # Group 1 IVs (all objects)
17753 sub name
17754 { $_[0]->{name} }
17755 sub category
17756 { $_[0]->{category} }
17757 sub modelFlag
17758 { $_[0]->{modelFlag} }
17759 sub number
17760 { $_[0]->{number} }
17761 sub parent
17762 { $_[0]->{parent} }
17763 sub childHash
17764 { my $self = shift; return %{$self->{childHash}}; }
17765  
17766 sub concreteFlag
17767 { $_[0]->{concreteFlag} }
17768 sub aliveFlag
17769 { $_[0]->{aliveFlag} }
17770 sub sentientFlag
17771 { $_[0]->{sentientFlag} }
17772 sub portableFlag
17773 { $_[0]->{portableFlag} }
17774 sub saleableFlag
17775 { $_[0]->{saleableFlag} }
17776  
17777 sub privateHash
17778 { my $self = shift; return %{$self->{privateHash}}; }
17779  
17780 sub sourceCodePath
17781 { $_[0]->{sourceCodePath} }
17782 sub notesList
17783 { my $self = shift; return @{$self->{notesList}}; }
17784  
17785 # Group 2 IVs (all objects except 'region' and 'room')
17786 sub noun
17787 { $_[0]->{noun} }
17788 sub nounTag
17789 { $_[0]->{nounTag} }
17790 sub otherNounList
17791 { my $self = shift; return @{$self->{otherNounList}}; }
17792 sub adjList
17793 { my $self = shift; return @{$self->{adjList}}; }
17794 sub pseudoAdjList
17795 { my $self = shift; return @{$self->{pseudoAdjList}}; }
17796 sub rootAdjList
17797 { my $self = shift; return @{$self->{rootAdjList}}; }
17798 sub unknownWordList
17799 { my $self = shift; return @{$self->{unknownWordList}}; }
17800 sub multiple
17801 { $_[0]->{multiple} }
17802 sub baseString
17803 { $_[0]->{baseString} }
17804 sub descrip
17805 { $_[0]->{descrip} }
17806  
17807 sub container
17808 { $_[0]->{container} }
17809 sub inventoryType
17810 { $_[0]->{inventoryType} }
17811  
17812 # Group 3 IVs ('character', 'minion', 'sentient', 'creature' and optionally 'custom')
17813 sub targetStatus
17814 { $_[0]->{targetStatus} }
17815 sub targetType
17816 { $_[0]->{targetType} }
17817 sub targetPath
17818 { $_[0]->{targetPath} }
17819 sub targetRoomNum
17820 { $_[0]->{targetRoomNum} }
17821  
17822 sub explicitFlag
17823 { $_[0]->{explicitFlag} } # Also a group 4 IV
17824  
17825 sub alreadyAttackedFlag
17826 { $_[0]->{alreadyAttackedFlag} }
17827  
17828 # Group 4 IVs ('weapon', 'armour', 'garment', 'portable', 'decoration', optionally 'custom')
17829 # sub explicitFlag
17830 # { $_[0]->{explicitFlag} } # Also a group 3 IV
17831 sub weight
17832 { $_[0]->{weight} }
17833 sub bonusHash
17834 { my $self = shift; return %{$self->{bonusHash}}; }
17835  
17836 sub condition
17837 { $_[0]->{condition} }
17838 sub conditionChangeFlag
17839 { $_[0]->{conditionChangeFlag} }
17840 sub fixableFlag
17841 { $_[0]->{fixableFlag} }
17842  
17843 sub sellableFlag
17844 { $_[0]->{sellableFlag} }
17845 sub buyValue
17846 { $_[0]->{buyValue} }
17847 sub sellValue
17848 { $_[0]->{sellValue} }
17849  
17850 sub exclusiveFlag
17851 { $_[0]->{exclusiveFlag} }
17852 sub exclusiveHash
17853 { my $self = shift; return %{$self->{exclusiveHash}}; }
17854 }
17855  
17856 { package Games::Axmud::Generic::OtherWin;
17857  
17858 use strict;
17859 use warnings;
17860 # use diagnostics;
17861  
17862 use Glib qw(TRUE FALSE);
17863  
17864 our @ISA = qw(
17865 Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud
17866 );
17867  
17868 ##################
17869 # Constructors
17870  
17871 sub new {
17872  
17873 # Called by GA::Generic::Win->createFreeWin
17874 # Creates a new instance of an 'other' window (most window objects inheriting from this
17875 # generic object share the same ->new function, with only standard IVs)
17876 #
17877 # Expected arguments
17878 # $number - Unique number for this window object
17879 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
17880 # should be created
17881 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
17882 # 'free' window object. When this window opens/closes, the owner is
17883 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
17884 # functions
17885 #
17886 # Optional arguments
17887 # $session - The GA::Session from which this function was called. 'undef' if the
17888 # calling function didn't specify a session and $owner's ->session IV
17889 # is also 'undef'
17890 # $title - Ignored if set (all 'other' windows define their own title)
17891 # $editObj - Ignored if set
17892 # $tempFlag - Ignored if set
17893 # %configHash - Hash containing any number of key-value pairs needed for this
17894 # particular 'other' window; set to an empty hash if not required
17895 # - This type of window object recognises these initialisation settings:
17896 #
17897 # ...
17898 #
17899 # Return values
17900 # 'undef' on improper arguments
17901 # Blessed reference to the newly-created object on success
17902  
17903 my (
17904 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
17905 %configHash,
17906 ) = @_;
17907  
17908 # Check for improper arguments
17909 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
17910  
17911 return $axmud::CLIENT->writeImproper($class . '->new', @_);
17912 }
17913  
17914 # Setup
17915 my $self = {
17916 _objName => 'other_win_' . $number,
17917 _objClass => $class,
17918 _parentFile => undef, # No parent file object
17919 _parentWorld => undef, # No parent file object
17920 _privFlag => TRUE, # All IVs are private
17921  
17922 # Standard window object IVs
17923 # --------------------------
17924  
17925 # Unique number for this window object
17926 number => $number,
17927 # The window category - 'grid' or 'free'
17928 winCategory => 'free',
17929 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
17930 winType => 'other',
17931 # A name for the window (can be unique to this type of window object, or can be the
17932 # same as ->winType)
17933 winName => 'other',
17934 # The GA::Obj::Workspace object for the workspace in which this window is created
17935 workspaceObj => $workspaceObj,
17936 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
17937 # object. When this window opens/closes, the owner is informed via calls to its
17938 # ->add_childFreeWin / ->del_childFreeWin functions
17939 owner => $owner,
17940 # The GA::Session from which this function was called. 'undef' if the calling function
17941 # didn't specify a session and $owner's ->session IV is also 'undef'
17942 session => $session,
17943 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
17944 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
17945 # displayed in a 'dialogue' window)
17946 pseudoCmdMode => 'win_error',
17947  
17948 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
17949 # parent 'main' window's Gtk3::Window
17950 # The code should use this IV when it wants to do something to the window itself
17951 # (minimise it, make it active, etc)
17952 winWidget => undef,
17953 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
17954 # the parent GA::Table::PseudoWin table object
17955 # The code should use this IV when it wants to add, modify or remove widgets inside the
17956 # window itself
17957 winBox => undef,
17958 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
17959 # FALSE if not
17960 enabledFlag => FALSE,
17961 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
17962 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
17963 visibleFlag => TRUE,
17964 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
17965 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
17966 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
17967 childFreeWinHash => {},
17968 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
17969 # window is informed via a call to $self->del_childFreeWin
17970 # When the child is destroyed, this window might want to call some of its own functions
17971 # to update various widgets and/or IVs, in which case this window adds an entry to
17972 # this hash; a hash in the form
17973 # $childDestroyHash{unique_number} = list_reference
17974 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
17975 # reference to a list in groups of 2, in the form
17976 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
17977 childDestroyHash => {},
17978  
17979 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
17980 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
17981 # area)
17982 packingBox => undef,
17983  
17984 # Standard IVs for 'free' windows
17985  
17986 # The window's default size, in pixels
17987 widthPixels => $axmud::CLIENT->customFreeWinWidth,
17988 heightPixels => $axmud::CLIENT->customFreeWinHeight,
17989 # Default border/item spacing sizes used in the window, in pixels
17990 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
17991 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
17992  
17993 # A string to use as the window title
17994 title => $axmud::SCRIPT . ' window',
17995 # Hash containing any number of key-value pairs needed for this particular 'config'
17996 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
17997 # name and type. Set to an empty hash if not required
17998 configHash => {%configHash},
17999 };
18000  
18001 # Bless the object into existence
18002 bless $self, $class;
18003  
18004 return $self;
18005 }
18006  
18007 # Standard window object functions
18008  
18009 # sub winSetup {} # Inherited from GA::Generic::FreeWin
18010  
18011 # sub winEnable {} # Inherited from GA::Generic::FreeWin
18012  
18013 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
18014  
18015 # sub winDestroy {} # Inherited from GA::Generic::FreeWin
18016  
18017 # sub winShowAll {} # Inherited from GA::Generic::Win
18018  
18019 # sub drawWidgets {} # Inherited from GA::Generic::Win
18020  
18021 # sub redrawWidgets {} # Inherited from GA::Generic::Win
18022  
18023 # ->signal_connects
18024  
18025 # Other functions
18026  
18027 ##################
18028 # Methods
18029  
18030 ##################
18031 # Accessors - set
18032  
18033 ##################
18034 # Accessors - get
18035 }
18036  
18037 { package Games::Axmud::Generic::Plugin::Cmd;
18038  
18039 # NB Plugin client commands can have the same name as existing client commands. When the
18040 # plugin is loaded, the existing command is replaced for as long as the plugin is enabled.
18041  
18042 use strict;
18043 use warnings;
18044 # use diagnostics;
18045  
18046 use Glib qw(TRUE FALSE);
18047  
18048 our @ISA = qw(Games::Axmud::Generic::Cmd Games::Axmud);
18049  
18050 ##################
18051 # Constructors
18052  
18053 ##################
18054 # Methods
18055  
18056 ##################
18057 # Accessors - set
18058  
18059 ##################
18060 # Accessors - get
18061 }
18062  
18063 { package Games::Axmud::Generic::Profile;
18064  
18065 use strict;
18066 use warnings;
18067 # use diagnostics;
18068  
18069 use Glib qw(TRUE FALSE);
18070  
18071 our @ISA = qw(Games::Axmud);
18072  
18073 ##################
18074 # Constructors
18075  
18076 ##################
18077 # Methods
18078  
18079 sub cloneInitTaskList {
18080  
18081 # Called by $self->clone immediately after cloning this profile from another
18082 # Clones task objects in the original profile's initial tasklist
18083 #
18084 # Expected arguments
18085 # $original - The original profile object, from which this object was cloned
18086 #
18087 # Return values
18088 # 'undef' on improper arguments
18089 # 1 otherwise
18090  
18091 my ($self, $original, $check) = @_;
18092  
18093 # Local variables
18094 my (
18095 @taskList,
18096 %taskHash,
18097 );
18098  
18099 # Check for improper arguments
18100 if (! defined $original || defined $check) {
18101  
18102 return $axmud::CLIENT->writeImproper($self->_objClass . '->new', @_);
18103 }
18104  
18105 # Import the original profile's initial tasklist
18106 foreach my $name ($original->initTaskOrderList) {
18107  
18108 my ($oldObj, $newObj);
18109  
18110 $oldObj = $original->ivShow('initTaskHash', $name);
18111 $newObj = $oldObj->clone('initial', $self->name, $self->category);
18112 if ($newObj) {
18113  
18114 push (@taskList, $newObj);
18115 $taskHash{$newObj->uniqueName} = $newObj;
18116 }
18117 }
18118  
18119 # Update IVs
18120 if (@taskList) {
18121  
18122 $self->ivPoke('initTaskHash', %taskHash);
18123 $self->ivPoke('initTaskOrderList', @taskList);
18124 }
18125  
18126 return 1;
18127 }
18128  
18129 ##################
18130 # Accessors - set
18131  
18132 ##################
18133 # Accessors - get
18134  
18135 sub name
18136 { $_[0]->{name} }
18137 sub category
18138 { $_[0]->{category} }
18139 sub parentWorld
18140 { $_[0]->{parentWorld} }
18141  
18142 sub initTaskHash
18143 { my $self = shift; return %{$self->{initTaskHash}}; }
18144 sub initTaskOrderList
18145 { my $self = shift; return @{$self->{initTaskOrderList}}; }
18146 sub initTaskTotal
18147 { $_[0]->{initTaskTotal} }
18148 sub initScriptHash
18149 { my $self = shift; return %{$self->{initScriptHash}}; }
18150 sub initScriptOrderList
18151 { my $self = shift; return @{$self->{initScriptOrderList}}; }
18152 sub initMission
18153 { $_[0]->{initMission} }
18154 sub initCmdList
18155 { my $self = shift; return @{$self->{initCmdList}}; }
18156  
18157 sub setupCompleteFlag
18158 { $_[0]->{setupCompleteFlag} }
18159 sub notepadList
18160 { my $self = shift; return @{$self->{notepadList}}; }
18161 sub privateHash
18162 { my $self = shift; return %{$self->{privateHash}}; }
18163 }
18164  
18165 { package Games::Axmud::Generic::Strip;
18166  
18167 use strict;
18168 use warnings;
18169 # use diagnostics;
18170  
18171 use Glib qw(TRUE FALSE);
18172  
18173 our @ISA = qw(Games::Axmud);
18174  
18175 ##################
18176 # Constructors
18177  
18178 sub new {
18179  
18180 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
18181 # Generic function to create this strip object (most objects inheriting from this one will
18182 # use their own ->new function)
18183 #
18184 # Expected arguments
18185 # $number - The strip object's number within the parent window (matches
18186 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
18187 # created to access its default IVs)
18188 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
18189 # objects
18190 #
18191 # Optional arguments
18192 # %initHash - A hash containing arbitrary data to use as the strip object's
18193 # initialisation settings. The strip object should use default
18194 # initialisation settings unless it can succesfully interpret one or more
18195 # of the key-value pairs in the hash, if there are any
18196 # - This type of strip object recognises these initialisation settings:
18197 #
18198 # 'some_string' - 'some_value'
18199 # 'some_string_2' - 'some_value'
18200 # ... - ...
18201 #
18202 # Return values
18203 # 'undef' on improper arguments
18204 # Blessed reference to the newly-created object on success
18205  
18206 my ($class, $number, $winObj, %initHash) = @_;
18207  
18208 # Local variables
18209 my %modHash;
18210  
18211 # Check for improper arguments
18212 if (! defined $class || ! defined $number || ! defined $winObj) {
18213  
18214 return $axmud::CLIENT->writeImproper($class . '->new', @_);
18215 }
18216  
18217 # # Default initialisation settings
18218 # %modHash = (
18219 # 'some_string' => 'some_value',
18220 # 'some_string_2' => 'some_value',
18221 # );
18222 #
18223 # # Interpret the initialisation settings in %initHash, if any
18224 # foreach my $key (keys %modHash) {
18225 #
18226 # if (exists $initHash{$key}) {
18227 #
18228 # if ($key eq 'some_flag_set_to_TRUE_or_FALSE') {
18229 #
18230 # if ($initHash{$key}) {
18231 # $modHash{$key} = TRUE;
18232 # } else {
18233 # $modHash{$key} = FALSE;
18234 # }
18235 #
18236 # } else {
18237 #
18238 # $modHash{$key} = $initHash{$key};
18239 # }
18240 # }
18241 # }
18242  
18243 # Setup
18244 my $self = {
18245 _objName => 'strip_' . $number,
18246 _objClass => $class,
18247 _parentFile => undef, # No parent file object
18248 _parentWorld => undef, # No parent file object
18249 _privFlag => TRUE, # All IVs are private
18250  
18251 # Standard strip object IVs
18252 # -------------------------
18253  
18254 # The strip object's number within the parent window (matches
18255 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
18256 # its default IVs)
18257 number => $number,
18258 # The type of strip object (custom strip objects should use a ->type starting with
18259 # 'custom_' to avoid clashing with future built-in strip objects)
18260 type => 'generic',
18261 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
18262 winObj => $winObj,
18263  
18264 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
18265 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
18266 # still exists in GA::Win::Internal->stripHash, etc)
18267 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which
18268 # might have gauges to draw, or not, depending on current conditions. (Most strip
18269 # objects have this flag set to TRUE all the time)
18270 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
18271 # called by this object's functions
18272 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
18273 # the flag's value shouldn't be modified by anything other than
18274 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
18275 # $self->set_visibleFlag)
18276 visibleFlag => TRUE,
18277 # Flag set to TRUE is the strip object should be given its share of any extra space
18278 # within the packing box (the extra space is divided equally between all children of
18279 # the box whose ->expandFlag is TRUE)
18280 expandFlag => FALSE,
18281 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
18282 # actually allocated within the strip object, FALSE if it is used as padding outside
18283 # it (on both sides)
18284 fillFlag => FALSE,
18285 # Flag set to TRUE if the strip object should be packed into its window with a small
18286 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
18287 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
18288 # for example in the toolbar strip object)
18289 spacingFlag => TRUE,
18290 # Flag set to TRUE if only one instance of this strip object should be added to the
18291 # parent window, set to FALSE if any number of instances can be added
18292 jealousyFlag => TRUE,
18293 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
18294 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
18295 # users)
18296 blindFlag => FALSE,
18297 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
18298 # allowed to accept the focus, FALSE if not. The restriction is applied during the
18299 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
18300 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
18301 # GA::Strip::MenuBar)
18302 allowFocusFlag => FALSE,
18303  
18304 # Initialisation settings stored as a hash (see the comments above)
18305 initHash => \%modHash,
18306 # Reference to a function to call when some widget is used. This IV is set only when
18307 # required by this type of strip object. It can be set by a call to
18308 # $self->set_func() or by some setting in $self->initHash, which is applied in the
18309 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
18310 # generic object function Games::Axmud->getMethodRef()
18311 funcRef => undef,
18312 # A value passed to ->funcRef when it is called which identifies this strip object and
18313 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
18314 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
18315 # to $self->objEnable()
18316 funcID => undef,
18317  
18318 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
18319 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
18320 packingBox => undef,
18321  
18322 # Other IVs
18323 # ---------
18324  
18325 # Widgets
18326 # button => undef, # Gtk3::Button
18327  
18328 # Everything else
18329  
18330 # ...
18331 };
18332  
18333 # Bless the object into existence
18334 bless $self, $class;
18335  
18336 return $self;
18337 }
18338  
18339 ##################
18340 # Methods
18341  
18342 # Standard strip object functions
18343  
18344 sub objEnable {
18345  
18346 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
18347 # Generic function for setting up the strip object's widgets (which isn't actually called by
18348 # anything)
18349 # Copy this function into your own strip object code and add your own widgets
18350 #
18351 # Expected arguments
18352 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
18353 # parent window
18354 #
18355 # Return values
18356 # 'undef' on improper arguments
18357 # 1 on success
18358  
18359 my ($self, $winmapObj, $check) = @_;
18360  
18361 # Check for improper arguments
18362 if (! defined $winmapObj || defined $check) {
18363  
18364 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
18365 }
18366  
18367 # Create a Gtk3::VBox (or a Gtk3::HBox) to contain one or more Gtk3 widgets
18368 my $packingBox = Gtk3::VBox->new(FALSE, 0);
18369 $packingBox->set_border_width(0);
18370  
18371 # Add a widget
18372 # my $button = Gtk3::Button->new($name);
18373 # $packingBox->pack_start($button, FALSE, FALSE, 0);
18374  
18375 # Update IVs
18376 $self->ivPoke('packingBox', $packingBox);
18377 # $self->ivPoke('button', $button); # Optional
18378  
18379 return 1;
18380 }
18381  
18382 sub objDestroy {
18383  
18384 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
18385 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
18386 # to do any necessary tidying up
18387 # Generic function that can be inherited by any strip object that doesn't need to do any
18388 # tidying up
18389 #
18390 # Expected arguments
18391 # (none besides $self)
18392 #
18393 # Return values
18394 # 'undef' on improper arguments
18395 # 1 otherwise
18396  
18397 my ($self, $check) = @_;
18398  
18399 # Check for improper arguments
18400 if (defined $check) {
18401  
18402 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
18403 }
18404  
18405 # (No tidying up required for this type of strip object)
18406  
18407 return 1;
18408 }
18409  
18410 sub setWidgetsIfSession {
18411  
18412 # Called by GA::Win::Internal->setWidgetsIfSession
18413 # Allows this strip object to sensitise or desensitise its widgets, depending on whether
18414 # the parent window has a ->visibleSession at the moment
18415 # (NB Only 'main' windows have a ->visibleSession; for other 'grid' windows, the flag
18416 # argument will be FALSE)
18417 #
18418 # Expected arguments
18419 # $flag - TRUE if the parent window has a visible session, FALSE if not
18420 #
18421 # Return values
18422 # 'undef' on improper arguments
18423 # 1 otherwise
18424  
18425 my ($self, $flag, $check) = @_;
18426  
18427 # Check for improper arguments
18428 if (! defined $flag || defined $check) {
18429  
18430 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
18431 }
18432  
18433 # (nothing to do for this strip object)
18434  
18435 return 1;
18436 }
18437  
18438 sub setWidgetsChangeSession {
18439  
18440 # Called by GA::Win::Internal->setWidgetsChangeSession
18441 # Allows this strip object to update its widgets whenever the visible session in any 'main'
18442 # window changes
18443 #
18444 # Expected arguments
18445 # (none besides $self)
18446 #
18447 # Return values
18448 # 'undef' on improper arguments
18449 # 1 otherwise
18450  
18451 my ($self, $check) = @_;
18452  
18453 # Check for improper arguments
18454 if (defined $check) {
18455  
18456 return $axmud::CLIENT->writeImproper(
18457 $self->_objClass . '->setWidgetsChangeSession',
18458 @_,
18459 );
18460 }
18461  
18462 # (nothing to do for this strip object)
18463  
18464 return 1;
18465 }
18466  
18467 # ->signal_connects
18468  
18469 # Other functions
18470  
18471 ##################
18472 # Accessors - set
18473  
18474 sub notify_addStripObj {
18475  
18476 # Called by GA::Win::Internal->drawWidgets and ->addStripObj whenever a strip object is
18477 # added to the window
18478  
18479 my ($self, $stripObj, $check) = @_;
18480  
18481 # Check for improper arguments
18482 if (! defined $stripObj || defined $check) {
18483  
18484 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addStripObj', @_);
18485 }
18486  
18487 # (This generic function does nothing with the notification)
18488  
18489 return 1;
18490 }
18491  
18492 sub notify_removeStripObj {
18493  
18494 # Called by GA::Win::Internal->removeStripObj whenever a strip object is removed from the
18495 # window
18496  
18497 my ($self, $stripObj, $check) = @_;
18498  
18499 # Check for improper arguments
18500 if (! defined $stripObj || defined $check) {
18501  
18502 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeStripObj', @_);
18503 }
18504  
18505 # (This generic function does nothing with the notification)
18506  
18507 return 1;
18508 }
18509  
18510 sub notify_addTableObj {
18511  
18512 # Called by GA::Strip::Table->addTableObj whenever a table object is added to the window's
18513 # Gtk3::Grid
18514  
18515 my ($self, $tableObj, $check) = @_;
18516  
18517 # Check for improper arguments
18518 if (! defined $tableObj || defined $check) {
18519  
18520 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addTableObj', @_);
18521 }
18522  
18523 # (This generic function does nothing with the notification)
18524  
18525 return 1;
18526 }
18527  
18528 sub notify_removeTableObj {
18529  
18530 # Called by GA::Strip::Table->removeTableObj whenever a table object is removed from the
18531 # window's Gtk3::Grid
18532  
18533 my ($self, $tableObj, $check) = @_;
18534  
18535 # Check for improper arguments
18536 if (! defined $tableObj || defined $check) {
18537  
18538 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeTableObj', @_);
18539 }
18540  
18541 # (This generic function does nothing with the notification)
18542  
18543 return 1;
18544 }
18545  
18546 sub set_func {
18547  
18548 my ($self, $funcRef, $check) = @_;
18549  
18550 # Check for improper arguments
18551 if (defined $check) {
18552  
18553 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_func', @_);
18554 }
18555  
18556 $self->ivPoke('funcRef', $funcRef);
18557  
18558 return 1;
18559 }
18560  
18561 sub set_id {
18562  
18563 my ($self, $funcID, $check) = @_;
18564  
18565 # Check for improper arguments
18566 if (defined $check) {
18567  
18568 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_id', @_);
18569 }
18570  
18571 $self->ivPoke('funcID', $funcID);
18572  
18573 return 1;
18574 }
18575  
18576 sub set_visibleFlag {
18577  
18578 # Should only be called by GA::Win::Internal->hideStripObj and ->revealStripObj
18579  
18580 my ($self, $flag, $check) = @_;
18581  
18582 # Check for improper arguments
18583 if (! defined $flag || defined $check) {
18584  
18585 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_visibleFlag', @_);
18586 }
18587  
18588 if (! $flag) {
18589 $self->ivPoke('visibleFlag', FALSE);
18590 } else {
18591 $self->ivPoke('visibleFlag', TRUE);
18592 }
18593  
18594 return 1;
18595 }
18596  
18597 ##################
18598 # Accessors - get
18599  
18600 sub number
18601 { $_[0]->{number} }
18602 sub type
18603 { $_[0]->{type} }
18604 sub winObj
18605 { $_[0]->{winObj} }
18606  
18607 sub visibleFlag
18608 { $_[0]->{visibleFlag} }
18609 sub expandFlag
18610 { $_[0]->{expandFlag} }
18611 sub fillFlag
18612 { $_[0]->{fillFlag} }
18613 sub spacingFlag
18614 { $_[0]->{spacingFlag} }
18615 sub jealousyFlag
18616 { $_[0]->{jealousyFlag} }
18617 sub blindFlag
18618 { $_[0]->{blindFlag} }
18619 sub allowFocusFlag
18620 { $_[0]->{allowFocusFlag} }
18621  
18622 sub initHash
18623 { my $self = shift; return %{$self->{initHash}}; }
18624 sub funcRef
18625 { $_[0]->{funcRef} }
18626 sub funcID
18627 { $_[0]->{funcID} }
18628  
18629 sub packingBox
18630 { $_[0]->{packingBox} }
18631 }
18632  
18633 { package Games::Axmud::Generic::Table;
18634  
18635 use strict;
18636 use warnings;
18637 # use diagnostics;
18638  
18639 use Glib qw(TRUE FALSE);
18640  
18641 our @ISA = qw(Games::Axmud);
18642  
18643 ##################
18644 # Constructors
18645  
18646 sub new {
18647  
18648 # Called by GA::Strip::Table->addTableObj
18649 # Generic function for creating table objects (which isn't actually called by anything)
18650 # Copy this function into your own table object code and add your own IVs to $self = {}
18651 #
18652 # Expected arguments
18653 # $number - The table object's number within the parent strip object (matches
18654 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
18655 # created to access its default IVs)
18656 # $name - A name for the table object. Can be any string or, if no name was
18657 # specified in the call to the calling function, $name is the same as
18658 # $number. (No part of the code checks that table object names are unique;
18659 # if two or more table objects share the same ->name, usually the one with
18660 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
18661 # chars)
18662 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary strip
18663 # objects
18664 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
18665 # parent strip object's Gtk3::Grid for use exclusively by this table
18666 # object. 'temp' for temporary strip objects
18667 #
18668 # Optional arguments
18669 # %initHash - A hash containing arbitrary data to use as the table object's
18670 # initialisation settings. The table object should use default
18671 # initialisation settings unless it can succesfully interpret one or more
18672 # of the key-value pairs in the hash, if there are any
18673 # - This type of table object recognises these initialisation settings:
18674 #
18675 # 'some_string' - 'some_value'
18676 # 'some_string_2' - 'some_value'
18677 # ... - ...
18678 #
18679 # Return values
18680 # 'undef' on improper arguments
18681 # Blessed reference to the newly-created object on success
18682  
18683 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
18684  
18685 # Local variables
18686 my %modHash;
18687  
18688 # Check for improper arguments
18689 if (
18690 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
18691 || ! defined $zoneObj
18692 ) {
18693 return $axmud::CLIENT->writeImproper($class . '->new', @_);
18694 }
18695  
18696 # # Default initialisation settings
18697 # %modHash = (
18698 # 'some_string' => 'some_value',
18699 # 'some_string_2' => 'some_value',
18700 # );
18701 #
18702 # # Interpret the initialisation settings in %initHash, if any
18703 # foreach my $key (keys %modHash) {
18704 #
18705 # if (exists $initHash{$key}) {
18706 #
18707 # if ($key eq 'some_flag_set_to_TRUE_or_FALSE') {
18708 #
18709 # if ($initHash{$key}) {
18710 # $modHash{$key} = TRUE;
18711 # } else {
18712 # $modHash{$key} = FALSE;
18713 # }
18714 #
18715 # } else {
18716 #
18717 # $modHash{$key} = $initHash{$key};
18718 # }
18719 # }
18720 # }
18721  
18722 # Setup
18723 my $self = {
18724 _objName => 'table_obj_' . $number,
18725 _objClass => $class,
18726 _parentFile => undef, # No parent file object
18727 _parentWorld => undef, # No parent file object
18728 _privFlag => TRUE, # All IVs are private
18729  
18730 # Standard table object IVs
18731 # -------------------------
18732  
18733 # The table object's number within the parent strip object (matches
18734 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
18735 # access its default IVs)
18736 number => $number,
18737 # A name for the table object. Can be any string or, if no name was specified in the
18738 # call to the calling function, $name is the same as $number. (No part of the code
18739 # checks that table object names are unique; if two or more table objects share the
18740 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
18741 # table objects. Max 16 chars)
18742 name => $name,
18743 # The type of table object (custom table objects should use a ->type starting with
18744 # 'custom_' to avoid clashing with future built-in table objects)
18745 type => 'generic',
18746 # The parent strip object (GA::Strip::Table)
18747 stripObj => $stripObj,
18748 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
18749 # temporary table objects
18750 winObj => $stripObj->winObj,
18751 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
18752 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
18753 # table objects
18754 zoneObj => $zoneObj,
18755  
18756 # Flag set to TRUE if this table object can be deleted from the Gtk3::Grid, once it is
18757 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
18758 # when a connection to a world terminates)
18759 allowRemoveFlag => TRUE,
18760 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
18761 # created. Set to FALSE if it can't be resized
18762 allowResizeFlag => TRUE,
18763 # Initialisation settings stored as a hash (see the comments above)
18764 initHash => \%modHash,
18765 # Reference to a function to call when some widget is used. This IV is set only when
18766 # required by this type of table object. It can be set by a call to
18767 # $self->set_func() or by some setting in $self->initHash, which is applied in the
18768 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
18769 # generic object function Games::Axmud->getMethodRef()
18770 funcRef => undef,
18771 # A value passed to ->funcRef when it is called which identifies this table object and
18772 # its widget(s). Can be any value except 'undef'. It can be set by a call to
18773 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
18774 # to $self->objEnable()
18775 funcID => '',
18776  
18777 # The container widget(s) for this table object
18778 # If a frame title is not required, both IVs are set to the same container widget
18779 # (usually a Gtk3::HBox or Gtk3::VBox)
18780 # If a frame title is required, ->packingBox is set to a Gtk3::Frame, ->packingBox2 is
18781 # set to a different container widget (a Gtk3::HBox, etc). ->packingBox is packed into
18782 # the parent strip object's Gtk3::Grid. ->packingBox2 contains all the other widgets
18783 # for this table object. ->packingBox2 is packed inside ->packingBox
18784 packingBox => undef, # Gtk3::HBox (etc) or Gtk3::Frame
18785 packingBox2 => undef, # Gtk3::HBox (etc)
18786  
18787 # Other IVs
18788 # ---------
18789  
18790 # Widgets
18791 # button => undef, # Gtk3::Button
18792  
18793 # Everything else
18794  
18795 # ...
18796 };
18797  
18798 # Bless the object into existence
18799 bless $self, $class;
18800  
18801 return $self;
18802 }
18803  
18804 ##################
18805 # Methods
18806  
18807 # Standard table object functions
18808  
18809 sub objEnable {
18810  
18811 # Called by GA::Strip::Table->addTableObj
18812 # Generic function for setting up the table object's widgets (which isn't actually called by
18813 # anything)
18814 # Copy this function into your own table object code and add your own widgets
18815 #
18816 # Expected arguments
18817 # (none besides $self)
18818 #
18819 # Return values
18820 # 'undef' on improper arguments
18821 # 1 on success
18822  
18823 my ($self, $check) = @_;
18824  
18825 # Check for improper arguments
18826 if (defined $check) {
18827  
18828 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
18829 }
18830  
18831 # Create a packing box; it is this object which is placed onto the Gtk3::Grid
18832 my $packingBox = Gtk3::VBox->new(FALSE, 0);
18833 $packingBox->set_border_width(0);
18834  
18835 # Add a widget
18836 # my $button = Gtk3::Button->new($name);
18837 # $packingBox->pack_start($button, FALSE, FALSE, 0);
18838  
18839 # Update IVs
18840 $self->ivPoke('packingBox', $packingBox); # Compulsory
18841 # $self->ivPoke('button', $button); # Optional
18842  
18843 return 1;
18844 }
18845  
18846 sub objDestroy {
18847  
18848 # Called by GA::Strip::Table->objDestroy, just before that strip is removed from its
18849 # parent window, to give this object a chance to do any necessary tidying up
18850 # Generic function that can be inherited by any table object that doesn't need to do any
18851 # tidying up
18852 #
18853 # Expected arguments
18854 # (none besides $self)
18855 #
18856 # Return values
18857 # 'undef' on improper arguments
18858 # 1 otherwise
18859  
18860 my ($self, $check) = @_;
18861  
18862 # Check for improper arguments
18863 if (defined $check) {
18864  
18865 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
18866 }
18867  
18868 # (No tidying up required for this type of table object)
18869  
18870 return 1;
18871 }
18872  
18873 sub setWidgetsIfSession {
18874  
18875 # Called by GA::Strip::Table->setWidgetsIfSession
18876 # Allows this table object to sensitise or desensitise its widgets, depending on whether
18877 # the parent window has a ->visibleSession at the moment
18878 # (NB Only 'main' windows have a ->visibleSession; for other 'grid' windows, the flag
18879 # argument will be FALSE)
18880 #
18881 # Expected arguments
18882 # $flag - TRUE if the parent window has a visible session, FALSE if not
18883 #
18884 # Return values
18885 # 'undef' on improper arguments
18886 # 1 otherwise
18887  
18888 my ($self, $flag, $check) = @_;
18889  
18890 # Check for improper arguments
18891 if (! defined $flag || defined $check) {
18892  
18893 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
18894 }
18895  
18896 # (nothing to do for this table object)
18897  
18898 return 1;
18899 }
18900  
18901 sub setWidgetsChangeSession {
18902  
18903 # Called by GA::Strip::Table->setWidgetsChangeSession
18904 # Allows this table object to update its widgets whenever the visible session in any 'main'
18905 # window changes
18906 #
18907 # Expected arguments
18908 # (none besides $self)
18909 #
18910 # Return values
18911 # 'undef' on improper arguments
18912 # 1 otherwise
18913  
18914 my ($self, $check) = @_;
18915  
18916 # Check for improper arguments
18917 if (defined $check) {
18918  
18919 return $axmud::CLIENT->writeImproper(
18920 $self->_objClass . '->setWidgetsChangeSession',
18921 @_,
18922 );
18923 }
18924  
18925 # (nothing to do for this table object)
18926  
18927 return 1;
18928 }
18929  
18930 sub setWidgetsOnResize {
18931  
18932 # Called by GA::Strip::Table->resizeTableObj
18933 # Allows this table object to update its widgets whenever the table object is resized on its
18934 # Gtk3::Grid
18935 #
18936 # Expected arguments
18937 # $left, $right, $top, $bottom
18938 # - The coordinates of the top-left ($left, $top) and bottom-right ($right, $bottom)
18939 # corners of the table object on the table after the resize
18940 #
18941 # Return values
18942 # 'undef' on improper arguments
18943 # 1 otherwise
18944  
18945 my ($self, $left, $right, $top, $bottom, $check) = @_;
18946  
18947 # Check for improper arguments
18948 if (
18949 ! defined $left || ! defined $right || ! defined $top || ! defined $bottom
18950 || defined $check
18951 ) {
18952 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsOnResize', @_);
18953 }
18954  
18955 # (nothing to do for this table object)
18956  
18957 return 1;
18958 }
18959  
18960 # ->signal_connects
18961  
18962 # Other functions
18963  
18964 sub setupPackingBoxes {
18965  
18966 # Called by $self->objEnable
18967 # If a frame title is required, we need two packing boxes, rather than the usual one. The
18968 # Gtk3::Frame (stored in $self->packingBox) is added to the parent strip object's
18969 # Gtk3::Grid, but this object's widgets are packed into the usual container widget
18970 # (stored in $self->packingBox2)
18971 # If a frame title is not required, $self->packingBox and ->packingBox2 refer to the same
18972 # widget - the one passed to this function as an argument
18973 #
18974 # Expected arguments
18975 # $container - The container widget created by the calling function (usually a
18976 # Gtk3::HBox or Gtk3::VBox)
18977 #
18978 # Return values
18979 # An empty list on improper arguments
18980 # Otherwise, returns a list in the form
18981 # (packingBox, packingBox2)
18982  
18983 my ($self, $container, $check) = @_;
18984  
18985 # Local variables
18986 my (
18987 $packingBox, $packingBox2,
18988 @emptyList,
18989 );
18990  
18991 # Check for improper arguments
18992 if (! defined $container || defined $check) {
18993  
18994 $axmud::CLIENT->writeImproper($self->_objClass . '->setupPackingBoxes', @_);
18995 return @emptyList;
18996 }
18997  
18998 if ($self->ivShow('initHash', 'frame_title')) {
18999  
19000 $packingBox = Gtk3::Frame->new($self->ivShow('initHash', 'frame_title'));
19001 $packingBox->set_border_width(0);
19002  
19003 $packingBox2 = $container;
19004 $packingBox->add($packingBox2);
19005  
19006 } else {
19007  
19008 $packingBox = $packingBox2 = $container;
19009 }
19010  
19011 return ($packingBox, $packingBox2);
19012 }
19013  
19014 sub testFlag {
19015  
19016 # Can be called by anything
19017 # Convert any boolean value into a literal Glib TRUE or FALSE. If no value is specified,
19018 # uses the specified default value. If neither a value nor a default value are
19019 # specified, returns FALSE
19020 #
19021 # Expected arguments
19022 # (none besides $self)
19023 #
19024 # Optional arguments
19025 # $flag - Any boolean value; 'undef' is treated as FALSE
19026 # $defaultFlag - The default value to use, should be either a literal Glib TRUE or
19027 # FALSE, or 'undef'
19028 #
19029 # Return values
19030 # TRUE or FALSE
19031  
19032 my ($self, $flag, $defaultFlag, $check) = @_;
19033  
19034 # Check for improper arguments
19035 if (defined $check) {
19036  
19037 $axmud::CLIENT->writeImproper($self->_objClass . '->testFlag', @_);
19038 return FALSE;
19039 }
19040  
19041 if (! defined $flag) {
19042  
19043 $flag = $defaultFlag;
19044 }
19045  
19046 if (! $flag) {
19047 return FALSE;
19048 } else {
19049 return TRUE;
19050 }
19051 }
19052  
19053 sub testJustify {
19054  
19055 # Can be called by anything
19056 # Converts a value into a Gtk3::Justification. The specified value is case-insensitive.
19057 # If no value is specified, converts the specified default value. If neither a value
19058 # nor a default value are specified, returns 'GTK_JUSTIFY_LEFT'. If the value (or default
19059 # value, if required) is not valid, returns 'GTK_JUSTIFY_LEFT'
19060 #
19061 # The conversion table is:
19062 # 'left', 'GTK_JUSTIFY_LEFT' > 'GTK_JUSTIFY_LEFT'
19063 # 'right', 'GTK_JUSTIFY_RIGHT' > 'GTK_JUSTIFY_RIGHT'
19064 # 'centre', 'center', 'GTK_JUSTIFY_CENTER' > 'GTK_JUSTIFY_CENTER'
19065 # 'fill', 'GTK_JUSTIFY_FILL' > 'GTK_JUSTIFY_FILL'
19066 # <invalid value> > 'GTK_JUSTIFY_LEFT'
19067 #
19068 # Expected arguments
19069 # (none besides $self)
19070 #
19071 # Optional arguments
19072 # $value - One of the values described above, or 'undef'
19073 # $defaultValue - The default value to use, should be either a Gtk3::Justification or
19074 # 'undef'
19075 #
19076 # Return values
19077 # 'undef' on improper arguments
19078 # Otherwise returns a Gtk3::Justification
19079  
19080 my ($self, $value, $defaultValue, $check) = @_;
19081  
19082 # Check for improper arguments
19083 if (defined $check) {
19084  
19085 return $axmud::CLIENT->writeImproper($self->_objClass . '->testJustify', @_);
19086 }
19087  
19088 if (! defined $value) {
19089  
19090 if (! defined $defaultValue) {
19091 return 'GTK_JUSTIFY_LEFT';
19092 } else {
19093 $value = $defaultValue;
19094 }
19095 }
19096  
19097 $value = lc($value);
19098  
19099 if ($value eq 'left' || $value eq 'gtk_justify_left') {
19100 return 'GTK_JUSTIFY_LEFT';
19101 } elsif ($value eq 'right' || $value eq 'gtk_justify_right') {
19102 return 'GTK_JUSTIFY_RIGHT';
19103 } elsif ($value eq 'centre' || $value eq 'center' || $value eq 'gtk_justify_center') {
19104 return 'GTK_JUSTIFY_CENTER';
19105 } elsif ($value eq 'fill' || $value eq 'gtk_justify_fill') {
19106 return 'GTK_JUSTIFY_FILL';
19107 } else {
19108 return 'GTK_JUSTIFY_LEFT';
19109 }
19110 }
19111  
19112 sub testAlign {
19113  
19114 # Can be called by anything
19115 # Converts a value into an alignment used by several Gtk3 widgets, a fractional value in the
19116 # range 0-1. If no value is specified, converts the specified default value. If neither a
19117 # value nor a default value are specified, returns 0. If the value (or default value, if
19118 # required) is not valid, returns 0
19119 #
19120 # Expected arguments
19121 # (none besides $self)
19122 #
19123 # Optional arguments
19124 # $value - One of the values described above, or 'undef'
19125 # $defaultVAlue - The default value to use, should be a fractional number in the range
19126 # 0-1 or 'undef'
19127 #
19128 # Return values
19129 # 'undef' on improper arguments
19130 # Otherwise returns a value in the range 0-1
19131  
19132 my ($self, $value, $defaultValue, $check) = @_;
19133  
19134 # Check for improper arguments
19135 if (defined $check) {
19136  
19137 return $axmud::CLIENT->writeImproper($self->_objClass . '->testJustify', @_);
19138 }
19139  
19140 if (! defined $value) {
19141  
19142 if (! defined $defaultValue) {
19143 return 0;
19144 } else {
19145 $value = $defaultValue;
19146 }
19147 }
19148  
19149 if (! $axmud::CLIENT->floatCheck($value, 0, 1)) {
19150 return 0;
19151 } else {
19152 return $value;
19153 }
19154 }
19155  
19156 sub testStock {
19157  
19158 # Can be called by anything
19159 # Checks a Gtk3::Stock like 'gtk-yes' or 'gtk-save' (case-insensitive). If it's valid,
19160 # returns it (converted to all lower-case); if it's not valid, returns 'undef'. If no
19161 # Gtk3::Stock is specified, returns 'undef'
19162 #
19163 # Expected arguments
19164 # (none besides $self)
19165 #
19166 # Optional arguments
19167 # $stock - A Gtk3::Stock, or 'undef'
19168 #
19169 # Return values
19170 # 'undef' on improper arguments, if $stock is invalid or if $stock is 'undef'
19171 # Otherwise returns a Gtk3::Stock
19172  
19173 my ($self, $stock, $check) = @_;
19174  
19175 # Local variables
19176 my @list;
19177  
19178 # Check for improper arguments
19179 if (defined $check) {
19180  
19181 return $axmud::CLIENT->writeImproper($self->_objClass . '->testStock', @_);
19182 }
19183  
19184 if (! defined $stock) {
19185  
19186 return undef;
19187 }
19188  
19189 @list = Gtk3::Stock->list_ids();
19190 foreach my $item (@list) {
19191  
19192 if (lc($stock) eq $item) {
19193  
19194 return $item;
19195 }
19196 }
19197  
19198 return undef;
19199 }
19200  
19201 sub testInt {
19202  
19203 # Can be called by anything
19204 # Checks that a value is an integer. Optionally checks that the value is some minimum
19205 # value. If the check succeeds, returns the value. If the check fails or no value is
19206 # specified, returns a default value (but returns 'undef' if no default value is
19207 # specified)
19208 #
19209 # Expected arguments
19210 # (none besides $self)
19211 #
19212 # Optional arguments
19213 # $value - A value to check, or 'undef'
19214 # $minValue - The minimum value, or 'undef'
19215 # $defaultValue - The default value, or 'undef'
19216 #
19217 # Return values
19218 # 'undef' on improper arguments or if the check fails and no default value is specified
19219 # Otherwise returns an integer value
19220  
19221 my ($self, $value, $minValue, $defaultValue, $check) = @_;
19222  
19223 # Check for improper arguments
19224 if (defined $check) {
19225  
19226 return $axmud::CLIENT->writeImproper($self->_objClass . '->testInt', @_);
19227 }
19228  
19229 if (
19230 ! defined $value
19231 || ! $axmud::CLIENT->intCheck($value)
19232 || (defined $minValue && $value < $minValue)
19233 ) {
19234 return $defaultValue;
19235  
19236 } else {
19237  
19238 return $value;
19239 }
19240 }
19241  
19242 sub testIconValue {
19243  
19244 # Can be called by anything, but probably called by GA::Table::Entry->objEnable to set the
19245 # Gtk3::Entry icon
19246 # Checks whether some value is an acceptable value, given a specified value type, value
19247 # minimum and/or value maximum
19248 #
19249 # Expected arguments
19250 # (none besides $self)
19251 #
19252 # Optional arguments
19253 # $value - A value to check. If 'undef', no check is carried out
19254 # $type - Set to 'int' (to be acceptable, the value must be an integer), 'odd' (the
19255 # value must be an odd-numbered integer), 'even' (the value must be an
19256 # even-numbered integer), 'float' (the value must be an integer or
19257 # floating point number), 'string' (the value can be anything, even an
19258 # empty string). If 'undef', no check is carried out
19259 # $min, $max - For 'int'/'float', the minimum/maximum values that are acceptable. For
19260 # 'odd'/'even', the minimum/maximum values that are acceptable. For
19261 # 'string', the minimum/maximum length of the string. If either or both
19262 # values are 'undef', then no minimumx and/or maximum applies. This
19263 # function assumes the calling function has checked that $min and $max
19264 # are sane values
19265 #
19266 # Return values
19267 # 'undef' on improper arguments, if $value and/or $type were not specified, if $type was
19268 # not recognised or if the $value is not acceptable
19269 # 1 if $value is acceptable
19270  
19271 my ($self, $value, $type, $min, $max, $check) = @_;
19272  
19273 # Check for improper arguments
19274 if (defined $check) {
19275  
19276 return $axmud::CLIENT->writeImproper($self->_objClass . '->testIconValue', @_);
19277 }
19278  
19279 # Some combinations of argument can't be checked
19280 if (
19281 ! defined $value
19282 || ! defined $type
19283 || (
19284 $type ne 'int' && $type ne 'float' && $type ne 'odd' && $type ne 'even'
19285 && $type ne 'string'
19286 )
19287 ) {
19288 return undef;
19289 }
19290  
19291 # Perform the check
19292 if ($type eq 'int') {
19293  
19294 if (
19295 ! $axmud::CLIENT->intCheck($value)
19296 || (defined $min && $value < $min)
19297 || (defined $max && $value > $max)
19298 ) {
19299 # Invalid value
19300 return undef;
19301  
19302 } else {
19303  
19304 # Valid value
19305 return 1;
19306 }
19307  
19308 } elsif ($type eq 'odd') {
19309  
19310 if (
19311 ! $axmud::CLIENT->intCheck($value)
19312 || (defined $min && $value < $min)
19313 || (defined $max && $value > $max)
19314 # Number is even
19315 || ! ($value % 2)
19316 ) {
19317 # Invalid value
19318 return undef;
19319  
19320 } else {
19321  
19322 # Valid value
19323 return 1;
19324 }
19325  
19326 } elsif ($type eq 'even') {
19327  
19328 if (
19329 ! $axmud::CLIENT->intCheck($value)
19330 || (defined $min && $value < $min)
19331 || (defined $max && $value > $max)
19332 # Number is odd
19333 || ($value % 2)
19334 ) {
19335 # Invalid value
19336 return undef;
19337  
19338 } else {
19339  
19340 # Valid value
19341 return 1;
19342 }
19343  
19344 } elsif ($type eq 'float') {
19345  
19346 if (
19347 ! $axmud::CLIENT->floatCheck($value)
19348 || (defined $min && $value < $min)
19349 || (defined $max && $value > $max)
19350 ) {
19351 # Invalid value
19352 return undef;
19353  
19354 } else {
19355  
19356 # Valid value
19357 return 1;
19358 }
19359  
19360 } elsif ($type eq 'string') {
19361  
19362 if (
19363 (defined $min && length($value) < $min)
19364 || (defined $max && length($value) > $max)
19365 ) {
19366 # Invalid value
19367 return undef;
19368  
19369 } else {
19370  
19371 # Valid value
19372 return 1;
19373 }
19374 }
19375 }
19376  
19377 ##################
19378 # Accessors - set
19379  
19380 sub notify_addTableObj {
19381  
19382 # Called by GA::Strip::Table->addTableObj whenever a table object is added to the window's
19383 # Gtk3::Grid
19384  
19385 my ($self, $tableObj, $check) = @_;
19386  
19387 # Check for improper arguments
19388 if (! defined $tableObj || defined $check) {
19389  
19390 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addTableObj', @_);
19391 }
19392  
19393 # (This generic function does nothing with the notification)
19394  
19395 return 1;
19396 }
19397  
19398 sub notify_removeTableObj {
19399  
19400 # Called by GA::Strip::Table->removeTableObj whenever a table object is removed from the
19401 # window's Gtk3::Grid
19402  
19403 my ($self, $tableObj, $check) = @_;
19404  
19405 # Check for improper arguments
19406 if (! defined $tableObj || defined $check) {
19407  
19408 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeTableObj', @_);
19409 }
19410  
19411 # (This generic function does nothing with the notification)
19412  
19413 return 1;
19414 }
19415  
19416 sub set_allowRemoveFlag {
19417  
19418 # Must only be called by the code which created the table object
19419  
19420 my ($self, $flag, $check) = @_;
19421  
19422 # Check for improper arguments
19423 if (! defined $flag || defined $check) {
19424  
19425 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_allowRemoveFlag', @_);
19426 }
19427  
19428 if ($flag) {
19429 $self->ivPoke('allowRemoveFlag', TRUE);
19430 } else {
19431 $self->ivPoke('allowRemoveFlag', FALSE);
19432 }
19433  
19434 return 1;
19435 }
19436  
19437 sub set_allowResizeFlag {
19438  
19439 # Must only be called by the code which created the table object
19440  
19441 my ($self, $flag, $check) = @_;
19442  
19443 # Check for improper arguments
19444 if (! defined $flag || defined $check) {
19445  
19446 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_allowResizeFlag', @_);
19447 }
19448  
19449 if ($flag) {
19450 $self->ivPoke('allowResizeFlag', TRUE);
19451 } else {
19452 $self->ivPoke('allowResizeFlag', FALSE);
19453 }
19454  
19455 return 1;
19456 }
19457  
19458 sub set_func {
19459  
19460 my ($self, $funcRef, $check) = @_;
19461  
19462 # Check for improper arguments
19463 if (defined $check) {
19464  
19465 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_func', @_);
19466 }
19467  
19468 $self->ivPoke('funcRef', $funcRef);
19469  
19470 return 1;
19471 }
19472  
19473 sub set_frameTitle {
19474  
19475 my ($self, $text, $check) = @_;
19476  
19477 # Check for improper arguments
19478 if (defined $check) {
19479  
19480 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_frameTitle', @_);
19481 }
19482  
19483 if (! defined $text) {
19484  
19485 $text = '';
19486 }
19487  
19488 if ($self->packingBox->isa('Gtk3::Frame')) {
19489  
19490 $self->packingBox->set_label($text);
19491 }
19492  
19493 return 1;
19494 }
19495  
19496 sub set_id {
19497  
19498 my ($self, $funcID, $check) = @_;
19499  
19500 # Check for improper arguments
19501 if (defined $check) {
19502  
19503 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_id', @_);
19504 }
19505  
19506 $self->ivPoke('funcID', $funcID);
19507  
19508 return 1;
19509 }
19510  
19511 sub set_zoneObj {
19512  
19513 my ($self, $zoneObj, $check) = @_;
19514  
19515 # Check for improper arguments
19516 if (defined $check) {
19517  
19518 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_zoneObj', @_);
19519 }
19520  
19521 $self->ivPoke('zoneObj', $zoneObj);
19522  
19523 return 1;
19524 }
19525  
19526 ##################
19527 # Accessors - get
19528  
19529 sub number
19530 { $_[0]->{number} }
19531 sub name
19532 { $_[0]->{name} }
19533 sub type
19534 { $_[0]->{type} }
19535 sub stripObj
19536 { $_[0]->{stripObj} }
19537 sub winObj
19538 { $_[0]->{winObj} }
19539 sub zoneObj
19540 { $_[0]->{zoneObj} }
19541  
19542 sub allowRemoveFlag
19543 { $_[0]->{allowRemoveFlag} }
19544 sub allowResizeFlag
19545 { $_[0]->{allowResizeFlag} }
19546 sub initHash
19547 { my $self = shift; return %{$self->{initHash}}; }
19548 sub funcRef
19549 { $_[0]->{funcRef} }
19550 sub funcID
19551 { $_[0]->{funcID} }
19552  
19553 sub packingBox
19554 { $_[0]->{packingBox} }
19555 sub packingBox2
19556 { $_[0]->{packingBox2} }
19557 }
19558  
19559 { package Games::Axmud::Generic::Task;
19560  
19561 use strict;
19562 use warnings;
19563 # use diagnostics;
19564  
19565 use Glib qw(TRUE FALSE);
19566  
19567 our @ISA = qw(Games::Axmud);
19568  
19569 ##################
19570 # Constructors
19571  
19572 sub new {
19573  
19574 # Prepare a new instance of the generic task (although the generic task is never actually
19575 # blessed into existence)
19576 #
19577 # Expected arguments
19578 # $session - The parent GA::Session (not set as an IV by this function - set by
19579 # $self->updateTaskLists for current tasks)
19580 #
19581 # Optional arguments
19582 # $taskType - Which tasklist this task is being created into - 'current' for the current
19583 # tasklist (tasks which are actually running now), 'initial' (tasks which
19584 # should be run when the user connects to the world), 'custom' (tasks with
19585 # customised initial parameters, which are run when the user demands). If
19586 # set to 'undef', this is a temporary task, created in order to access the
19587 # default values stored in IVs, that will not be added to any tasklist
19588 # $profName - ($taskType = 'current') name of the profile from whose initial tasklist
19589 # this task was created ('undef' if none)
19590 # - ($taskType = 'initial') name of the profile in whose initial tasklist
19591 # this task will be. If 'undef', the global initial tasklist is used
19592 # - ($taskType = 'custom') 'undef'
19593 # $profCategory
19594 # - ($taskType = 'current', 'initial') which category the profile falls undef
19595 # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile)
19596 # - ($taskType = 'custom') 'undef'
19597 # $customName
19598 # - ($taskType = 'current', 'initial') 'undef'
19599 # - ($taskType = 'custom') the custom task name, matching a key in
19600 # GA::Session->customTaskHash
19601 #
19602 # Return values
19603 # 'undef' on improper arguments
19604 # Otherwise returns $self, a hash that will be blessed into existence by the inheriting
19605 # object
19606  
19607 my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_;
19608  
19609 # Check for improper arguments
19610 if (! defined $class || ! defined $session || defined $check) {
19611  
19612 return $axmud::CLIENT->writeImproper($class . '->new', @_);
19613 }
19614  
19615 # For 'initial' tasks, check that the profile $profName exists (for 'current' tasks, if
19616 # $profName is defined, we can safely assume that it already exists)
19617 if (
19618 $taskType
19619 && $taskType eq 'initial'
19620 && defined $profName
19621 && ! $session->ivExists('profHash', $profName)
19622 ) {
19623 return $axmud::CLIENT->writeError(
19624 'Can\'t create new initial task because profile ' . $profName . ' doesn\'t exist',
19625 $class . '->new',
19626 );
19627 }
19628  
19629 # Setup
19630 my $self = {
19631 _objName => 'generic_task',
19632 _objClass => $class,
19633 # Parent file object IVs set by ->setParentFileObj
19634 _parentFile => undef,
19635 _parentWorld => undef,
19636 _privFlag => TRUE, # All IVs are private
19637  
19638 # Perl object components
19639 # ----------------------
19640  
19641 # The parent GA::Session object (for current tasks) - set by $self->updateTaskLists
19642 session => undef,
19643  
19644 # Task settings
19645 # -------------
19646  
19647 # The generic task has 'task settings' (IVs which are used with every kind of task), but
19648 # no 'task parameters' (IVs which are unique to each kind of task)
19649  
19650 # What type of task this is, e.g. 'locator_task', 'attack_bot_task' etc (max 16
19651 # characters, A-Z, a-z, underline, numbers (not on first char), non-Latin alphabets
19652 # acceptable)
19653 name => 'generic_task',
19654  
19655 # Capitalised form of $self->name, used for (e.g.) task window titles (max 32 chars)
19656 prettyName => 'Generic Task',
19657 # Each instance of the generic task is given a unique name, just before being blessed
19658 # into existence (based on ->name, so assumed to be no more than 24 characters)
19659 uniqueName => undef,
19660 # Very short name (probably just two letters) for display in the Status task's
19661 # own window
19662 shortName => 'Gn',
19663 # For custom tasks, the custom task name (matches a key in GA::Client->customTaskHash,
19664 # max 16 chars); set to 'undef' for current and initial tasks
19665 customName => $customName,
19666  
19667 # What category of task, 'process' or 'activity'
19668 category => 'process',
19669 # Description of the task (any length permitted)
19670 descrip => 'A generic task',
19671 # 'current', 'initial' or 'custom' (or 'undef' for a temporary task)
19672 taskType => $taskType,
19673 # ($taskType = 'current') name of the profile from whose initial tasklist this task was
19674 # created ('undef' if none)
19675 # ($taskType = 'initial') name of the profile in whose initial tasklisk this task will
19676 # be
19677 # ($taskType = 'custom') 'undef'
19678 profName => $profName,
19679 # ($taskType = 'initial') the category of the profile with which this initial task is
19680 # associated ('world', 'race', 'guild', 'char', etc)
19681 # ($taskType = 'current', 'initial') which category the profile falls under (i.e.
19682 # 'world', 'race', 'char', etc, or 'undef' if no profile)
19683 # ($taskType = 'custom') 'undef'
19684 profCategory => $profCategory,
19685 # A reference to the GA::Session IV for this task, if there is one (e.g.
19686 # GA::Session->locatorTask for the current Locator task). We need it so that, if the
19687 # task is destroyed with the ';killtask' command, that IV can be set to 'undef'
19688 # Set for all built-in tasks that have their ->jealousyFlag set to TRUE; at the
19689 # moment, that's all built-in tasks except the Frame and Script tasks. In addition,
19690 # only the lead (first) Chat task has its ->shortCutIV set
19691 # For private tasks, usually set to 'undef'; however, if you write a replacement for
19692 # (say) the built-in Attack task, it's possible to set this IV to 'attackTask' - in
19693 # which case, when your private task is running and other parts of the Axmud code
19694 # consult the current Attack task, they'll consult your private task instead
19695 shortCutIV => undef,
19696  
19697 # Whether multiple instances of this task can run concurrently
19698 # FALSE - any number of concurrent instances can run
19699 # TRUE - only one instance can run
19700 # (Activity tasks are almost always jealous. Process tasks are often jealous.)
19701 jealousyFlag => TRUE,
19702 # Whether this task requires the Locator task to be running
19703 # FALSE - this task doesn't need the Locator task
19704 # TRUE - this task can't run without the Locator task (and will shut down if the
19705 # Locator task shuts down)
19706 requireLocatorFlag => TRUE,
19707 # Whether the task should reset itself, if any of the current profiles are changed
19708 # (because many tasks depend on data in current profiles; if they suddenly change,
19709 # the tasks will at best be relying on obsolete data, and at worst could corrupt the
19710 # new current profiles)
19711 # FALSE - this task doesn't care if any of the current profiles are changed
19712 # TRUE - this task must reset itself if any of the current profiles are changed
19713 profSensitivityFlag => TRUE,
19714 # Whether this task can be stored as an initial/custom task
19715 # FALSE - this task isn't storable (can't be started with ';starttask' under normal
19716 # circumstances - e.g. the Advance task, which should be started with
19717 # ';advance', and the Chat task, which should be started with ';listen')
19718 # TRUE - this task is storable (can be used as an initial/custom task)
19719 storableFlag => TRUE,
19720  
19721 # When the task will start/started - matches GA::Session->sessionTime (in seconds)
19722 # [ ->status = 'wait_init' ] the time at which to start
19723 # [ ->status = 'running', 'paused'] the time the task actually started
19724 startTime => 0,
19725 # The next time the task's status should be checked - matches
19726 # GA::Session->sessionTime (in seconds)
19727 # [ Status = 'wait_task_*] the next time to check (usually after 60 seconds)
19728 # [ Status = 'paused'] the time to unpause
19729 checkTime => 0,
19730 # How the task should stop running
19731 # 'unlimited' run indefinitely, using the task's code to decide when to shut down
19732 # 'run_for' run for some time after the task has become active
19733 # 'run_until' run until a certain time
19734 endStatus => 'unlimited',
19735 # When the task should stop running (default value is 0 for 'run forever')
19736 # [ ->status = 'wait_* ][ ->endStatus = 'run_for' ]
19737 # - run for this many minutes
19738 # [ ->status = 'wait_* ][ ->endStatus = 'run_until' ]
19739 # - run until this system time (matches GA::Session->sessionTime, in seconds)
19740 # [ ->status = 'running', 'paused' ][ ->endStatus = 'run_*' ]
19741 # - stop at this system time (matches GA::Session->sessionTime, in seconds)
19742 # [ ->status = 'finished' ]
19743 # - the system time at which the task actually finished (not the time it's due to
19744 # finish) (matches GA::Session->sessionTime, in seconds)
19745 endTime => 0,
19746 # Wait for another task to do something
19747 # [ ->status = 'wait_task_*' ]
19748 # - the task for which to wait - can match either Task->name or Task->uniqueName
19749 waitForTask => undef,
19750 # How often the task loop should call this task, in seconds (e.g. 1, call once a second,
19751 # 0.2, call five times a second)
19752 # If 0, the task is called once per task loop. The task will never be called more
19753 # than once per task loop, so if this IV is set to 0.1 and the task loop is running
19754 # once a second, this task will still only be called once a second
19755 # Set to 0 for all activity tasks
19756 delayTime => 0,
19757  
19758 # Set to TRUE if the task should shut down gracefully, FALSE otherwise
19759 shutdownFlag => FALSE,
19760 # Flag set to TRUE if the task has ever been reset, FALSE if it's never been reset (so
19761 # that functions like $self->doFirstStage and ->doInit don't, for example, try to add
19762 # widgets to a task window that was created by the pre-reset task, and therefore
19763 # already contains widgets)
19764 hasResetFlag => FALSE,
19765 # The task's status
19766 # 'no_exist' task doesn't exist
19767 # 'wait_init' waiting to initialise
19768 # 'wait_task_exist' waiting for a task to exist, before initialising
19769 # 'wait_task_no_exist' waiting for a task to not exist, before initialising
19770 # 'wait_task_start_stop' waiting for a task to exist, and then finish, before
19771 # initialising
19772 # 'running' task is active
19773 # 'paused' task is paused
19774 # 'finished' task is finished
19775 # 'reset' task must be reset
19776 status => 'no_exist',
19777 # The task's resumption status
19778 # [->status = 'paused']
19779 # - when the task resumes, what its status should be (default is 'running')
19780 resumeStatus => undef,
19781 # For some tasks it's useful to have a functionality of running in an 'active' mode
19782 # (actively doing things) or in a 'disactivated' mode (waiting for something to
19783 # happen). This IV provides that functionality.
19784 # If the task is 'active' (or if the functionality isn't needed), the flag is set to
19785 # TRUE, if the task is 'disactivated', the variable is set to FALSE. Tasks that don't
19786 # need to distinguish between 'active' and 'disactivated' should have this flag set
19787 # to TRUE.
19788 activeFlag => TRUE,
19789 # The task stage (which chunk of the task should be performed on the next task loop).
19790 # Should be a number; integers are preferred, but if you use decimals like 1.1 or 1.2,
19791 # don't make the stage longer than 5 characters (i.e. don't use 1.1510)
19792 # [ ->category = 'process']
19793 # - set to 0 until task starts, thereafter any value (usually a number)
19794 # [ ->category = 'activity']
19795 # - always set to 0 (and should be ignored by the task code)
19796 stage => 0,
19797  
19798 # Task windows can take one of three forms: a 'grid' window (separate from the session's
19799 # 'main' window), or a table object inside the session's 'main' window,
19800 # GA::Table::Pane or GA::Table::PseudoWin
19801 # GA::Table::Pane creates a simple pane object inside the session's 'main' window.
19802 # This task interacts with the pane object and its textview(s) mostly by accessing
19803 # $self->defaultTabObj IVs
19804 # GA::Table::PseudoWin creates a pseudo-window - a window object inheriting from
19805 # GA::Generic::GridWin, but which does not open a separate window; instead, the
19806 # pseudo-window's widgets are drawn inside the table object
19807 #
19808 # There are no built-in tasks which use more than one task window. If you write your own
19809 # tasks, the code is free to open additional task windows, and to store those task
19810 # windows in its own IVs
19811 #
19812 # Is the task allowed to open task windows at all?
19813 allowWinFlag => FALSE,
19814 # Is the task required to have a task window open? (TRUE - the task can't run if a task
19815 # window can't be opened and must halt if the window is closed, FALSE - the task can
19816 # run without a task window)
19817 # (Ignored if ->allowWinFlag is FALSE)
19818 requireWinFlag => FALSE,
19819 # Should the task open a task window when it starts? (Ignored if ->allowWinFlag or
19820 # ->requireWinFlag are FALSE)
19821 startWithWinFlag => FALSE,
19822 #
19823 # The comments for the remaining IVs assume the task opens only one task window (if any)
19824 #
19825 # What kind of task window this task prefers to open (see the comments just above) - an
19826 # ordered list of strings, containing any of the following:
19827 # 'grid' - open a 'grid' window
19828 # 'pane' - open a pane object inside the session's 'main' window
19829 # 'entry' - open a pane object using an entry box inside the session's 'main'
19830 # window
19831 # 'pseudo' - opens a pseudo-window inside the session's 'main' window
19832 # When $self->openWin is called, it will act on each item on the list, from first to
19833 # last, until it succeeds in opening a task window (that is to say, if the first item
19834 # is 'win' and the code successfully opens a 'grid' window, it ignores the rest of the
19835 # list)
19836 # If it's an empty list, then of course no task window is opened
19837 winPreferList => [],
19838 # For 'grid' and 'pseudo', the blessed reference of the window object
19839 # (GA::Win::Internal), if one is open; set to 'undef' otherwise
19840 winObj => undef,
19841 # For 'pane', 'entry' and 'pseudo', the blessed reference of the table object inside the
19842 # session's 'main' window; set to 'undef' otherwise
19843 # NB For 'pseudo', both ->winObj and ->tableObj are set
19844 tableObj => undef,
19845 # For all task window types, flag set to TRUE if there is a task window open (i.e.
19846 # either ->winObj or ->tableObj are set), set to FALSE if there is no task window open
19847 # (both ->winObj and ->tableObj are not set)
19848 taskWinFlag => FALSE,
19849 # For all task window types, flag set to TRUE if there is a task window open that's
19850 # using an entry box; set to FALSE otherwise
19851 taskWinEntryFlag => FALSE,
19852 # For 'grid' and 'pseudo', the winmap to use in the window object, if one is open
19853 # (matches a key in GA::Client->winmapHash). If set to 'undef' and a window object is
19854 # created, the 'basic_empty' winmap is used
19855 winmap => undef,
19856 # For all task window types, when the client command ';opentaskwindow' is used to open a
19857 # task window some time after the task has started, a function within the task to call
19858 # which fills the window with strip objects and table objects, or which initialises
19859 # the contents of a pane object, or anything else required (e.g. 'createWidgets',
19860 # which would call $self->createWidgets() - a literal function name, not a reference
19861 # to a function)
19862 # If 'undef', no function is called
19863 winUpdateFunc => undef,
19864 # For all task window types, if the task has created a task window that includes a pane
19865 # object, the tab object (GA::Obj::Tab) corresponding to the first tab in that pane
19866 # object (otherwise set to 'undef')
19867 # Set automatically if the winmap specified by $self->winmap contains a pane object; can
19868 # be set manually otherwise
19869 defaultTabObj => undef,
19870 # For any task window using a pane object, which kind of tab to add to the pane when the
19871 # task window opens - 'simple' to create a simple tab (one with no label), 'multi' to
19872 # create a tab with a label, and 'empty' to create no tabs at first, leaving an empty
19873 # an empty pane
19874 # For task windows that don't use a pane object, this IV is ignored, so the value should
19875 # remain set to 'undef'
19876 # If set to 'multi' or 'empty', simple tabs are never added; the first tab is always a
19877 # normal tab
19878 tabMode => undef,
19879 # For any task window using a pane object, flag set to TRUE if that pane object uses a
19880 # monochrome colour scheme (a specified background colour with a suitable text
19881 # colour), which is set by the task itself (for example, the Status task changes
19882 # colour when the current' characters hit points change)
19883 # Flag set to FALSE if the default colour scheme for 'custom' windows should apply (or
19884 # if there is no pane object at all)
19885 monochromeFlag => FALSE,
19886 # For any task using a pane object, the colour scheme applied is specified thus:
19887 # 1. If the following IV is set, that colour scheme is applied
19888 # 2. Otherwise, if a colour scheme exists with the same name as the task (matching
19889 # $self->name, e.g. 'locator_task', or that name with the '_task' removed, e.g.
19890 # 'locator'), then that colour scheme is applied
19891 # 3. Otherwise, the colour scheme applied is the same as the window's ->winType (for
19892 # all task windows, 'custom')
19893 colourScheme => undef,
19894 # For any task window using a pane object, flag set to TRUE if that pane objecct's
19895 # vertical scroll bar, if any, should remain at the top, leaving the first lines in
19896 # view; set FALSE if it should scroll to the bottom (as normal)
19897 noScrollFlag => FALSE,
19898  
19899 # Flag set to TRUE if this task is capable of doing text-to-speech (TTS), FALSE
19900 # otherwise
19901 ttsFlag => FALSE,
19902 # For tasks that can do TTS, the name of the TTS configuration object to use. If set to
19903 # 'undef', the default configuration for tasks is used
19904 ttsConfig => undef,
19905 # TTS attributes and flag attributes.
19906 # The user can use the client commands ';read', ';switch' and ';alert' to interact with
19907 # individual tasks to customise the way they use TTS
19908 # ';read' is used with TTS attributes, which typically get the task to read out
19909 # information (e.g. the Status task can read out current health points).
19910 # ';switch' is used with TTS flag attributes, which typically tell the task to
19911 # automatically read out information (e.g. the Locator task can be told to read out
19912 # room titles automatically, as they are received; or not)
19913 # ';alert' is used with TTS alert attributes, which typically read out a message when
19914 # some statistic reaches a certain level (e.g. the Status task can be told to read
19915 # out an alert when health points fall below or recover to a certain percentage)
19916 # A hash of all attributes used by built-in tasks is stored in
19917 # GA::Client->constTtsAttribHash, ->constTtsFlagAttribHash and
19918 # ->constTtsAlertAttribHash
19919 # Each GA::Session stores a custom list of attributes, initially set to the same
19920 # values, but modified as any user-written tasks start/stop. If a user-written task
19921 # wants to use an attribute like 'title', the ';read', ';switch' and ';alert' commands
19922 # work with the user-written task, rather than the built-in one. (When the user-
19923 # written task halts, the built-in task's attributes are restored)
19924 # A hash of all TTS (normal) attributes used by this task, in the form
19925 # $ttsAttribHash{attribute} = optional_value_or_undef
19926 # ...where 'attribute' is a string unique to this hash, preferably a single word in all
19927 # lower-case letters
19928 # When the ';read' command calls this task's ->ttsReadAttrib() function, that function
19929 # decides how to respond. If it wants to store a value in this hash, it can do so. If
19930 # it stores a value, it might be a value specified by the ';read' command, or not.
19931 # Otherwise the attribute's corresponding value is 'undef'. The hash should only be
19932 # modified by calls to ->ttsReadAttrib()
19933 ttsAttribHash => {},
19934 # A hash of all TTS flag attributes used by this task, in the form
19935 # $ttsFlagAttribHash{flag_attribute} = TRUE_or_FALSE_value
19936 # ...where 'flag_attribute' is a string unique to this hash, preferably a single word in
19937 # all lower-case letters
19938 # When the ';switch' command calls this task's ->ttsSwitchFlagAttrib() function, that
19939 # function decides how to respond. Almost always, the TRUE or FALSE value stored in
19940 # this hash is toggled, but that's not compulsory. The hash should only be modified
19941 # by calls to ->ttsSwitchFlagAttrib()
19942 ttsFlagAttribHash => {},
19943 # A hash of all TTS alert attributes used by this task, in the form
19944 # $ttsAlertAttribHash{alert_attribute} = optional_value_or_undef
19945 # ...where 'alert_attribute' is a string unique to this hash, preferably a single word
19946 # in all lower-case letters
19947 # When the ';alert' command calls this task's ->ttsSetAlertAttrib() function, that
19948 # function decides how to respond. If it wants to store a value in this hash, it can
19949 # do so. If it stores a value, it might be a value specified by the ';alert' command,
19950 # or not. Otherwise the attribute's corresponding value is 'undef'. The hash should
19951 # only be modified by calls to ->ttsSetAlertAttrib()
19952 ttsAlertAttribHash => {},
19953 };
19954  
19955 # The generic task is never actually blessed into existence
19956 return $self;
19957 }
19958  
19959 sub clone {
19960  
19961 # Create a clone of an existing task
19962 # Usually used upon connection to a world, when every task in the initial tasklists must
19963 # be cloned into a new object, representing a task in the current tasklist
19964 # (Also used when cloning a profile object, since all the tasks in its initial tasklist must
19965 # also be cloned)
19966 #
19967 # Expected arguments
19968 # $session - The parent GA::Session (not stored as an IV)
19969 # $taskType - Which tasklist this task is being created into - 'current' for the current
19970 # tasklist (tasks which are actually running now), 'initial' (tasks which
19971 # should be run when the user connects to the world). Custom tasks aren't
19972 # cloned (at the moment)
19973 #
19974 # Optional arguments
19975 # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the
19976 # existing task is stored
19977 # $profCategory
19978 # - ($taskType = 'initial') which category the profile falls under (i.e.
19979 # 'world', 'race', 'char', etc)
19980 #
19981 # Return values
19982 # 'undef' on improper arguments or if the task can't be cloned
19983 # Blessed reference to the newly-created object on success
19984  
19985 my ($self, $session, $taskType, $profName, $profCategory, $check) = @_;
19986  
19987 # Check for improper arguments
19988 if (
19989 ! defined $session || ! defined $taskType || defined $check
19990 || ($taskType ne 'current' && $taskType ne 'initial')
19991 || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory))
19992 ) {
19993 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
19994 }
19995  
19996 # For initial tasks, check that $profName exists
19997 if (
19998 $taskType eq 'initial'
19999 && defined $profName
20000 && ! $session->ivExists('profHash', $profName)
20001 ) {
20002 return $axmud::CLIENT->writeError(
20003 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist',
20004 $self->_objClass . '->clone',
20005 );
20006 }
20007  
20008 # Check that the task doesn't belong to a disabled plugin (in which case, it can't be
20009 # cloned)
20010 if (! $self->checkPlugins()) {
20011  
20012 return undef;
20013 }
20014  
20015 # Create the new task, using default settings and parameters
20016 my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory);
20017  
20018 # Most of the cloned task's settings have default values, but a few are copied from the
20019 # original
20020 $self->cloneTaskSettings($clone);
20021  
20022 # Give the new (cloned) task the same initial parameters as the original one
20023 # (no parameters to preserve)
20024  
20025 # Cloning complete
20026 return $clone;
20027 }
20028  
20029 ##################
20030 # Methods
20031  
20032 # Constructor support functions
20033  
20034 sub cloneTaskSettings {
20035  
20036 # Called by $self->clone (and nothing else)
20037 # Most task settings are not copied from the original task to a clone (most of the clone's
20038 # task settings continue to have default values), however there are a few task settings
20039 # which must be copied from the clone. This function handles it.
20040 #
20041 # Expected arguments
20042 # $self - The original task
20043 # $clone - The cloned task
20044 #
20045 # Return values
20046 # 'undef' on improper arguments
20047 # 1 on success
20048  
20049 my ($self, $clone, $check) = @_;
20050  
20051 # Check for improper arguments
20052 if (! defined $clone || defined $check) {
20053  
20054 return $axmud::CLIENT->writeImproper($self->_objClass . '->cloneTaskSettings', @_);
20055 }
20056  
20057 $clone->{_objName} = $self->{_objName};
20058 # ->_parentFile / ->_parentWorld has already been set (by ->updateTaskLists)
20059 $clone->{_objClass} = $self->{_objClass};
20060 $clone->{_privFlag} = TRUE, # All IVs are private
20061  
20062 # Text-to-speech (TTS) task settings must be copied from the original, so that settings in
20063 # tasks stored in the global initial tasklist are transferred to a current task, when it
20064 # starts
20065 $clone->{ttsFlag} = $self->ttsFlag;
20066 $clone->{ttsConfig} = $self->ttsConfig;
20067 $clone->{ttsAttribHash} = {$self->ttsAttribHash};
20068 $clone->{ttsFlagAttribHash} = {$self->ttsFlagAttribHash};
20069 $clone->{ttsAlertAttribHash} = {$self->ttsAlertAttribHash};
20070 # Same applies to the IV that sets whether a window is opened, when the task starts (for the
20071 # benefit of tasks which can do either)
20072 $clone->{startWithWinFlag} = $self->startWithWinFlag;
20073 # Same applies to the preferred colour scheme
20074 $clone->{colourScheme} = $self->colourScheme;
20075  
20076 return 1;
20077 }
20078  
20079 sub preserve {
20080  
20081 # Called by $self->main whenever this task is reset, in order to preserve some if its task
20082 # parameters (but not necessarily all of them)
20083 #
20084 # Expected arguments
20085 # $newTask - The new task which has been created, to which some of this task's instance
20086 # variables might have to be transferred
20087 #
20088 # Return values
20089 # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current
20090 # tasklist
20091 # 1 on success
20092  
20093 my ($self, $newTask, $check) = @_;
20094  
20095 # Check for improper arguments
20096 if (! defined $newTask || defined $check) {
20097  
20098 return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_);
20099 }
20100  
20101 # Check the task is in the current tasklist
20102 if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) {
20103  
20104 return $self->writeWarning(
20105 '\'' . $self->uniqueName . '\' task missing from the current tasklist',
20106 $self->_objClass . '->preserve',
20107 );
20108 }
20109  
20110 # Preserve some task parameters (the others are left with their default settings, some of
20111 # which will be re-initialised in stage 2)
20112  
20113 # (no parameters to preserve)
20114  
20115 return 1;
20116 }
20117  
20118 sub checkPlugins {
20119  
20120 # Called by a task's ->new function (but not by the generic task itself))
20121 # Checks that this task wasn't created by a plugin which is currently disabled, or not
20122 # loaded (in which case, the task can't be added to a current, initial or custom tasklist)
20123 #
20124 # Expected arguments
20125 # (none besides $self)
20126 #
20127 # Return values
20128 # 'undef' on improper arguments or if this task was created by a plugin which is
20129 # currently disabled, or not loaded
20130 # 1 otherwise
20131  
20132 my ($self, $check) = @_;
20133  
20134 # Local variables
20135 my ($plugin, $pluginObj);
20136  
20137 # Check for improper arguments
20138 if (defined $check) {
20139  
20140 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPlugins', @_);
20141 }
20142  
20143 # Was this task created by a plugin?
20144 if ($axmud::CLIENT->ivExists('pluginTaskHash', $self->name)) {
20145  
20146 $plugin = $axmud::CLIENT->ivShow('pluginTaskHash', $self->name);
20147 $pluginObj = $axmud::CLIENT->ivShow('pluginHash', $plugin);
20148  
20149 if (! $pluginObj) {
20150  
20151 # This task can't be added to a current, initial or custom tasklist
20152 return $self->error(
20153 'The \'' . $self->name . '\' task was created by a plugin which has not been'
20154 . ' loaded',
20155 );
20156  
20157 } elsif (! $pluginObj->enabledFlag) {
20158  
20159 return $self->error(
20160 'The \'' . $self->name . '\' task was created by a plugin which has been'
20161 . ' disabled',
20162 );
20163 }
20164 }
20165  
20166 # Otherwise, the task can be added to a current, initial or custom tasklist
20167 return 1;
20168 }
20169  
20170 sub setParentFileObj {
20171  
20172 # Called by a task's ->new function (but not by the generic task itself))
20173 # Sets the standard IVs ->_parentFile and ->_parentWorld, if required
20174 #
20175 # Expected arguments
20176 # $session - The calling function's GA::Session
20177 # $taskType - Which tasklist this task is being created into - 'current', 'initial'
20178 # or 'custom'
20179 #
20180 # Optional arguments
20181 # $profName - Name of the profile in whose initial tasklist this task will be (or
20182 # 'undef')
20183 # $profCategory - That profile's category (or 'undef')
20184 #
20185 # Return values
20186 # 'undef' on improper arguments
20187 # 1 otherwise
20188  
20189 my ($self, $session, $taskType, $profName, $profCategory, $check) = @_;
20190  
20191 # Check for improper arguments
20192 if (! defined $session || ! defined $taskType || defined $check) {
20193  
20194 return $axmud::CLIENT->writeImproper($self->_objClass . '->setParentFileObj', @_);
20195 }
20196  
20197 # Initial task in a profile's initial tasklist
20198 if ($taskType eq 'initial' && defined $profName) {
20199  
20200 if ($profCategory eq 'world') {
20201  
20202 $self->{_parentFile} = $profName;
20203  
20204 } else {
20205  
20206 $self->{_parentFile} = 'otherprof';
20207 $self->{_parentWorld} = $session->currentWorld->name;
20208 }
20209  
20210 # Task in the global initial/custom tasklists
20211 } elsif ($taskType eq 'initial' || $taskType eq 'custom') {
20212  
20213 $self->{_parentFile} = 'tasks';
20214 }
20215  
20216 return 1;
20217 }
20218  
20219 sub updateTaskLists {
20220  
20221 # Called by a task's ->new function (but not by the generic task itself))
20222 # Also called by GA::Obj::File->extractData when importing an initial/custom task
20223 #
20224 # Updates the current, global initial, custom or profile initial tasklists with the newly-
20225 # created task, as appropriate. Also sets $self->uniqueName
20226 # NB We use $self->{...} to set the value of IVs, rather than $self->ivPoke(...), to avoid
20227 # setting the ->modifyFlag IV of parent GA::Obj::File (stored in $self->_parentFile)
20228 #
20229 # Expected arguments
20230 # $session - The calling function's GA::Session (set as an IV for current tasks only)
20231 #
20232 # Return values
20233 # 'undef' on improper arguments or if we try to add a non-storable task to an initial or
20234 # custom tasklist
20235 # 1 otherwise
20236  
20237 my ($self, $session, $check) = @_;
20238  
20239 # Local variables
20240 my $profile;
20241  
20242 # Check for improper arguments
20243 if (! defined $session || defined $check) {
20244  
20245 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateTaskLists', @_);
20246 }
20247  
20248 if ($self->taskType eq 'current') {
20249  
20250 # Give task a unique name within the current tasklist
20251 $self->{uniqueName} = $self->{name} . '_' . $axmud::CLIENT->inc_taskTotal();
20252 # Set the session to which this current task will belong
20253 $self->{session} = $session;
20254 # Create an entry in the session's current tasklist
20255 $session->add_task($self);
20256  
20257 } else {
20258  
20259 # If ->storableFlag is not set, the task can't be added to any initial/custom tasklist
20260 if (! $self->storableFlag) {
20261  
20262 return $self->writeError(
20263 '\'' . $self->prettyName . '\' task cannot be added as an initial/custom task',
20264 $self->_objClass . '->updateTaskLists',
20265 );
20266  
20267 } elsif ($self->taskType eq 'initial') {
20268  
20269 if (! defined $self->profName) {
20270  
20271 # Give task a unique name within the global initial tasklist
20272 $self->{uniqueName}
20273 = $self->{name} . '_' . $axmud::CLIENT->inc_initTaskTotal();
20274 # Create an entry in the global initial tasklist
20275 $axmud::CLIENT->add_initTask($self);
20276  
20277 } else {
20278  
20279 # Give task a unique name within the associated profile's initial tasklist
20280 $profile = $session->ivShow('profHash', $self->profName);
20281 $self->{uniqueName}
20282 = $self->{name} . '_' . $profile->ivIncrement('initTaskTotal');
20283  
20284 # Inform the associated profile it has acquired a new initial task
20285 $profile->ivAdd('initTaskHash', $self->uniqueName, $self);
20286 $profile->ivPush('initTaskOrderList', $self->uniqueName);
20287 }
20288  
20289 } elsif ($self->taskType eq 'custom') {
20290  
20291 # Create an entry in the custom tasklist registry (the ->uniqueName IV isn't set;
20292 # the task already has a ->customName)
20293 $axmud::CLIENT->add_customTask($self);
20294 }
20295  
20296 # The parent file object should be marked as having had its data modified
20297 $session->setModifyFlag(
20298 $self->_parentFile,
20299 TRUE,
20300 $self->_objClass . '->updateTaskLists',
20301 );
20302 }
20303  
20304 return 1;
20305 }
20306  
20307 # Code for 'process' tasks
20308  
20309 sub main {
20310  
20311 # All process tasks must have their own main() function which resembles this generic one
20312 # $self->main() is called by GA::Session->taskLoop() every time the task loop spins
20313 #
20314 # Activity tasks should not have a main() function. They inherit their main() function from
20315 # this generic task, and an error is displayed if anything tries to call it
20316 #
20317 # Expected arguments
20318 # (none besides $self)
20319 #
20320 # Return values
20321 # 'undef' on improper arguments, if there is an error, if the task is shutting down or if
20322 # the task is reset
20323 # Otherwise, we normally return the new value of $self->stage
20324  
20325 my ($self, $check) = @_;
20326  
20327 # Local variables
20328 my $newTaskObj;
20329  
20330 # Check for improper arguments
20331 if (defined $check) {
20332  
20333 return $axmud::CLIENT->writeImproper($self->_objClass . '->main', @_);
20334 }
20335  
20336 if ($self->category eq 'activity') {
20337  
20338 # Issue a warning - activity tasks should not have their own main function, and it
20339 # should not be called
20340 return $self->writeError(
20341 '\'' . $self->uniqueName . '\' task is an activity task, but its ->main() function'
20342 . ' was called',
20343 $self->_objClass . '->main',
20344 );
20345  
20346 } elsif ($self->shutdownFlag) {
20347  
20348 # There are two ways to stop a task - by setting its status to 'finished' (in which case
20349 # it stops immediately), or by setting its ->shutdownFlag to TRUE
20350 # Task is shutting down. Close the task window, if it is open
20351 if ($self->taskWinFlag) {
20352  
20353 $self->closeWin();
20354 }
20355  
20356 # For built-in jealous tasks, inform the GA::Session that a built-in task has stopped
20357 # running
20358 if ($self->shortCutIV) {
20359  
20360 $self->session->del_standardTask($self);
20361 }
20362  
20363 # If the Status task is running, tell it to update its display of active tasks (unless
20364 # this task is the Status task, of course)
20365 if ($self->name ne 'status_task') {
20366  
20367 $self->session->update_statusTask();
20368 }
20369  
20370 # Execute any other code (each task can define their own ->doShutdown() function)
20371 $self->doShutdown();
20372  
20373 # This task can stop immediately
20374 $self->ivPoke('status', 'finished');
20375 return undef;
20376  
20377 } elsif ($self->status eq 'reset') {
20378  
20379 # The task is resetting
20380 # Create a new copy of this task, preserving some of its task parameters, but setting
20381 # other task parameters to their default states
20382 $newTaskObj = $self->_objClass->new($self->session, 'current');
20383 if (! $newTaskObj) {
20384  
20385 # Reset failed; halt this task instead
20386 $self->ivPoke('status', 'finished');
20387  
20388 return $self->writeError(
20389 'Failed to reset \'' . $self->uniqueName . '\' task - halting task instead',
20390 $self->_objClass . '->main',
20391 );
20392 }
20393  
20394 # Also preserve a few task settings. The new task has the same ->endStatus, ->endTime
20395 # and TTS settings as this one
20396 $newTaskObj->set_endStatus($self->endStatus);
20397 $newTaskObj->set_endTime($self->endTime);
20398 $newTaskObj->set_hasResetFlag(TRUE);
20399 $newTaskObj->set_ttsConfig($self->ttsConfig);
20400 $newTaskObj->set_ttsHash($self);
20401 # New task should be 'running', and start at stage 2 on the next task loop
20402 $newTaskObj->set_status('running');
20403 $newTaskObj->set_stage(2);
20404  
20405 # Copy some of this task's parameters to the new task
20406 $self->preserve($newTaskObj);
20407  
20408 # For built-in jealous tasks, inform the GA::Session that an old built-in task has
20409 # stopped running, and that a new one has started running
20410 if ($self->shortCutIV) {
20411  
20412 $self->session->del_standardTask($self);
20413 }
20414  
20415 if ($newTaskObj->shortCutIV) {
20416  
20417 $self->session->add_standardTask($newTaskObj);
20418 }
20419  
20420 # If the Status task is running, tell it to update its display of active tasks (unless
20421 # this task is the Status task, of course)
20422 if ($self->name ne 'status_task') {
20423  
20424 $self->session->update_statusTask();
20425 }
20426  
20427 # If there is a task window open, transfer it to the new task
20428 $self->transferWin($newTaskObj);
20429  
20430 # Execute any other code (each task can define their own ->doReset() function)
20431 $self->doReset($newTaskObj);
20432  
20433 # This task must stop immediately, to be replaced by $newTaskObj on the next task loop
20434 $self->ivPoke('status', 'finished');
20435 return undef;
20436  
20437 } elsif ($self->stage == 1) {
20438  
20439 # Create a new task window (if possible)
20440 if (
20441 ! $self->taskWinFlag
20442 && $self->allowWinFlag
20443 && ($self->requireWinFlag || $self->startWithWinFlag)
20444 ) {
20445 # Create a new task window
20446 if (! $self->openWin($self->winmap) && $self->requireWinFlag) {
20447  
20448 # The window was not opened, but the task requires a window in order to run, so
20449 # it must be halted
20450 $self->writeWarning(
20451 '\'' . $self->uniqueName . '\' task couldn\'t open its own window'
20452 . ' - aborting task',
20453 $self->_objClass . '->main',
20454 );
20455  
20456 $self->ivPoke('status', 'finished');
20457 return undef;
20458 }
20459 }
20460  
20461 # Set the global variable to tell any interested parties that this built-in task is
20462 # running
20463 $self->session->add_standardTask($self);
20464 # If the Status task is running, tell it to update its display of active tasks (unless
20465 # this task is the Status task, of course)
20466 if ($self->name ne 'status_task') {
20467  
20468 $self->session->update_statusTask();
20469 }
20470  
20471 # Execute any other code (each task can define their own ->doFirstStage() function)
20472 $self->doFirstStage();
20473  
20474 return $self->ivPoke('stage', 2);
20475  
20476 } else {
20477  
20478 # Process stages 2+
20479 return $self->doStage();
20480 }
20481 }
20482  
20483 sub doFirstStage {
20484  
20485 # Called by $self->main, just before the task completes the first stage ($self->stage)
20486 # This function does nothing, so tasks that need to do something special during the first
20487 # stage should have their own ->doFirstStage function
20488 #
20489 # Expected arguments
20490 # (none besides $self)
20491 #
20492 # Return values
20493 # 'undef' on improper arguments
20494 # 1 otherwise
20495  
20496 my ($self, $check) = @_;
20497  
20498 # Check for improper arguments
20499 if (defined $check) {
20500  
20501 return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_);
20502 }
20503  
20504 # (This generic ->doFirstStage function does nothing)
20505  
20506 return 1;
20507 }
20508  
20509 sub doStage {
20510  
20511 # Called by $self->main to process all stages (except stage 1)
20512 #
20513 # Expected arguments
20514 # (none besides $self)
20515 #
20516 # Return values
20517 # 'undef' on improper arguments or if this function sets that task's ->status IV to
20518 # 'finished' or sets its ->shutdownFlag to TRUE
20519 # Otherwise, we normally return the new value of $self->stage
20520  
20521 my ($self, $check) = @_;
20522  
20523 # Check for improper arguments
20524 if (defined $check) {
20525  
20526 return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_);
20527 }
20528  
20529 if ($self->stage == 2) {
20530  
20531 # (This generic ->doFirstStage function does nothing at stage 2, which repeats
20532 # indefinitely)
20533 return $self->ivPoke('stage', 2);
20534  
20535 } else {
20536  
20537 # The task stage has somehow been set to an invalid value
20538 return $self->invalidStage();
20539 }
20540 }
20541  
20542 sub invalidStage {
20543  
20544 # Called by $self->doStage when $self->stage has been set to an unrecognised value
20545 #
20546 # Expected arguments
20547 # (none besides $self)
20548 #
20549 # Return values
20550 # 'undef'
20551  
20552 my ($self, $check) = @_;
20553  
20554 # Check for improper arguments
20555 if (defined $check) {
20556  
20557 return $axmud::CLIENT->writeImproper($self->_objClass . '->invalidStage', @_);
20558 }
20559  
20560 # If $self->stage has been set to an unrecognised value, we can't continue
20561 $self->ivPoke('status', 'finished');
20562  
20563 return $self->writeError(
20564 '\'' . $self->uniqueName . '\' task : undefined task stage \'' . $self->stage . '\'',
20565 $self->_objClass . '->invalidStage',
20566 );
20567 }
20568  
20569 # Code for 'activity' tasks
20570  
20571 sub init {
20572  
20573 # All activity tasks must have their own init() function which resembles this generic one
20574 # $self->init() is called by GA::Session->taskLoop() once, when the task is added to the
20575 # current tasklist
20576 #
20577 # Process tasks should not have an init() function. They inherit their init() function from
20578 # this generic task, and an error is displayed if anything tries to call it
20579 #
20580 # Expected arguments
20581 # (none besides $self)
20582 #
20583 # Return values
20584 # 'undef' on improper arguments, if there is an error, if the task is shutting down or if
20585 # the task is reset
20586 # 1 otherwise
20587  
20588 my ($self, $check) = @_;
20589  
20590 # Local variables
20591 # ...
20592  
20593 # Check for improper arguments
20594 if (defined $check) {
20595  
20596 return $axmud::CLIENT->writeImproper($self->_objClass . '->init', @_);
20597 }
20598  
20599 if ($self->category eq 'process') {
20600  
20601 # Issue a warning - process tasks should not have their own init function, and it should
20602 # not be called
20603 return $self->writeError(
20604 '\'' . $self->uniqueName . '\' task is a process task, but its ->init() function'
20605 . ' was called',
20606 $self->_objClass . '->init',
20607 );
20608 }
20609  
20610 # Create a new task window (if possible)
20611 if (
20612 ! $self->taskWinFlag
20613 && $self->allowWinFlag
20614 && ($self->requireWinFlag || $self->startWithWinFlag)
20615 ) {
20616 # Create a new task window
20617 if (! $self->openWin($self->winmap) && $self->requireWinFlag) {
20618  
20619 # The window was not opened, but the task requires a window in order to run, so it
20620 # must be halted
20621 $self->writeWarning(
20622 '\'' . $self->uniqueName . '\' task couldn\'t open its own window'
20623 . ' - aborting task',
20624 $self->_objClass . '->main',
20625 );
20626  
20627 $self->ivPoke('status', 'finished');
20628 return undef;
20629 }
20630 }
20631  
20632 # For built-in jealous tasks, inform the GA::Session that a built-in task has started
20633 # running
20634 if ($self->shortCutIV) {
20635  
20636 $self->session->add_standardTask($self);
20637 }
20638  
20639 # If the Status task is running, tell it to update its display of active tasks (unless
20640 # this task is the Status task, of course)
20641 if ($self->name ne 'status_task') {
20642  
20643 $self->session->update_statusTask();
20644 }
20645  
20646 # Execute any other code (each task can define their own ->doInit() function)
20647 $self->doInit();
20648  
20649 # Setup complete
20650 return 1;
20651 }
20652  
20653 sub doInit {
20654  
20655 # Called by $self->init, just before the task completes its setup ($self->init)
20656 # This function does nothing, so tasks that need to do something special during a reset
20657 # should have their own ->doInit function
20658 # NB If this function modifies the task window - for example, if it should add table objects
20659 # to the window - the function should first check $self->hasResetFlag, and refrain from
20660 # creating new table objects for a window that already contains them (some example code
20661 # appears below)
20662 #
20663 # Expected arguments
20664 # (none besides $self)
20665 #
20666 # Return values
20667 # 'undef' on improper arguments
20668 # 1 otherwise
20669  
20670 my ($self, $check) = @_;
20671  
20672 # Check for improper arguments
20673 if (defined $check) {
20674  
20675 return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_);
20676 }
20677  
20678 # (This generic ->doInit function does nothing)
20679  
20680 # If the task creates a window with various table objects, it might be easier to remove
20681 # them all, rather than writing code to update them all when the task resets. You can use
20682 # this example code in that case
20683 # if ($self->hasResetFlag) {
20684 #
20685 # if (! defined $self->winObj->tableStripObj->removeAllTableObjs()) {
20686 #
20687 # # Operation failed; task must close
20688 # $self->ivPoke('shutdownFlag', TRUE);
20689 # return 1;
20690 # }
20691 # }
20692  
20693 return 1;
20694 }
20695  
20696 sub shutdown {
20697  
20698 # All activity tasks must have their own shutdown() function to allow the task to shut down
20699 # gracefully
20700 # $self->shutdown is called by GA::Session->taskLoop() once, when its ->shutdownFlag is
20701 # set to TRUE
20702 # Also called by GA::Session->stop, should the session have to stop suddenly (makes sure
20703 # any task windows are closed)
20704 #
20705 # Expected arguments
20706 # (none besides $self)
20707 #
20708 # Return values
20709 # 'undef' on improper arguments
20710 # 1 otherwise
20711  
20712 my ($self, $check) = @_;
20713  
20714 # Check for improper arguments
20715 if (defined $check) {
20716  
20717 return $axmud::CLIENT->writeImproper($self->_objClass . '->shutdown', @_);
20718 }
20719  
20720 # Task is shutting down. Close the task window, if it is open
20721 if ($self->taskWinFlag) {
20722  
20723 $self->closeWin();
20724 }
20725  
20726 # For built-in jealous tasks, inform the GA::Session that a built-in task has stopped
20727 # running
20728 if ($self->shortCutIV) {
20729  
20730 $self->session->del_standardTask($self);
20731 }
20732  
20733 # If the Status task is running, tell it to update its display of active tasks (unless this
20734 # task is the Status task, of course)
20735 if ($self->name ne 'status_task') {
20736  
20737 $self->session->update_statusTask();
20738 }
20739  
20740 # Execute any other code (each task can define their own ->doShutdown() function)
20741 $self->doShutdown();
20742  
20743 # Task can stop immediately
20744 $self->ivPoke('status', 'finished');
20745 return undef;
20746 }
20747  
20748 sub reset {
20749  
20750 # All activity tasks must have their own reset() function to allow the task to reset
20751 # properly
20752 # $self->reset is called by GA::Session->taskLoop() once, when its ->status is set to
20753 # 'reset'
20754 #
20755 # Expected arguments
20756 # (none besides $self)
20757 #
20758 # Return values
20759 # 'undef'
20760  
20761 my ($self, $check) = @_;
20762  
20763 # Local variables
20764 my $newTaskObj;
20765  
20766 # Check for improper arguments
20767 if (defined $check) {
20768  
20769 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset', @_);
20770 }
20771  
20772 # The task is resetting
20773 # Create a new copy of this task, preserving some of its task parameters, but setting other
20774 # task parameters to their default states
20775 $newTaskObj = $self->_objClass->new($self->session, 'current');
20776 if (! $newTaskObj) {
20777  
20778 # Reset failed; halt this task instead
20779 $self->ivPoke('status', 'finished');
20780  
20781 return $self->writeError(
20782 'Failed to reset \'' . $self->uniqueName . '\' task - halting task instead',
20783 $self->_objClass . '->reset',
20784 );
20785 }
20786  
20787 # Also preserve a few task settings. The new task has the same ->endStatus, ->endTime and
20788 # TTS settings as this one
20789 $newTaskObj->set_endStatus($self->endStatus);
20790 $newTaskObj->set_endTime($self->endTime);
20791 $newTaskObj->set_hasResetFlag(TRUE);
20792 $newTaskObj->set_ttsConfig($self->ttsConfig);
20793 $newTaskObj->set_ttsHash($self);
20794 # New task's status should be left as 'wait_init', so that its ->init function will be
20795 # called on the next task loop
20796 $newTaskObj->set_status('wait_init');
20797  
20798 # Copy some of this task's parameters to the new task
20799 $self->preserve($newTaskObj);
20800  
20801 # For built-in jealous tasks, inform the GA::Session that an old built-in task has stopped
20802 # running, and that a new one has started running
20803 if ($self->shortCutIV) {
20804  
20805 $self->session->del_standardTask($self);
20806 }
20807  
20808 if ($newTaskObj->shortCutIV) {
20809  
20810 $self->session->add_standardTask($newTaskObj);
20811 }
20812  
20813 # If the Status task is running, tell it to update its display of active tasks (unless this
20814 # task is the Status task, of course)
20815 if ($self->name ne 'status_task') {
20816  
20817 $self->session->update_statusTask();
20818 }
20819  
20820 # If there is a task window open, transfer it to the new task
20821 $self->transferWin($newTaskObj);
20822  
20823 # Execute any other code (each task can define their own ->doReset() function)
20824 $self->doReset($newTaskObj);
20825  
20826 # This task must stop immediately, to be replaced by $newTaskObj on the next task loop
20827 $self->ivPoke('status', 'finished');
20828 return undef;
20829 }
20830  
20831 # Code for both 'process' and 'activity' functions
20832  
20833 sub doShutdown {
20834  
20835 # Called just before the task completes a shutdown
20836 # For process tasks, called by $self->main. For activity tasks, called by $self->shutdown
20837 #
20838 # This function does nothing, so tasks that need to do something special during a shutdown
20839 # should have their own ->doShutdown function
20840 #
20841 # Expected arguments
20842 # (none besides $self)
20843 #
20844 # Return values
20845 # 'undef' on improper arguments
20846 # 1 otherwise
20847  
20848 my ($self, $check) = @_;
20849  
20850 # Check for improper arguments
20851 if (defined $check) {
20852  
20853 return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_);
20854 }
20855  
20856 # (This generic ->doShutdown function does nothing)
20857  
20858 return 1;
20859 }
20860  
20861 sub doReset {
20862  
20863 # Called just before the task completes a reset
20864 # For process tasks, called by $self->main. For activity tasks, called by $self->reset
20865 #
20866 # This function does nothing, so tasks that need to do something special during a reset
20867 # should have their own ->doReset function
20868 #
20869 # Expected arguments
20870 # $newTaskObj - The replacement task object
20871 #
20872 # Return values
20873 # 'undef' on improper arguments
20874 # 1 otherwise
20875  
20876 my ($self, $newTaskObj, $check) = @_;
20877  
20878 # Check for improper arguments
20879 if (! defined $newTaskObj || defined $check) {
20880  
20881 return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_);
20882 }
20883  
20884 # (This generic ->doReset function does nothing)
20885  
20886 return 1;
20887 }
20888  
20889 # Task window functions
20890  
20891 sub toggleWin {
20892  
20893 # Called by GA::Cmd::OpenTaskWindow->do and CloseTaskWindow->do
20894 # Decides what to do if the user tries to open or close a task window for this task
20895 # Should usually display a message informing the user of what it decided to do
20896 #
20897 # Expected arguments
20898 # (none besides $self)
20899 #
20900 # Return values
20901 # 'undef' on improper arguments or if the task isn't able to open a task window
20902 # 1 if the window is opened/closed
20903  
20904 my ($self, $check) = @_;
20905  
20906 # Local variables
20907 my $func;
20908  
20909 # Check for improper arguments
20910 if (defined $check) {
20911  
20912 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleWin', @_);
20913 }
20914  
20915 if (! $self->allowWinFlag) {
20916  
20917 # This task isn't allowed to open a window
20918 return $self->writeError(
20919 'Windows not available for this task',
20920 $self->_objClass . '->toggleWin',
20921 );
20922  
20923 } elsif ($self->taskWinFlag) {
20924  
20925 # A window is open, so close it
20926 $self->closeWin();
20927  
20928 if ($self->requireWinFlag) {
20929  
20930 # The task should shut down when its window is closed
20931 $self->ivPoke('shutdownFlag', TRUE);
20932 $self->writeText(
20933 'Window for \'' . $self->prettyName . '\' task closed (task will also halt)',
20934 );
20935  
20936 } else {
20937  
20938 # The task can continue without a window
20939 $self->writeText(
20940 'Window for \'' . $self->prettyName . '\' task closed',
20941 );
20942 }
20943  
20944 # Window closing complete
20945 return 1;
20946  
20947 } else {
20948  
20949 # A window is not currently open, so open it
20950 $self->openWin($self->winmap);
20951  
20952 if (! $self->taskWinFlag) {
20953  
20954 if ($self->requireWinFlag) {
20955  
20956 # The task cannot run without a window
20957 $self->ivPoke('shutdownFlag', TRUE);
20958 $self->writeText(
20959 'Window for \'' . $self->prettyName . '\' task could not be opened (task'
20960 . ' will be halted)',
20961 );
20962  
20963 } else {
20964  
20965 # The task can continue without a window
20966 $self->writeText(
20967 'Window for \'' . $self->prettyName . '\' task could not be opened',
20968 );
20969 }
20970  
20971 } else {
20972  
20973 $self->writeText(
20974 'Window for \'' . $self->prettyName . '\' task opened',
20975 );
20976  
20977 # If the task defines a function to call, in order to set up the window after being
20978 # opened, call the function now
20979 $func = $self->winUpdateFunc;
20980 if ($func) {
20981  
20982 $self->$func();
20983 }
20984 }
20985  
20986 # Window opening complete
20987 return 1;
20988 }
20989 }
20990  
20991 sub openWin {
20992  
20993 # Called by the task's ->main method or by its ->toggleWin method, or by any other code
20994 # Tries to open each type of task window in $self->winPreferList, halting at the first
20995 # successful attempt (or when all attempts fail)
20996 #
20997 # Expected arguments
20998 # (none besides self)
20999 #
21000 # Optional arguments
21001 # $winmap - The winmap to use in a 'grid' window or a pseudo-window (matches a key in
21002 # GA::Client->winmapHash). If 'undef', $self->winmap is used
21003 # @preferList - The types of task window to try to open. If not an empty list, this list
21004 # is used rather than $self->winPreferList
21005 #
21006 # Return values
21007 # 'undef' on improper arguments, if $winmap doesn't exist (when specified, checked even if
21008 # a 'grid' window isn't opened) or if a task window is not opened
21009 # 1 if a window is opened
21010  
21011 my ($self, $winmap, @preferList) = @_;
21012  
21013 # Local variables
21014 my ($winmapObj, $result);
21015  
21016 # (No improper arguments to check)
21017  
21018 # Don't open a task window if it's not allowed, or if there's already one open
21019 # Additionally, in Axmud 'blind' mode, don't open a task window unless it's required (the
21020 # task won't run without a window)
21021 if (
21022 ! $self->allowWinFlag
21023 || ! $self->winPreferList
21024 || $self->taskWinFlag
21025 || ($axmud::BLIND_MODE_FLAG && ! $self->requireWinFlag)
21026 ) {
21027 return undef;
21028 }
21029  
21030 # If $winmap wasn't specified, use the winmap specified by the IV or a default winmap, if
21031 # necessary
21032 if (! $winmap) {
21033  
21034 if ($self->winmap) {
21035 $winmap = $self->winmap;
21036 } else {
21037 $winmap = 'basic_empty';
21038 }
21039 }
21040  
21041 # Check the winmap exists
21042 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $winmap);
21043 if (! $winmapObj) {
21044  
21045 return undef;
21046 }
21047  
21048 # Open a task window, giving up after the first successful attempt
21049 if (! @preferList) {
21050  
21051 @preferList = $self->winPreferList;
21052 }
21053  
21054 OUTER: foreach my $item (@preferList) {
21055  
21056 if ($item eq 'grid') {
21057 $result = $self->openGridWin($winmapObj);
21058 } elsif ($item eq 'pane') {
21059 $result = $self->openPaneWin($winmapObj, FALSE);
21060 } elsif ($item eq 'entry') {
21061 $result = $self->openPaneWin($winmapObj, TRUE);
21062 } elsif ($item eq 'pseudo') {
21063 $result = $self->openPseudoWin($winmapObj);
21064 }
21065  
21066 if ($result) {
21067  
21068 last OUTER;
21069 }
21070 }
21071  
21072 return $result;
21073 }
21074  
21075 sub openGridWin {
21076  
21077 # Called by the $self->openWin (only)
21078 # Tries to open a task window as a 'grid' window (in response to 'grid' in
21079 # $self->winPreferList)
21080 #
21081 # Expected arguments
21082 # $winmapObj - The winmap object to use in the task window (matches a value in
21083 # GA::Client->winmapHash)
21084 #
21085 # Return values
21086 # 'undef' on improper arguments or if a 'grid' window is not opened
21087 # 1 if a 'grid' window is opened
21088  
21089 my ($self, $winmapObj, $check) = @_;
21090  
21091 # Local variables
21092 my (
21093 $winObj,
21094 @workspaceList,
21095 );
21096  
21097 # Check for improper arguments
21098 if (! defined $winmapObj || defined $check) {
21099  
21100 return $axmud::CLIENT->writeImproper($self->_objClass . '->openGridWin', @_);
21101 }
21102  
21103 # Compile a list of workspaces, with the workspace containing the parent session's 'main'
21104 # window first
21105 @workspaceList
21106 = $axmud::CLIENT->desktopObj->listWorkspaces($self->session->mainWin->workspaceObj);
21107  
21108 OUTER: foreach my $workspaceObj (@workspaceList) {
21109  
21110 $winObj = $workspaceObj->createGridWin(
21111 'custom', # All task windows are 'custom' windows
21112 $self->name, # Window name is the same as the task name
21113 $self->prettyName, # Window title
21114 $winmapObj->name,
21115 'Games::Axmud::Win::Internal',
21116 # Package name
21117 undef, # No windows exists yet
21118 undef, # Ditto
21119 $self, # Owner
21120 $self->session,
21121 $workspaceObj->findWorkspaceGrid($self->session),
21122 # Session's workspace grid object
21123 );
21124  
21125 if ($winObj) {
21126  
21127 last OUTER;
21128 }
21129 }
21130  
21131 if (! $winObj) {
21132  
21133 # Window not opened
21134 return undef;
21135  
21136 } else {
21137  
21138 # Window created and enabled
21139 $self->ivPoke('winObj', $winObj);
21140 $self->ivPoke('taskWinFlag', TRUE);
21141 # Set its title
21142 $self->setTaskWinTitle();
21143  
21144 # In Axmud 'blind' mode, make sure the session's 'main' window is not obscured by the
21145 # newly-opened task window
21146 if ($axmud::BLIND_MODE_FLAG) {
21147  
21148 $self->session->mainWin->restoreFocus();
21149 }
21150 }
21151  
21152 # Add a tab, if required. The TRUE argument indicates window setup
21153 $self->addTab(undef, TRUE);
21154 # Set up the entry box, if present
21155 $self->setupEntry();
21156  
21157 return 1;
21158 }
21159  
21160 sub openPaneWin {
21161  
21162 # Called by the $self->openWin (only)
21163 # Tries to open a task window as a pane object (GA::Table::Pane) inside the session's 'main'
21164 # window (in response to 'pane' or 'entry' in $self->winPreferList)
21165 #
21166 # Expected arguments
21167 # $winmapObj - The winmap object that would be used if a 'grid' window were opened
21168 # instead. This function sometimes uses it to work out with the pane
21169 # object should have an entry box, or not; in that situation, it chooses
21170 # no entry box if this value is 'undef'
21171 #
21172 # Optional arguments
21173 # $entryFlag - TRUE if the pane object should have its own entry box, FALSE (or 'undef')
21174 # if not
21175 #
21176 # Return values
21177 # 'undef' on improper arguments or if a pane object is not created
21178 # 1 if a pane object is created
21179  
21180 my ($self, $winmapObj, $entryFlag, $check) = @_;
21181  
21182 # Local variables
21183 my ($stripObj, $entryFunc, $left, $right, $top, $bottom, $tableObj, $tabObj);
21184  
21185 # Check for improper arguments
21186 if (! defined $winmapObj || defined $check) {
21187  
21188 return $axmud::CLIENT->writeImproper($self->_objClass . '->openPaneWin', @_);
21189 }
21190  
21191 # Tasks can't create pane objects inside 'main' windows if it's a 'main' window shared
21192 # between sessions
21193 if ($axmud::CLIENT->shareMainWinFlag) {
21194  
21195 return undef;
21196 }
21197  
21198 # If there's an entry box, set the callback function
21199 if ($entryFlag) {
21200  
21201 $entryFunc = $self->getMethodRef('entryCallback');
21202 }
21203  
21204 # Ask the session's 'main' window for the size and position of another table object, using
21205 # the winmap's default winzone size, and check whether space exists for another table
21206 # object
21207 $stripObj = $self->session->mainWin->tableStripObj;
21208 ($left, $right, $top, $bottom) = $stripObj->findPosn();
21209 if (! defined $left) {
21210  
21211 # No room for another table object
21212 return undef;
21213 }
21214  
21215 # Create a pane object at the specified size and position
21216 $tableObj = $stripObj->addTableObj(
21217 'Games::Axmud::Table::Pane',
21218 $left,
21219 $right,
21220 $top,
21221 $bottom,
21222 undef, # No ->objName
21223 # ->initHash
21224 'frame_title' => $self->prettyName,
21225 'entry_flag' => $entryFlag,
21226 'func' => $entryFunc,
21227 'id' => $self->uniqueName,
21228 'new_line' => 'before',
21229 );
21230  
21231 if (! $tableObj) {
21232  
21233 return undef;
21234 }
21235  
21236 # Pane object created and enabled
21237 $self->ivPoke('tableObj', $tableObj);
21238 $self->ivPoke('taskWinFlag', TRUE);
21239 $self->ivPoke('taskWinEntryFlag', $entryFlag);
21240  
21241 # Add a tab, if required. The TRUE argument indicates window setup
21242 $self->addTab(undef, TRUE);
21243  
21244 # Operatin complete
21245 return 1;
21246 }
21247  
21248 sub openPseudoWin {
21249  
21250 # Called by the $self->openWin (only)
21251 # Tries to open a task window as a pseudo-window inside the session's 'main' window, the
21252 # pseudo-window being handled by the table object GA::Table::PseudoWin (in response to
21253 # 'pseudo' in $self->winPreferList)
21254 #
21255 # Expected arguments
21256 # $winmapObj - The winmap object to use in the task window (matches a value in
21257 # GA::Client->winmapHash)
21258 #
21259 # Return values
21260 # 'undef' on improper arguments or if the pseudo-window is not opened
21261 # 1 if a pane object is created
21262  
21263 my ($self, $winmapObj, $entryFlag, $check) = @_;
21264  
21265 # Local variables
21266 my ($stripObj, $tableObj, $left, $right, $top, $bottom, $paneObj, $tabObj, $entryObj);
21267  
21268 # Check for improper arguments
21269 if (! defined $winmapObj || defined $check) {
21270  
21271 return $axmud::CLIENT->writeImproper($self->_objClass . '->openPseudoWin', @_);
21272 }
21273  
21274 # Tasks can't create boxes inside 'main' windows if it's a 'main' window shared between
21275 # sessions
21276 if ($axmud::CLIENT->shareMainWinFlag) {
21277  
21278 return undef;
21279 }
21280  
21281 # If there are any holders (GA::Table::Holder) with a suitable ->id, we can use the space
21282 # they occupy, rather than looking for a new space
21283 # Try (for example) 'status_task' first, then 'task'
21284 $stripObj = $self->session->mainWin->tableStripObj;
21285 $tableObj = $stripObj->replaceHolder(
21286 $self->name,
21287 'Games::Axmud::Table::PseudoWin',
21288 undef, # No ->objName
21289 # ->initHash
21290 'frame_title' => $self->prettyName,
21291 'win_type' => 'custom',
21292 'win_name' => $self->prettyName,
21293 'owner' => $self,
21294 'session' => $self->session,
21295 'winmap' => $winmapObj->name,
21296 );
21297  
21298 if (! $tableObj) {
21299  
21300 $stripObj->replaceHolder(
21301 'task',
21302 'Games::Axmud::Table::PseudoWin',
21303 undef, # No ->objName
21304 # ->initHash
21305 'frame_title' => $self->prettyName,
21306 'win_type' => 'custom',
21307 'win_name' => $self->prettyName,
21308 'owner' => $self,
21309 'session' => $self->session,
21310 'winmap' => $winmapObj->name,
21311 );
21312 }
21313  
21314 if (! $tableObj) {
21315  
21316 # Ask the session's 'main' window for the size and position of another table object,
21317 # using the winmap's default winzone size, and check whether space exists for another
21318 # table object
21319 ($left, $right, $top, $bottom) = $stripObj->findPosn();
21320 if (! defined $left) {
21321  
21322 # No room for another table object
21323 return undef;
21324 }
21325  
21326 # Create the GA::Table::PseudoWin object at the specified size and position
21327 $tableObj = $stripObj->addTableObj(
21328 'Games::Axmud::Table::PseudoWin',
21329 $left,
21330 $right,
21331 $top,
21332 $bottom,
21333 undef, # No ->objName
21334 # ->initHash
21335 'frame_title' => $self->prettyName,
21336 'win_type' => 'custom',
21337 'win_name' => $self->prettyName,
21338 'owner' => $self,
21339 'session' => $self->session,
21340 'winmap' => $winmapObj->name,
21341 );
21342 }
21343  
21344 if (! $tableObj) {
21345  
21346 return undef;
21347 }
21348  
21349 # Table object created and enabled
21350 $self->ivPoke('tableObj', $tableObj);
21351 $self->ivPoke('winObj', $tableObj->pseudoWinObj);
21352 $self->ivPoke('taskWinFlag', TRUE);
21353 $self->ivPoke('taskWinEntryFlag', $entryFlag);
21354  
21355 # Add a tab, if required. The TRUE argument indicates window setup
21356 $self->addTab(undef, TRUE);
21357 # Set up the entry box, if present
21358 $self->setupEntry();
21359  
21360 return 1;
21361 }
21362  
21363 sub closeWin {
21364  
21365 # Called by the task's ->main method or by its ->toggleWin method, or by any other code
21366 # Close the task window for this task, if it is open
21367 #
21368 # Expected arguments
21369 # (none besides self)
21370 #
21371 # Return values
21372 # 'undef' on improper arguments or if the window was not closed
21373 # 1 if the window was closed
21374  
21375 my ($self, $check) = @_;
21376  
21377 # Local variables
21378 my $result;
21379  
21380 # Check for improper arguments
21381 if (defined $check) {
21382  
21383 return $axmud::CLIENT->writeImproper($self->_objClass . '->closeWin', @_);
21384 }
21385  
21386 if ($self->tableObj) {
21387  
21388 # Remove a pseudo-window or a pane object inside this session's 'main' window
21389 $result = $self->session->mainWin->tableStripObj->removeTableObj($self->tableObj);
21390 $self->ivUndef('tableObj');
21391 $self->ivUndef('winObj');
21392  
21393 } elsif ($self->winObj) {
21394  
21395 # Remove a 'grid' window
21396 $result = $self->winObj->winDestroy();
21397 $self->ivUndef('winObj');
21398 }
21399  
21400 $self->ivPoke('taskWinFlag', FALSE);
21401 $self->ivPoke('taskWinEntryFlag', FALSE);
21402 $self->ivUndef('defaultTabObj');
21403  
21404 # If the task window could not be closed, or wasn't open in the first place, return 'undef';
21405 # otherwise return 1
21406 return $result;
21407 }
21408  
21409 sub transferWin {
21410  
21411 # Called by the task's ->main and ->reset functions
21412 # Transfers the task window to a new task
21413 #
21414 # Expected arguments
21415 # $newTaskObj - The new task
21416 #
21417 # Return values
21418 # 'undef' on improper arguments
21419 # 1 otherwise
21420  
21421 my ($self, $newTaskObj, $check) = @_;
21422  
21423 # Check for improper arguments
21424 if (! defined $newTaskObj || defined $check) {
21425  
21426 return $axmud::CLIENT->writeImproper($self->_objClass . '->transferWin', @_);
21427 }
21428  
21429 if ($self->winObj && $self->tableObj) {
21430  
21431 # Transfer a pseudo-window inside this session's 'main' window
21432 $newTaskObj->set_winObj($self->winObj);
21433 $newTaskObj->set_tableObj($self->tableObj);
21434 $newTaskObj->set_taskWinFlag($self->taskWinFlag);
21435 $newTaskObj->set_taskWinEntryFlag($self->taskWinEntryFlag);
21436 if ($self->defaultTabObj) {
21437  
21438 $newTaskObj->set_defaultTabObj($self->defaultTabObj);
21439 }
21440  
21441 $newTaskObj->setTaskWinTitle();
21442 $newTaskObj->insertTextThenClear('<task reset>', 'empty');
21443 $newTaskObj->winObj->set_owner($newTaskObj);
21444  
21445 } elsif ($self->winObj) {
21446  
21447 # Transfer a 'grid' window
21448 $newTaskObj->set_winObj($self->winObj);
21449 $newTaskObj->set_taskWinFlag($self->taskWinFlag);
21450 $newTaskObj->set_taskWinEntryFlag($self->taskWinEntryFlag);
21451 if ($self->defaultTabObj) {
21452  
21453 $newTaskObj->set_defaultTabObj($self->defaultTabObj);
21454 }
21455  
21456 $newTaskObj->setTaskWinTitle();
21457 $newTaskObj->insertTextThenClear('<task reset>', 'empty');
21458 $newTaskObj->winObj->set_owner($newTaskObj);
21459 $newTaskObj->winObj->resetUrgent(TRUE);
21460  
21461 } elsif ($self->tableObj) {
21462  
21463 # Remove a pane object inside this session's 'main' window
21464 $newTaskObj->set_tableObj($self->tableObj);
21465 $newTaskObj->set_taskWinFlag($self->taskWinFlag);
21466 $newTaskObj->set_taskWinEntryFlag($self->taskWinEntryFlag);
21467 if ($self->defaultTabObj) {
21468  
21469 $newTaskObj->set_defaultTabObj($self->defaultTabObj);
21470 }
21471  
21472 $newTaskObj->setTaskWinTitle();
21473 $newTaskObj->insertTextThenClear('<task reset>', 'empty');
21474 }
21475  
21476 return 1;
21477 }
21478  
21479 sub addTab {
21480  
21481 # Can be called by any code. During window setup, called by $self->openGridWin,
21482 # ->openPaneWin and ->openPseudoWin
21483 # Adds a tab to the task window's pane object, and updates IVs
21484 #
21485 # Expected arguments
21486 # (none besides $self)
21487 #
21488 # Optional arguments
21489 # $labelText - If defined, the tab label text to use. Ignored when a simple tab is
21490 # created
21491 # $openFlag - Set to TRUE when called during window setup, in which case a tab is not
21492 # opened if $self->tabMode is 'empty'. Set to FALSE (or 'undef') when
21493 # called by anything else, in which case this function treats values of
21494 # $self->tabMode 'empty and 'multi' the same, in other words, for all
21495 # defined values of $self->tabMode, we try to open a tab
21496 #
21497 # Return values
21498 # 'undef' on improper arguments or if no tab is added to the pane object
21499 # Otherwise returns the tab object (GA::Obj::Tab) created
21500  
21501 my ($self, $labelText, $openFlag, $check) = @_;
21502  
21503 # Local variables
21504 my ($paneObj, $tabObj);
21505  
21506 # Check for improper arguments
21507 if (defined $check) {
21508  
21509 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTab', @_);
21510 }
21511  
21512 # Find the pane object (GA::Table::Pane), if one was created
21513 if (! $self->winObj) {
21514 $paneObj = $self->tableObj;
21515 } else {
21516 $paneObj = $self->winObj->findTableObj('pane');
21517 }
21518  
21519 # The type of tab created depends on the value of $self->tabMode
21520 if (
21521 # No pane object exists
21522 ! $paneObj
21523 # Can't create tabs at all, if ->tabMode not set
21524 || ! defined $self->tabMode
21525 # Can't create a simple tab, if one already exists
21526 || ($self->tabMode eq 'simple' && $self->defaultTabObj)
21527 ) {
21528 return undef;
21529 }
21530  
21531 if ($self->tabMode eq 'simple') {
21532  
21533 $tabObj = $paneObj->addSimpleTab(
21534 $self->session,
21535 $self->getColourScheme(),
21536 );
21537  
21538 } elsif (
21539 ($openFlag && $self->tabMode eq 'multi')
21540 || ! $openFlag
21541 ) {
21542 $tabObj = $paneObj->addTab(
21543 $self->session,
21544 $self->getColourScheme(),
21545 undef,
21546 undef,
21547 $labelText,
21548 );
21549 }
21550  
21551 if (! $tabObj) {
21552  
21553 return undef;
21554 }
21555  
21556 if (! $self->defaultTabObj) {
21557  
21558 # The first tab added is the default one
21559 $self->ivPoke('defaultTabObj', $tabObj);
21560 }
21561  
21562 # The default newline behaviour for task windows is to insert a newline character before
21563 # each string displayed, rather than inserting one afterwards (as usual)
21564 $tabObj->textViewObj->set_newLineDefault('before');
21565  
21566 # Mark the pane's textview object as monochrome, if required
21567 if ($self->monochromeFlag) {
21568  
21569 $tabObj->paneObj->applyMonochrome($tabObj);
21570 }
21571  
21572 # Prevent the pane's textview from scrolling downwards
21573 if ($tabObj && $self->noScrollFlag) {
21574  
21575 $tabObj->textViewObj->set_scrollLockType('top');
21576 $tabObj->textViewObj->toggleScrollLock();
21577 }
21578  
21579 # Call a task function when the visible tab changes
21580 $paneObj->set_switchFunc($self->getMethodRef('switchTabCallback'));
21581 $paneObj->set_switchID($self->name);
21582  
21583 # Operation complete
21584 return $tabObj;
21585 }
21586  
21587 sub removeTab {
21588  
21589 # Can be called by any code
21590 # The task window's set up functions add a first tab (or not) to the window, and then other
21591 # parts of the task code are free to call $self->addTab to add more tabs, in which case
21592 # this function can be called to remove them again
21593 # When the task window closes, it's not necessary to call this function at all
21594 #
21595 # Expected arguments
21596 # $arg - So that tasks have flexibility over the way they store the tabs they create,
21597 # $arg can be the tab object (GA::Obj::Tab) or the tab object's ->number
21598 #
21599 # Return values
21600 # 'undef' on improper arguments, if the specified tab no longer exists in the task
21601 # window's pane object (GA::Table::Pane) or if the close operation fails
21602 # 1 if the close operation succeeds
21603  
21604 my ($self, $arg, $check) = @_;
21605  
21606 # Local variables
21607 my ($paneObj, $result);
21608  
21609 # Check for improper arguments
21610 if (defined $check) {
21611  
21612 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupEntry', @_);
21613 }
21614  
21615 # Find the pane object (GA::Table::Pane), if one was created
21616 if (! $self->winObj) {
21617 $paneObj = $self->tableObj;
21618 } else {
21619 $paneObj = $self->winObj->findTableObj('pane');
21620 }
21621  
21622 if (! $paneObj) {
21623  
21624 return undef;
21625 }
21626  
21627 # Find the pane object (GA::Table::Pane)
21628 $paneObj = $self->winObj->findTableObj('pane');
21629  
21630 if ($axmud::CLIENT->intCheck($arg, 0)) {
21631  
21632 $arg = $paneObj->ivShow('tabObjHash', $arg);
21633 if (! defined $arg) {
21634  
21635 # Tab has already been removed
21636 return undef;
21637 }
21638  
21639 } elsif (
21640 ! $paneObj->ivExists('tabObjHash', $arg->number)
21641 || $paneObj->ivShow('tabObjHash', $arg->number) ne $arg
21642 ) {
21643 # Tab has already been removed
21644 return undef;
21645 }
21646  
21647 # Remove the tab
21648 $result = $paneObj->removeTab($arg);
21649  
21650 # Update standard IVs
21651 if ($self->defaultTabObj && $self->defaultTabObj eq $arg) {
21652  
21653 $self->ivUndef('defaultTabObj');
21654 }
21655  
21656 # Operation complete
21657 return $result;
21658 }
21659  
21660 sub setupEntry {
21661  
21662 # Called by $self->openGridWin and ->openPseudoWin (only)
21663 # Sets up the task window's entry box, if it exists
21664 #
21665 # Expected arguments
21666 # (none besides $self)
21667 #
21668 # Return values
21669 # 'undef' on improper arguments or if no entry box exists
21670 # 1 otherwise
21671  
21672 my ($self, $check) = @_;
21673  
21674 # Local variables
21675 my $entryObj;
21676  
21677 # Check for improper arguments
21678 if (defined $check) {
21679  
21680 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupEntry', @_);
21681 }
21682  
21683 if (! $self->winObj) {
21684  
21685 return undef;
21686 }
21687  
21688 # Find the entry for this window, if one was created, and set its callback function. The
21689 # entry box may have been created by a strip object (GA::Strip::Entry) or a table object
21690 # (GA::Table::Entry)
21691 $entryObj = $self->winObj->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
21692 if (! $entryObj) {
21693  
21694 $entryObj = $self->winObj->findTableObj('entry');
21695 }
21696  
21697 if (! $entryObj) {
21698  
21699 $self->ivPoke('taskWinEntryFlag', FALSE);
21700  
21701 return undef;
21702  
21703 } else {
21704  
21705 $self->ivPoke('taskWinEntryFlag', TRUE);
21706 $entryObj->set_func($self->getMethodRef('entryCallback'));
21707 $entryObj->set_id($self->uniqueName);
21708  
21709 return 1;
21710 }
21711 }
21712  
21713 sub setTaskWinTitle {
21714  
21715 # Can be called by any code to set or restore the text in the task window label: the title
21716 # bar for a 'grid' window, or the frame title for a pane object in the session's 'main'
21717 # window
21718 #
21719 # Expected arguments
21720 # (none besides self)
21721 #
21722 # Optional arguments
21723 # $string - A string to add the title bar (if 'undef', the default title is used)
21724 # $flag - If TRUE, $string is added to the usual text; otherwise string replaces
21725 # the usual text
21726 #
21727 # Return values
21728 # 'undef' on improper arguments or if the task window is not open
21729 # 1 if the window was closed
21730  
21731 my ($self, $string, $flag, $check) = @_;
21732  
21733 # Local variables
21734 my $text;
21735  
21736 # Check for improper arguments
21737 if (defined $check) {
21738  
21739 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTaskWinTitle', @_);
21740 }
21741  
21742 # Set the default title bar text for task windows
21743 $text = $self->prettyName;
21744  
21745 # If $string was specified, append it to $text (or overwrite $text)
21746 if (defined $string) {
21747  
21748 if ($flag) {
21749 $text .= ' ' . $string;
21750 } else {
21751 $text = $string;
21752 }
21753 }
21754  
21755 # Update the label
21756 if ($self->tableObj) {
21757  
21758 # Set the frame title (calling a function in GA::Generic::Table)
21759 $self->tableObj->set_frameTitle($text);
21760 return 1;
21761  
21762 } elsif ($self->winObj) {
21763  
21764 # Set the title bar (calling a function in GA::Win::Internal)
21765 $self->winObj->setWinTitle($text);
21766 return 1;
21767  
21768 } else {
21769  
21770 # Task window not open
21771 return undef;
21772 }
21773 }
21774  
21775 # Shortcuts to GA::Obj::TextView for the task's default tab
21776  
21777 sub clearBuffer {
21778  
21779 my ($self, @args) = @_;
21780  
21781 if ($self->defaultTabObj) {
21782 return $self->defaultTabObj->textViewObj->clearBuffer(@args);
21783 } else {
21784 return undef;
21785 }
21786 }
21787  
21788 sub insertText {
21789  
21790 my ($self, @args) = @_;
21791  
21792 if ($self->defaultTabObj) {
21793 return $self->defaultTabObj->textViewObj->insertText(@args);
21794 } else {
21795 return undef;
21796 }
21797 }
21798  
21799 sub insertMultipleText {
21800  
21801 my ($self, @args) = @_;
21802  
21803 if ($self->defaultTabObj) {
21804 return $self->defaultTabObj->textViewObj->insertMultipleText(@args);
21805 } else {
21806 return undef;
21807 }
21808 }
21809  
21810 sub insertWithLinks {
21811  
21812 my ($self, @args) = @_;
21813  
21814 if ($self->defaultTabObj) {
21815 return $self->defaultTabObj->textViewObj->insertWithLinks(@args);
21816 } else {
21817 return undef;
21818 }
21819 }
21820  
21821 sub insertQuick {
21822  
21823 my ($self, @args) = @_;
21824  
21825 if ($self->defaultTabObj) {
21826 return $self->defaultTabObj->textViewObj->insertQuick(@args);
21827 } else {
21828 return undef;
21829 }
21830 }
21831  
21832 sub insertTextThenClear {
21833  
21834 my ($self, @args) = @_;
21835  
21836 if (
21837 ! $self->defaultTabObj
21838 || ! $self->defaultTabObj->textViewObj->insertText(@args)
21839 ) {
21840 return undef;
21841  
21842 } else {
21843  
21844 # The next time text is inserted into the textview's buffer, the buffer is first cleared
21845 # (which removes the '<task reset>' message, if this function was called by
21846 # $slf->transferWin)
21847 $self->defaultTabObj->textViewObj->set_clearAfterInsert();
21848  
21849 return 1;
21850 }
21851 }
21852  
21853 sub showImage {
21854  
21855 my ($self, @args) = @_;
21856  
21857 if ($self->defaultTabObj) {
21858 return $self->defaultTabObj->textViewObj->showImage(@args);
21859 } else {
21860 return undef;
21861 }
21862 }
21863  
21864 # Callbacks
21865  
21866 sub entryCallback {
21867  
21868 # Usually called by a ->signal_connect in GA::Strip::Entry->setEntrySignals or in
21869 # GA::Table::Entry->setActivateEvent, when the user types something in the strip/table
21870 # object's Gtk3::Entry and presses RETURN
21871 # This generic function just displays the typed text in the task window's default tab;
21872 # other tasks can write their own ->entryCallback as required
21873 #
21874 # Expected arguments
21875 # $obj - The strip or table object whose Gtk3::Entry was used
21876 # $entry - The Gtk3::Entry itself
21877 #
21878 # Optional arguments
21879 # $id - A value passed to the table object that identifies the particular
21880 # Gtk3::Entry used (in case the table object uses multiple entries). By
21881 # default, $self->openWin sets $id to the same as $self->uniqueName;
21882 # could be an 'undef' value otherwise
21883 # $text - The text typed in the entry by the user (should not be 'undef')
21884 #
21885 # Return values
21886 # 'undef' on improper arguments
21887 # 1 otherwise
21888  
21889 my ($self, $obj, $entry, $id, $text, $check) = @_;
21890  
21891 # Check for improper arguments
21892 if (! defined $obj || ! defined $entry || defined $check) {
21893  
21894 return $axmud::CLIENT->writeImproper($self->_objClass . '->entryCallback', @_);
21895 }
21896  
21897 if ($self->taskWinFlag && $self->defaultTabObj && $self->defaultTabObj->textViewObj) {
21898  
21899 $self->defaultTabObj->textViewObj->insertText($text, 'after');
21900 }
21901  
21902 return 1;
21903 }
21904  
21905 sub switchTabCallback {
21906  
21907 # Usually called GA::Table::Pane->respondVisibleTab whenever the visible tab in the task
21908 # window changes
21909 # This generic function does nothing; other tasks can write their own ->switchTabCallback
21910 # as required
21911 #
21912 # Expected arguments
21913 # $paneObj - The GA::Table::Pane object for the task window
21914 # $tabObj - The GA::Obj::Tab for the newly-visible tab
21915 #
21916 # Optional arguments
21917 # $id - A value passed by the pane object; for tasks, set to this task's ->name
21918 # (in general, might be 'undef')
21919 #
21920 # Return values
21921 # 'undef' on improper arguments
21922 # 1 otherwise
21923  
21924 my ($self, $paneObj, $tabObj, $id, $check) = @_;
21925  
21926 # Check for improper arguments
21927 if (! defined $paneObj || ! defined $tabObj || defined $check) {
21928  
21929 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchTabCallback', @_);
21930 }
21931  
21932 # (This generic function does nothing)
21933  
21934 return 1;
21935 }
21936  
21937 sub closeTabCallback {
21938  
21939 # Usually called GA::Table::Pane->removeTab whenever a tab in the task window is manually
21940 # closed by the user
21941 # This generic function simpy checks that the closed tab isn't the same one stored in
21942 # $self->defaultTabObj, and resets that IV, if so
21943 #
21944 # Expected arguments
21945 # $paneObj - The GA::Table::Pane object for the task window
21946 # $tabObj - The GA::Obj::Tab for the closed tab
21947 #
21948 # Optional arguments
21949 # $id - A value passed by the pane object; for tasks, set to this task's ->name
21950 # (in general, might be 'undef')
21951 #
21952 # Return values
21953 # 'undef' on improper arguments
21954 # 1 otherwise
21955  
21956 my ($self, $paneObj, $tabObj, $id, $check) = @_;
21957  
21958 # Check for improper arguments
21959 if (! defined $paneObj || ! defined $tabObj || defined $check) {
21960  
21961 return $axmud::CLIENT->writeImproper($self->_objClass . '->closeTabCallback', @_);
21962 }
21963  
21964 if ($self->defaultTabObj && $self->defaultTabObj eq $tabObj) {
21965  
21966 $self->ivUndef('defaultTabObj');
21967 }
21968  
21969 return 1;
21970 }
21971  
21972 # Text-to-speech functions
21973  
21974 sub ttsReadAttrib {
21975  
21976 # Called by GA::Cmd::Read->do and PermRead->do
21977 # Users can use the client command ';read' to interact with individual tasks, typically
21978 # getting them to read out information (e.g. the Status task can read out current health
21979 # points)
21980 # The ';read' command is in the form ';read <attribute>' or ';read <attribute> <value>'.
21981 # The ';read' command looks up the <attribute> in GA::Client->ttsAttribHash, which tells
21982 # it which task to call
21983 # Tasks that don't use text-to-speech (TTS) will inherit this generic function. Tasks that
21984 # do use TTS should include a modified form of this function that decides what to do
21985 # with each <attribute>. If a <value> was also specified, the task can decide whether to
21986 # use it, store it or ignore it
21987 #
21988 # Expected arguments
21989 # $attrib - The TTS attribute specified by the calling function. Must be one of the
21990 # keys in $self->ttsAttribHash
21991 #
21992 # Optional arguments
21993 # $value - The value specified by the calling function (or 'undef' if none was
21994 # specified)
21995 # $noSpecialFlag
21996 # - Set to TRUE when called by GA::Cmd::PermRead->do, in which case only
21997 # this task's hash of attributes is updated. If set to FALSE (or 'undef'),
21998 # something is usually read aloud, too
21999 #
22000 # Return values
22001 # 'undef' on improper arguments or if the $attrib doesn't exist in this task's
22002 # ->ttsAttribHash
22003 # 1 otherwise
22004  
22005 my ($self, $attrib, $value, $noSpecialFlag, $check) = @_;
22006  
22007 # Check for improper arguments
22008 if (! defined $attrib || defined $check) {
22009  
22010 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsReadAttrib', @_);
22011 }
22012  
22013 # TTS attributes are case-insensitive
22014 $attrib = lc($attrib);
22015  
22016 # Check that the specified attribute is actually used by this task (';read' or ';permread'
22017 # should carry out this check, but better safe than sorry)
22018 if (! $self->ivExists('ttsAttribHash', $attrib)) {
22019  
22020 return undef;
22021  
22022 } elsif ($noSpecialFlag) {
22023  
22024 # When called by GA::Cmd::PermRead->do, don't read out anything, just update the hash
22025 # of attributes (when appropriate)
22026 # This generic function doesn't update $self->ttsAttribHash, but other tasks'
22027 # ->ttsReadAttrib should decide which attributes (if any) to update)
22028  
22029 # (no attributes require an update)
22030  
22031 return 1;
22032  
22033 } else {
22034  
22035 # The generic function doesn't have any TTS attributes, but other tasks' ->ttsReadAttrib
22036 # functions should decide what to do here, and return 1
22037  
22038 # (no attributes require a response)
22039  
22040 return 1;
22041 }
22042 }
22043  
22044 sub ttsSwitchFlagAttrib {
22045  
22046 # Called by GA::Cmd::Switch->do and PermSwitch->do
22047 # Users can use the client command ';switch' to interact with individual tasks, typically
22048 # telling them to turn on/off the automatic reading out of information (e.g. the Locator
22049 # task can be told to start or stop reading out room titles as they are received from
22050 # the world)
22051 # The ';switch' command is in the form ';switch <flag_attribute>'. The ';switch' command
22052 # looks up the <flag_attribute> (which is a string, not a TRUE/FALSE value) in
22053 # GA::Session->ttsFlagAttribHash, which tells it which task to call
22054 # Tasks that don't use text-to-speech (TTS) will inherit this generic function. Tasks that
22055 # do use TTS can either inherit this generic function (if all they want to do is toggle
22056 # the TRUE/FALSE values stored in a key-value pair in $self->ttsFlagAttribHash), or else
22057 # they must include a modified form of this function that does something different
22058 #
22059 # Expected arguments
22060 # $flagAttrib - The TTS flag attribute specified by the calling function. Must be one of
22061 # the keys in $self->ttsFlagAttribHash
22062 #
22063 # Optional arguments
22064 # $noSpecialFlag
22065 # - Set to TRUE when called by GA::Cmd::PermSwitch->do, in which case only
22066 # this task's hash of flag attributes is updated. Otherwise set to FALSE
22067 # (or 'undef'), in which case other things can happen when a flag
22068 # attribute is switched. For all built-in tasks, there is no difference
22069 # in behaviour
22070 #
22071 # Return values
22072 # 'undef' on improper arguments or if the $flagAttrib doesn't exist in this task's
22073 # ->ttsFlagAttribHash
22074 # Otherwise returns a confirmation message for the calling function to display
22075  
22076 my ($self, $flagAttrib, $noSpecialFlag, $check) = @_;
22077  
22078 # Local variables
22079 my $msg;
22080  
22081 # Check for improper arguments
22082 if (! defined $flagAttrib || defined $check) {
22083  
22084 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSwitchFlagAttrib', @_);
22085 }
22086  
22087 # TTS flag attributes are case-insensitive
22088 $flagAttrib = lc($flagAttrib);
22089  
22090 # Check that the specified flag attribute is actually used by this task (';switch' or
22091 # ';permswitch' should carry out this check, but better safe than sorry)
22092 if (! $self->ivExists('ttsFlagAttribHash', $flagAttrib)) {
22093  
22094 return undef;
22095  
22096 } else {
22097  
22098 # If a current task performs some kind of action, when a flag attribute is switched,
22099 # the code for the action should be placed here. (Tasks in the global initial
22100 # tasklist can't perform an action, of course.)
22101 if (! $noSpecialFlag) {
22102  
22103 # (no actions to perform)
22104 }
22105  
22106 # The generic task doesn't have any TTS flag attributes, but other tasks'
22107 # ->ttsSwitchFlagAttrib functions should decide what to do here, and return a
22108 # confirmation message
22109 # Usually, that means toggling the TRUE/FALSE values stored in $self->ttsFlagAttribHash
22110 $msg = '\'' . $self->prettyName . '\' flag attribute \'' . $flagAttrib
22111 . '\' switched to ';
22112  
22113 if ($self->ivShow('ttsFlagAttribHash', $flagAttrib)) {
22114  
22115 $self->ivAdd('ttsFlagAttribHash', $flagAttrib, FALSE);
22116 $msg .= 'OFF';
22117  
22118 } else {
22119  
22120 $self->ivAdd('ttsFlagAttribHash', $flagAttrib, TRUE);
22121 $msg .= 'ON';
22122 }
22123  
22124 return $msg;
22125 }
22126 }
22127  
22128 sub ttsSetAlertAttrib {
22129  
22130 # Called by GA::Cmd::Alert->do and PermAlert->do
22131 # Users can use the client command ';alert' to interact with individual tasks, typically
22132 # instructing them to read out information some time later (e.g. the Status task can read
22133 # out an alert when health points drop below a certain level or recover to a certain
22134 # level)
22135 # The ';alert' command is in the form ';alert <alert_attribute>' or
22136 # ';alert <alert_attribute> <value>'. The ';alert' command looks up the <alert_attribute>
22137 # in GA::Session->ttsAlertAttribHash, which tells it which task to call
22138 # Tasks that don't use text-to-speech (TTS) will inherit this generic function. Tasks that
22139 # do use TTS should include a modified form of this function that decides what to do
22140 # with each <alert_attribute>. If a <value> was also specified, the task can decide
22141 # whether to use it, store it or ignore it
22142 #
22143 # Expected arguments
22144 # $alertAttrib - The TTS attribute specified by the calling function. Must be one of
22145 # the keys in $self->ttsAttribHash
22146 #
22147 # Optional arguments
22148 # $value - The value specified by the calling function (or 'undef' if none was
22149 # specified)
22150 # $noSpecialFlag - Set to TRUE when called by GA::Cmd::PermAlert->do, in which case only
22151 # this task's hash of alert attributes is updated. Otherwise set to
22152 # FALSE (or 'undef'), in which case other things can happen when an
22153 # alert is set. For all built-in tasks, there is no difference in
22154 # behaviour
22155 #
22156 # Return values
22157 # 'undef' on improper arguments or if the $attrib doesn't exist in this task's
22158 # ->ttsAlertAttribHash
22159 # Otherwise returns a confirmation message for the calling function to display
22160  
22161 my ($self, $alertAttrib, $value, $noSpecialFlag, $check) = @_;
22162  
22163 # Local variables
22164 my $msg;
22165  
22166 # Check for improper arguments
22167 if (! defined $alertAttrib || defined $check) {
22168  
22169 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSetAlertAttrib', @_);
22170 }
22171  
22172 # TTS attributes are case-insensitive
22173 $alertAttrib = lc($alertAttrib);
22174  
22175 # Check that the specified attribute is actually used by this task (';alert' or ';permalert'
22176 # should carry out this check, but better safe than sorry)
22177 if (! $self->ivExists('ttsAlertAttribHash', $alertAttrib)) {
22178  
22179 return undef;
22180  
22181 } else {
22182  
22183 # If a current task performs some kind of action, when an alert attribute is set, the
22184 # code for the action should be placed here. (Tasks in the global initial tasklist
22185 # can't perform an action, of course.)
22186 if (! $noSpecialFlag) {
22187  
22188 # (no actions to perform)
22189 }
22190  
22191 # The generic task doesn't have any TTS alert attributes, but other tasks'
22192 # ->ttsSetAlertAttrib functions should decide what to do here, and return a
22193 # confirmation message
22194 $msg = 'The generic task can\'t process alert attributes';
22195  
22196 return $msg;
22197 }
22198 }
22199  
22200 sub ttsQuick {
22201  
22202 # Perform a quick call to GA::Client->tts, using this task's TTS settings
22203 # By using this function, rather than calling GA::Client->tts directly, we can use one
22204 # line of code, rather than several
22205 #
22206 # Expected arguments
22207 # $text - The text to read out
22208 #
22209 # Return values
22210 # 'undef' on improper arguments
22211 # 1 otherwise
22212  
22213 my ($self, $text, $check) = @_;
22214  
22215 # Check for improper arguments
22216 if (! defined $text || defined $check) {
22217  
22218 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsQuick', @_);
22219 }
22220  
22221 if ($axmud::CLIENT->ttsTaskFlag) {
22222  
22223 $axmud::CLIENT->tts(
22224 $text, # This varies...
22225 'task', # ...but these are always the same
22226 $self->ttsConfig,
22227 $self->session,
22228 );
22229 }
22230  
22231 return 1;
22232 }
22233  
22234 # Misc functions
22235  
22236 sub getColourScheme {
22237  
22238 # Called by $self->openPaneWin and ->configureWin
22239 # Returns the name of the colour scheme that should be used in a tab in the task window
22240 #
22241 # Expected arguments
22242 # (none besides $self)
22243 #
22244 # Return values
22245 # 'undef' on improper arguments or if the default colour scheme for task windows
22246 # ('custom') should be used
22247 # Otherwise, returns the name of the colour scheme to use
22248  
22249 my ($self, $check) = @_;
22250  
22251 # Local variables
22252 my ($colourScheme, $name);
22253  
22254 # Check for improper arguments
22255 if (defined $check) {
22256  
22257 return $axmud::CLIENT->writeImproper($self->_objClass . '->getColourScheme', @_);
22258 }
22259  
22260 if (
22261 $self->colourScheme
22262 && $axmud::CLIENT->ivExists('colourSchemeHash', $self->colourScheme)
22263 ) {
22264 return $self->colourScheme;
22265  
22266 } else {
22267  
22268 # If a colour scheme exists with the same name as this task, use it; otherwise use the
22269 # default colour scheme for 'custom' windows (by leaving $colourScheme as 'undef')
22270 # For the convenience of the user, check for both 'locator_task' and 'locator'
22271 $name = $self->name;
22272 if ($axmud::CLIENT->ivExists('colourSchemeHash', $name)) {
22273  
22274 return $name;
22275  
22276 } else {
22277  
22278 $name =~ s/_task//;
22279 if ($axmud::CLIENT->ivExists('colourSchemeHash', $name)) {
22280  
22281 return $name;
22282 }
22283 }
22284 }
22285  
22286 # Use the default colour scheme
22287 return undef;
22288 }
22289  
22290 sub returnParameterHash {
22291  
22292 # Can be called by anything
22293 # Returns all of the task's parameters and their values as a hash - thereby stripping all
22294 # task settings and the IVs ->_objName, ->_objClass, ->_parentFile, ->_parentWorld and
22295 # ->_privFlag - for any code that needs it
22296 #
22297 # Expected arguments
22298 # (none besides $self)
22299 #
22300 # Return values
22301 # An empty hash on improper arguments
22302 # Otherwise the hash of task parameters (might be empty if the task has no parameters)
22303  
22304 my ($self, $check) = @_;
22305  
22306 # Local variables
22307 my (
22308 @ivList,
22309 %taskHash, %emptyHash,
22310 );
22311  
22312 # Check for improper arguments
22313 if (defined $check) {
22314  
22315 $axmud::CLIENT->writeImproper($self->_objClass . '->returnParameterHash', @_);
22316 return %emptyHash;
22317 }
22318  
22319 # Compile a list of parameters to show. First import the list of IVs
22320 @ivList = $self->ivList();
22321  
22322 # Convert that list into a hash, preserving both the IV and its value
22323 foreach my $iv (@ivList) {
22324  
22325 $taskHash{$iv} = $self->{$iv};
22326 }
22327  
22328 # Remove all the task settings from %taskHash
22329 foreach my $iv ($axmud::CLIENT->ivKeys('constTaskSettingsHash')) {
22330  
22331 delete $taskHash{$iv};
22332 }
22333  
22334 # Remove the special IVs present in all Axmud Perl objects, leaving only IVs that are
22335 # task parameters
22336 foreach my $iv ($axmud::CLIENT->ivKeys('constIVHash')) {
22337  
22338 delete $taskHash{$iv};
22339 }
22340  
22341 return %taskHash;
22342 }
22343  
22344 ##################
22345 # Accessors - set
22346  
22347 sub set_colourScheme {
22348  
22349 my ($self, $colourScheme, $check) = @_;
22350  
22351 # Local variables
22352 my $paneObj;
22353  
22354 # Check for improper arguments
22355 if (defined $check) {
22356  
22357 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_colourScheme', @_);
22358 }
22359  
22360 $self->ivPoke('colourScheme', $colourScheme); # Can be 'undef'
22361  
22362 if ($self->defaultTabObj && $self->defaultTabObj->paneObj) {
22363  
22364 $self->defaultTabObj->paneObj->applyColourScheme(undef, $self->colourScheme);
22365 }
22366  
22367 return 1;
22368 }
22369  
22370 sub set_defaultTabObj {
22371  
22372 my ($self, $obj, $check) = @_;
22373  
22374 # Check for improper arguments
22375 if (! defined $obj || defined $check) {
22376  
22377 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_defaultTabObj', @_);
22378 }
22379  
22380 $self->ivPoke('defaultTabObj', $obj);
22381  
22382 return 1;
22383 }
22384  
22385 sub set_endStatus {
22386  
22387 my ($self, $endStatus, $check) = @_;
22388  
22389 # Check for improper arguments
22390 if (! defined $endStatus || defined $check) {
22391  
22392 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_endStatus', @_);
22393 }
22394  
22395 $self->ivPoke('endStatus', $endStatus);
22396  
22397 return 1;
22398 }
22399  
22400 sub set_endTime {
22401  
22402 my ($self, $endTime, $check) = @_;
22403  
22404 # Check for improper arguments
22405 if (! defined $endTime || defined $check) {
22406  
22407 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_endTime', @_);
22408 }
22409  
22410 $self->ivPoke('endTime', $endTime);
22411  
22412 return 1;
22413 }
22414  
22415 sub set_hasResetFlag {
22416  
22417 my ($self, $flag, $check) = @_;
22418  
22419 # Check for improper arguments
22420 if (! defined $flag || defined $check) {
22421  
22422 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_hasResetFlag', @_);
22423 }
22424  
22425 if ($flag) {
22426 $self->ivPoke('hasResetFlag', TRUE);
22427 } else {
22428 $self->ivPoke('hasResetFlag', FALSE);
22429 }
22430  
22431 return 1;
22432 }
22433  
22434 sub set_resumeStatus {
22435  
22436 my ($self, $status, $check) = @_;
22437  
22438 # Check for improper arguments
22439 if (defined $check) {
22440  
22441 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_resumeStatus', @_);
22442 }
22443  
22444 if (defined $status) {
22445  
22446 if ($axmud::CLIENT->ivExists('constTaskStatusHash', $status)) {
22447  
22448 $self->ivPoke('resumeStatus', $status);
22449  
22450 } else {
22451  
22452 # Invalid status
22453 return undef;
22454 }
22455  
22456 } else {
22457  
22458 $self->ivUndef('resumeStatus');
22459 }
22460  
22461 return 1;
22462 }
22463  
22464 sub set_requireWinFlag {
22465  
22466 my ($self, $flag, $check) = @_;
22467  
22468 # Check for improper arguments
22469 if (! defined $flag || defined $check) {
22470  
22471 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_requireWinFlag', @_);
22472 }
22473  
22474 if ($flag) {
22475 $self->ivPoke('requireWinFlag', TRUE);
22476 } else {
22477 $self->ivPoke('requireWinFlag', FALSE);
22478 }
22479  
22480 return 1;
22481 }
22482  
22483 sub set_shutdownFlag {
22484  
22485 my ($self, $flag, $check) = @_;
22486  
22487 # Check for improper arguments
22488 if (! defined $flag || defined $check) {
22489  
22490 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_status', @_);
22491 }
22492  
22493 if ($flag) {
22494 $self->ivPoke('shutdownFlag', TRUE);
22495 } else {
22496 $self->ivPoke('shutdownFlag', FALSE);
22497 }
22498  
22499 return 1;
22500 }
22501  
22502 sub set_stage {
22503  
22504 my ($self, $stage, $check) = @_;
22505  
22506 # Check for improper arguments
22507 if (! defined $stage || defined $check) {
22508  
22509 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_stage', @_);
22510 }
22511  
22512 $self->ivPoke('stage', $stage);
22513  
22514 return 1;
22515 }
22516  
22517 sub set_startTime {
22518  
22519 my ($self, $startTime, $check) = @_;
22520  
22521 # Check for improper arguments
22522 if (! defined $startTime || defined $check) {
22523  
22524 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_startTime', @_);
22525 }
22526  
22527 $self->ivPoke('startTime', $startTime);
22528  
22529 return 1;
22530 }
22531  
22532 sub set_startWithWinFlag {
22533  
22534 my ($self, $flag, $check) = @_;
22535  
22536 # Check for improper arguments
22537 if (! defined $flag || defined $check) {
22538  
22539 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_startWithWinFlag', @_);
22540 }
22541  
22542 if ($flag) {
22543 $self->ivPoke('startWithWinFlag', TRUE);
22544 } else {
22545 $self->ivPoke('startWithWinFlag', FALSE);
22546 }
22547  
22548 return 1;
22549 }
22550  
22551 sub set_status {
22552  
22553 my ($self, $status, $check) = @_;
22554  
22555 # Check for improper arguments
22556 if (! defined $status || defined $check) {
22557  
22558 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_status', @_);
22559 }
22560  
22561 if ($axmud::CLIENT->ivExists('constTaskStatusHash', $status)) {
22562  
22563 $self->ivPoke('status', $status);
22564 }
22565  
22566  
22567 return 1;
22568 }
22569  
22570 sub set_tableObj {
22571  
22572 my ($self, $tableObj, $check) = @_;
22573  
22574 # Check for improper arguments
22575 if (defined $check) {
22576  
22577 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tableObj', @_);
22578 }
22579  
22580 $self->ivPoke('tableObj', $tableObj);
22581  
22582 return 1;
22583 }
22584  
22585 sub set_taskWinEntryFlag {
22586  
22587 my ($self, $flag, $check) = @_;
22588  
22589 # Check for improper arguments
22590 if (! defined $flag || defined $check) {
22591  
22592 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_taskWinEntryFlag', @_);
22593 }
22594  
22595 if ($flag) {
22596 $self->ivPoke('taskWinEntryFlag', TRUE);
22597 } else {
22598 $self->ivPoke('taskWinEntryFlag', FALSE);
22599 }
22600  
22601 return 1;
22602 }
22603  
22604 sub set_taskWinFlag {
22605  
22606 my ($self, $flag, $check) = @_;
22607  
22608 # Check for improper arguments
22609 if (! defined $flag || defined $check) {
22610  
22611 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_taskWinFlag', @_);
22612 }
22613  
22614 if ($flag) {
22615 $self->ivPoke('taskWinFlag', TRUE);
22616 } else {
22617 $self->ivPoke('taskWinFlag', FALSE);
22618 }
22619  
22620 return 1;
22621 }
22622  
22623 sub set_ttsConfig {
22624  
22625 my ($self, $configuration, $check) = @_;
22626  
22627 # Check for improper arguments
22628 if (defined $check) {
22629  
22630 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_ttsConfig', @_);
22631 }
22632  
22633 $self->ivPoke('ttsConfig', $configuration);
22634  
22635 return 1;
22636 }
22637  
22638 sub set_ttsHash {
22639  
22640 my ($self, $taskObj, $check) = @_;
22641  
22642 # Check for improper arguments
22643 if (! defined $taskObj || defined $check) {
22644  
22645 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_ttsHash', @_);
22646 }
22647  
22648 $self->ivPoke('ttsAttribHash', $taskObj->ttsAttribHash);
22649 $self->ivPoke('ttsFlagAttribHash', $taskObj->ttsFlagAttribHash);
22650 $self->ivPoke('ttsAlertAttribHash', $taskObj->ttsAlertAttribHash);
22651  
22652 return 1;
22653 }
22654  
22655 sub set_waitForTask {
22656  
22657 my ($self, $waitForTask, $check) = @_;
22658  
22659 # Check for improper arguments
22660 if (! defined $waitForTask || defined $check) {
22661  
22662 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_waitForTask', @_);
22663 }
22664  
22665 $self->ivPoke('waitForTask', $waitForTask);
22666  
22667 return 1;
22668 }
22669  
22670 sub set_winObj {
22671  
22672 my ($self, $winObj, $check) = @_;
22673  
22674 # Check for improper arguments
22675 if (! defined $winObj || defined $check) {
22676  
22677 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winObj', @_);
22678 }
22679  
22680 $self->ivPoke('winObj', $winObj);
22681  
22682 return 1;
22683 }
22684  
22685 sub del_winObj {
22686  
22687 # Called by GA::Win::Generic->winDestroy
22688  
22689 my ($self, $winObj, $check) = @_;
22690  
22691 # Local variables
22692 my $stripObj;
22693  
22694 # Check for improper arguments
22695 if (! defined $winObj || defined $check) {
22696  
22697 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_winObj', @_);
22698 }
22699  
22700 # Do nothing if the task already knows the window is closed, or if the task is shutting down
22701 # anyway
22702 if ($self->winObj && $self->winObj eq $winObj && ! $self->shutdownFlag) {
22703  
22704 # Mark the window as closed
22705 $self->ivUndef('winObj');
22706 $self->ivPoke('taskWinFlag', FALSE);
22707 $self->ivPoke('taskWinEntryFlag', FALSE);
22708 $self->ivUndef('defaultTabObj');
22709  
22710 # For pseudo-windows, this function should probably not be called; nevertheless, if the
22711 # parent table object is still open, close it
22712 if ($winObj->pseudoWinTableObj) {
22713  
22714 $stripObj = $winObj->pseudoWinTableObj->stripObj;
22715 if ($stripObj->ivExists('tableObjHash', $winObj->pseudoWinTableObj->number)) {
22716  
22717 $stripObj->removeTableObj($winObj->pseudoWinTableObj);
22718 }
22719 }
22720  
22721 if ($self->requireWinFlag) {
22722  
22723 # The task should shut down when its window is closed
22724 $self->ivPoke('shutdownFlag', TRUE);
22725 $self->writeText(
22726 'Window for \'' . $self->prettyName . '\' task closed (task will also halt)',
22727 );
22728  
22729 } else {
22730  
22731 # The task can continue without a window
22732 $self->writeText(
22733 'Window for \'' . $self->prettyName . '\' task closed (task will continue)',
22734 );
22735 }
22736 }
22737  
22738 return 1;
22739 }
22740  
22741 ##################
22742 # Accessors - get
22743  
22744 sub session
22745 { $_[0]->{session} }
22746  
22747 sub name
22748 { $_[0]->{name} }
22749  
22750 sub prettyName
22751 { $_[0]->{prettyName} }
22752 sub uniqueName
22753 { $_[0]->{uniqueName} }
22754 sub shortName
22755 { $_[0]->{shortName} }
22756 sub customName
22757 { $_[0]->{customName} }
22758  
22759 sub category
22760 { $_[0]->{category} }
22761 sub descrip
22762 { $_[0]->{descrip} }
22763 sub taskType
22764 { $_[0]->{taskType} }
22765 sub profName
22766 { $_[0]->{profName} }
22767 sub profCategory
22768 { $_[0]->{profCategory} }
22769 sub shortCutIV
22770 { $_[0]->{shortCutIV} }
22771  
22772 sub jealousyFlag
22773 { $_[0]->{jealousyFlag} }
22774 sub requireLocatorFlag
22775 { $_[0]->{requireLocatorFlag} }
22776 sub profSensitivityFlag
22777 { $_[0]->{profSensitivityFlag} }
22778 sub storableFlag
22779 { $_[0]->{storableFlag} }
22780  
22781 sub startTime
22782 { $_[0]->{startTime} }
22783 sub checkTime
22784 { $_[0]->{checkTime} }
22785 sub endStatus
22786 { $_[0]->{endStatus} }
22787 sub endTime
22788 { $_[0]->{endTime} }
22789 sub waitForTask
22790 { $_[0]->{waitForTask} }
22791 sub delayTime
22792 { $_[0]->{delayTime} }
22793  
22794 sub shutdownFlag
22795 { $_[0]->{shutdownFlag} }
22796 sub hasResetFlag
22797 { $_[0]->{hasResetFlag} }
22798 sub status
22799 { $_[0]->{status} }
22800 sub resumeStatus
22801 { $_[0]->{resumeStatus} }
22802 sub activeFlag
22803 { $_[0]->{activeFlag} }
22804 sub stage
22805 { $_[0]->{stage} }
22806  
22807 sub allowWinFlag
22808 { $_[0]->{allowWinFlag} }
22809 sub requireWinFlag
22810 { $_[0]->{requireWinFlag} }
22811 sub startWithWinFlag
22812 { $_[0]->{startWithWinFlag} }
22813 sub winPreferList
22814 { my $self = shift; return @{$self->{winPreferList}}; }
22815 sub winObj
22816 { $_[0]->{winObj} }
22817 sub tableObj
22818 { $_[0]->{tableObj} }
22819 sub taskWinFlag
22820 { $_[0]->{taskWinFlag} }
22821 sub taskWinEntryFlag
22822 { $_[0]->{taskWinEntryFlag} }
22823 sub winmap
22824 { $_[0]->{winmap} }
22825 sub winUpdateFunc
22826 { $_[0]->{winUpdateFunc} }
22827 sub defaultTabObj
22828 { $_[0]->{defaultTabObj} }
22829 sub tabMode
22830 { $_[0]->{tabMode} }
22831 sub monochromeFlag
22832 { $_[0]->{monochromeFlag} }
22833 sub colourScheme
22834 { $_[0]->{colourScheme} }
22835 sub noScrollFlag
22836 { $_[0]->{noScrollFlag} }
22837  
22838 sub ttsFlag
22839 { $_[0]->{ttsFlag} }
22840 sub ttsConfig
22841 { $_[0]->{ttsConfig} }
22842 sub ttsAttribHash
22843 { my $self = shift; return %{$self->{ttsAttribHash}}; }
22844 sub ttsFlagAttribHash
22845 { my $self = shift; return %{$self->{ttsFlagAttribHash}}; }
22846 sub ttsAlertAttribHash
22847 { my $self = shift; return %{$self->{ttsAlertAttribHash}}; }
22848 }
22849  
22850 { package Games::Axmud::Generic::Win;
22851  
22852 use strict;
22853 use warnings;
22854 # use diagnostics;
22855  
22856 use Glib qw(TRUE FALSE);
22857  
22858 our @ISA = qw(Games::Axmud);
22859  
22860 ##################
22861 # Constructors
22862  
22863 # sub new {} # Defined in window objects which inherit this one
22864  
22865 ##################
22866 # Methods
22867  
22868 # Standard window object functions
22869  
22870 # sub winSetup {} # Defined in window objects which inherit this one
22871  
22872 # sub winEnable {} # Defined in window objects which inherit this one
22873  
22874 # sub winDisengage {} # Defined in window objects which inherit this one
22875  
22876 # sub winDestroy {} # Defined in window objects which inherit this one
22877  
22878 sub winShowAll {
22879  
22880 # Generic function to update the window itself to make any changes visible
22881 # If some code has called $self->setInvisible, then nothing happens (and the window
22882 # remains invisible)
22883 #
22884 # Expected arguments
22885 # (none besides $self)
22886 #
22887 # Optional arguments
22888 # $string - For debugging purposes. Describes the calling function, e.g.
22889 # ->winShowAll($self->_objClass . '->callingFunction');
22890 #
22891 # Return values
22892 # 'undef' on improper arguments
22893 # 1 otherwise
22894  
22895 my ($self, $string, $check) = @_;
22896  
22897 # Check for improper arguments
22898 if (defined $check) {
22899  
22900 return $axmud::CLIENT->writeImproper($self->_objClass . '->winShowAll', @_);
22901 }
22902  
22903 if ($self->winWidget && $self->visibleFlag) {
22904  
22905 $self->winWidget->show_all();
22906  
22907 # Any textview objects (GA::Obj::TextView) which are waiting to update their size IVs
22908 # can now do so
22909 foreach my $textViewObj ($axmud::CLIENT->desktopObj->ivValues('textViewHash')) {
22910  
22911 if ($textViewObj->sizeUpdateFlag && $textViewObj->winObj eq $self) {
22912  
22913 $textViewObj->updateVisibleSize();
22914 }
22915 }
22916  
22917 # Optionally, write information about the calling function to the terminal (for
22918 # debugging)
22919 # if ($string) {
22920 #
22921 # print "->winShowAll() call from " . $string . " at " . $axmud::CLIENT->getTime()
22922 # . "\n";
22923 #
22924 # } else {
22925 #
22926 # print "->winShowAll() call from unspecified function at "
22927 # . $axmud::CLIENT->getTime() . "\n";
22928 # }
22929 }
22930  
22931 return 1;
22932 }
22933  
22934 sub drawWidgets {
22935  
22936 # Generic function to draw widgets within the window, usually called by $self->winSetup or
22937 # $self->winEnable
22938 #
22939 # Expected arguments
22940 # (none besides $self)
22941 #
22942 # Return values
22943 # 'undef' on improper arguments
22944 # 1 on success
22945  
22946 my ($self, $check) = @_;
22947  
22948 # Check for improper arguments
22949 if (defined $check) {
22950  
22951 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
22952 }
22953  
22954 # (Do nothing)
22955  
22956 return 1;
22957 }
22958  
22959 sub redrawWidgets {
22960  
22961 # Generic function to redraw widgets within the window
22962 #
22963 # Expected arguments
22964 # (none besides $self)
22965 #
22966 # Return values
22967 # 'undef' on improper arguments
22968 # 1 on success
22969  
22970 my ($self, $check) = @_;
22971  
22972 # Check for improper arguments
22973 if (defined $check) {
22974  
22975 return $axmud::CLIENT->writeImproper($self->_objClass . '->redrawWidgets', @_);
22976 }
22977  
22978 # (Do nothing)
22979  
22980 return 1;
22981 }
22982  
22983 # ->signal_connects
22984  
22985 # Other functions
22986  
22987 sub setTitle {
22988  
22989 # Can be called by anything
22990 # Sets the text on this window's title bar
22991 #
22992 # Expected arguments
22993 # $title - The string to use as the window's title
22994 #
22995 # Return values
22996 # 'undef' on improper arguments
22997 # 1 otherwise
22998  
22999 my ($self, $title, $check) = @_;
23000  
23001 # Check for improper arguments
23002 if (! defined $title || defined $check) {
23003  
23004 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTitle', @_);
23005 }
23006  
23007 # (Don't use this function to set titles for pseudo-windows)
23008 if ($self->winWidget eq $self->winBox) {
23009  
23010 $self->winWidget->set_title($title);
23011 }
23012  
23013 return 1;
23014 }
23015  
23016 sub getTitle {
23017  
23018 # Can be called by anything
23019 # Gets the text on this window's title bar
23020 #
23021 # Expected arguments
23022 # (none besides $self)
23023 #
23024 # Return values
23025 # 'undef' on improper arguments
23026 # Otherwise returns the title bar text
23027  
23028 my ($self, $check) = @_;
23029  
23030 # Check for improper arguments
23031 if (defined $check) {
23032  
23033 return $axmud::CLIENT->writeImproper($self->_objClass . '->getTitle', @_);
23034 }
23035  
23036 return $self->winWidget->get_title();
23037  
23038 return 1;
23039 }
23040  
23041 sub setUrgent {
23042  
23043 # Sets this window's urgency hint
23044 #
23045 # Expected arguments
23046 # (none besides $self)
23047 #
23048 # Optional arguments
23049 # $flag - If set to TRUE, this window's urgency hint is only set, if Gtk3 reports that
23050 # it is not currently set. If set to FALSE (or 'undef'), this function sets
23051 # the window's urgency hint regardless
23052 #
23053 # Return values
23054 # 'undef' on improper arguments or if the window's urgency hint is not set
23055 # 1 if the window's urgency hint is set
23056  
23057 my ($self, $flag, $check) = @_;
23058  
23059 # Check for improper arguments
23060 if (defined $check) {
23061  
23062 return $axmud::CLIENT->writeImproper($self->_objClass . '->setUrgent', @_);
23063 }
23064  
23065 if (
23066 $self->winWidget eq $self->winBox
23067 && (! $flag || ! $self->winWidget->get_urgency_hint())
23068 ) {
23069 $self->winWidget->set_urgency_hint(TRUE);
23070  
23071 return 1;
23072  
23073 } else {
23074  
23075 # Hint not set
23076 return undef;
23077 }
23078 }
23079  
23080 sub resetUrgent {
23081  
23082 # Resets this window's urgency hint
23083 #
23084 # Expected arguments
23085 # (none besides $self)
23086 #
23087 # Optional arguments
23088 # $flag - If set to TRUE, this window's urgency hint is only reset, if Gtk3 reports that
23089 # it is currently set. If set to FALSE (or 'undef'), this function resets
23090 # the window's urgency hint regardless
23091 #
23092 # Return values
23093 # 'undef' on improper arguments or if the window's urgency hint is not reset
23094 # 1 if the window's urgency hint is reset
23095  
23096 my ($self, $flag, $check) = @_;
23097  
23098 # Check for improper arguments
23099 if (defined $check) {
23100  
23101 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetUrgent', @_);
23102 }
23103  
23104 if (
23105 $self->winWidget eq $self->winBox
23106 && (! $flag || $self->winWidget->get_urgency_hint())
23107 ) {
23108 $self->winWidget->set_urgency_hint(FALSE);
23109 # The line above doesn't work (in Linux Mint with Cinnamon), so we'll do it the brutal
23110 # way, too
23111 $self->restoreFocus();
23112 if ($self->session) {
23113  
23114 $self->session->mainWin->restoreFocus();
23115 }
23116  
23117 return 1;
23118  
23119 } else {
23120  
23121 # Hint not reset
23122 return undef;
23123 }
23124 }
23125  
23126 sub restoreFocus {
23127  
23128 # Can be called by any function (often after creating a 'dialogue' window or after
23129 # re-stacking 'grid' windows)
23130 # Activates this window object's Gtk3::Window, if it is known. For 'internal' windows,
23131 # returns the focus to the entry box in the 'Games::Axmud::Strip::Entry' strip object, if
23132 # there is one
23133 #
23134 # Expected arguments
23135 # (none besides $self)
23136 #
23137 # Return values
23138 # 'undef' on improper arguments or $self->winWidget is not set
23139 # 1 otherwise
23140  
23141 my ($self, $check) = @_;
23142  
23143 # Local variables
23144 my $stripObj;
23145  
23146 # Check for improper arguments
23147 if (defined $check) {
23148  
23149 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreFocus', @_);
23150 }
23151  
23152 # Activate the Gtk3::Window, if it is known (for pseudo-windows, activate the parent window)
23153 if ($self->winType eq 'external') {
23154  
23155 # Activate the window
23156 $axmud::CLIENT->desktopObj->wmCtrlObj->wmctrl(
23157 '-a',
23158 $self->internalID,
23159 '-i',
23160 );
23161  
23162 } else {
23163  
23164 if (! $self->winWidget) {
23165  
23166 return undef;
23167  
23168 } else {
23169  
23170 $self->winWidget->present();
23171 }
23172  
23173 # For 'internal' windows, returns the focus to the entry box in the
23174 # 'Games::Axmud::Strip::Entry' strip object, if there is one
23175 if (
23176 $self->winType eq 'main'
23177 || $self->winType eq 'protocol'
23178 || $self->winType eq 'custom'
23179 ) {
23180 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
23181 if ($stripObj) {
23182  
23183 $stripObj->entry->grab_focus();
23184 }
23185 }
23186 }
23187  
23188 return 1;
23189 }
23190  
23191 sub setVisible {
23192  
23193 # Can be called by any function
23194 # Makes the Gtk3::Window itself visible, and sets a flag so that calls to $self->winShowAll
23195 # are carried out
23196 #
23197 # Expected arguments
23198 # (none besides $self)
23199 #
23200 # Return values
23201 # 'undef' on improper arguments or $self->winWidget is not set
23202 # 1 otherwise
23203  
23204 my ($self, $check) = @_;
23205  
23206 # Check for improper arguments
23207 if (defined $check) {
23208  
23209 return $axmud::CLIENT->writeImproper($self->_objClass . '->setVisible', @_);
23210 }
23211  
23212 if (! $self->winWidget) {
23213  
23214 return undef;
23215  
23216 } else {
23217  
23218 $self->winWidget->set_visible(TRUE);
23219 $self->ivPoke('visibleFlag', TRUE);
23220  
23221 return 1;
23222 }
23223 }
23224  
23225 sub setInvisible {
23226  
23227 # Can be called by any function
23228 # Makes the Gtk3::Window itself invisible, and sets a flag so that calls to
23229 # $self->winShowAll are ignored until the window is made visible again (via a call to
23230 # $self->setVisible)
23231 #
23232 # Expected arguments
23233 # (none besides $self)
23234 #
23235 # Return values
23236 # 'undef' on improper arguments or $self->winWidget is not set
23237 # 1 otherwise
23238  
23239 my ($self, $check) = @_;
23240  
23241 # Check for improper arguments
23242 if (defined $check) {
23243  
23244 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInvisible', @_);
23245 }
23246  
23247 if (! $self->winWidget) {
23248  
23249 return undef;
23250  
23251 } else {
23252  
23253 $self->winWidget->set_visible(FALSE);
23254 $self->ivPoke('visibleFlag', FALSE);
23255  
23256 return 1;
23257 }
23258 }
23259  
23260 sub minimise {
23261  
23262 # Can be called by anything
23263 # Minimises the window
23264 #
23265 # Expected arguments
23266 # (none besides $self)
23267 #
23268 # Return values
23269 # 'undef' on improper arguments or if the window can't be minimised
23270 # 1 otherwise
23271  
23272 my ($self, $check) = @_;
23273  
23274 # Check for improper arguments
23275 if (defined $check) {
23276  
23277 return $axmud::CLIENT->writeImproper($self->_objClass . '->minimise', @_);
23278 }
23279  
23280 if (! $self->winWidget) {
23281  
23282 return undef;
23283  
23284 } else {
23285  
23286 $self->winWidget->iconify();
23287 return 1
23288 }
23289 }
23290  
23291 sub unminimise {
23292  
23293 # Can be called by anything
23294 # Minimises the window
23295 #
23296 # Expected arguments
23297 # (none besides $self)
23298 #
23299 # Return values
23300 # 'undef' on improper arguments or if the window can't be unminimised
23301 # 1 otherwise
23302  
23303 my ($self, $check) = @_;
23304  
23305 # Check for improper arguments
23306 if (defined $check) {
23307  
23308 return $axmud::CLIENT->writeImproper($self->_objClass . '->unminimise', @_);
23309 }
23310  
23311 if (! $self->winWidget) {
23312  
23313 return undef;
23314  
23315 } else {
23316  
23317 $self->winWidget->deiconify();
23318 # (On Linux, un-minimising the window doesn't work reliably without this line)
23319 $self->winWidget->present();
23320  
23321 return 1
23322 }
23323 }
23324  
23325 sub getBorder {
23326  
23327 # Can be called by anything except 'dialogue' window code, which accesses this function
23328 # throught its parent 'grid' or 'free' window
23329 # Gets the correct border size for this window type
23330 #
23331 # Expected arguments
23332 # (none besides $self)
23333 #
23334 # Return values
23335 # 'undef' on improper arguments
23336 # Otherwise returns the spacing size in pixels
23337  
23338 my ($self, $check) = @_;
23339  
23340 # Check for improper arguments
23341 if (defined $check) {
23342  
23343 return $axmud::CLIENT->writeImproper($self->_objClass . '->getBorder', @_);
23344 }
23345  
23346 if ($self->winCategory eq 'free') {
23347 return $axmud::CLIENT->constFreeBorderPixels;
23348 } elsif ($self->winType eq 'main') {
23349 return $axmud::CLIENT->constMainBorderPixels;
23350 } else {
23351 return $axmud::CLIENT->constGridBorderPixels;
23352 }
23353 }
23354  
23355 sub getSpacing {
23356  
23357 # Can be called by anything except 'dialogue' window code, which accesses this function
23358 # throught its parent 'grid' or 'free' window
23359 # Gets the correct spacing size for this window type
23360 #
23361 # Expected arguments
23362 # (none besides $self)
23363 #
23364 # Return values
23365 # 'undef' on improper arguments
23366 # Otherwise returns the spacing size in pixels
23367  
23368 my ($self, $check) = @_;
23369  
23370 # Check for improper arguments
23371 if (defined $check) {
23372  
23373 return $axmud::CLIENT->writeImproper($self->_objClass . '->getSpacing', @_);
23374 }
23375  
23376 if ($self->winCategory eq 'free') {
23377 return $axmud::CLIENT->constFreeSpacingPixels;
23378 } elsif ($self->winType eq 'main') {
23379 return $axmud::CLIENT->constMainSpacingPixels;
23380 } else {
23381 return $axmud::CLIENT->constGridSpacingPixels;
23382 }
23383 }
23384  
23385 # 'free' windows
23386  
23387 sub createFreeWin {
23388  
23389 # All 'free' windows must have an owner, and the owner must be another window object (which
23390 # can be a 'grid' or a 'free' window object)
23391 # 'dialogue' windows should be created via a call to one of the functions in this generic
23392 # window object (e.g. $self->showMsgDialogue, $self->showComboDialogue, etc)
23393 # All other types of 'free' window should be created via a call to $self->createFreeWin or
23394 # $self->quickFreeWin
23395 #
23396 # Expected arguments
23397 # $packageName - The Perl object for the child 'free' window
23398 #
23399 # Optional arguments
23400 # $owner - The owner. A 'grid' window object (but not an 'external' window) or a
23401 # 'free' window object (but not any other kind of object). If 'undef',
23402 # then this window object is the owner
23403 # $session - The GA::Session from which this function was called. If 'undef',
23404 # the new window's ->session is the same as $owner's session (which
23405 # might be 'undef', too)
23406 # $title - A string to use as the child window's title. If 'undef', a generic
23407 # title is used
23408 # $editObj - The object to be edited in the child window (for 'edit' windows only;
23409 # should be 'undef' for other types of 'free' window)
23410 # $tempFlag - Flag set to TRUE if $editObj is either temporary, or has not yet been
23411 # added to any registry (usually because the user needs to name it
23412 # first). Set to FALSE (or 'undef') otherwise. Ignored if $editObj is
23413 # not specified
23414 # %configHash - Hash containing any number of key-value pairs needed for this
23415 # particular 'free' window; for example, for example,
23416 # GA::PrefWin::TaskStart uses it to specify a task name and type.
23417 # Set to an empty hash if not required
23418 #
23419 # Return values
23420 # 'undef' on improper arguments or if the child 'free' window can't be created
23421 # Otherwise returns the blessed reference to the child window
23422  
23423 my ($self, $packageName, $owner, $session, $title, $editObj, $tempFlag, %configHash) = @_;
23424  
23425 # Local variables
23426 my ($pluginName, $pluginObj, $class, $winObj);
23427  
23428 # Check for improper arguments
23429 if (! defined $packageName) {
23430  
23431 return $axmud::CLIENT->writeImproper($self->_objClass . '->createFreeWin', @_);
23432 }
23433  
23434 # All windows except 'external' and 'dialogue' windows can have a child 'free' window
23435 if ($self->winType eq 'external' || $self->winType eq 'dialogue') {
23436  
23437 return undef;
23438 }
23439  
23440 # If the window package was added by a plugin and the plugin is disabled, don't create the
23441 # window
23442 $pluginName = $axmud::CLIENT->ivShow('pluginFreeWinHash', $packageName);
23443 if ($pluginName) {
23444  
23445 $pluginObj = $axmud::CLIENT->ivShow('pluginHash', $pluginName);
23446 if ($pluginObj && ! $pluginObj->enabledFlag) {
23447  
23448 return undef;
23449 }
23450 }
23451  
23452 # If no owner is specified, it's this window
23453 if (! $owner) {
23454  
23455 $owner = $self;
23456  
23457 # If an owner is specified, it must be a window object (inheriting from GA::Generic::Win)
23458 } elsif (! $owner->isa('Games::Axmud::Generic::Win')) {
23459  
23460 return undef;
23461 }
23462  
23463 # If no session is specified, it's the owner's session
23464 if (! $session) {
23465  
23466 $session = $owner->session;
23467 }
23468  
23469 # Create the 'free' window object
23470 $winObj = $packageName->new(
23471 $axmud::CLIENT->desktopObj->freeWinCount,
23472 $self->workspaceObj,
23473 $owner,
23474 $session,
23475 $title,
23476 $editObj,
23477 $tempFlag,
23478 %configHash,
23479 );
23480  
23481 # Check it's any 'free' window besides a 'dialogue' window
23482 if (! $winObj || $winObj->winCategory ne 'free' || $winObj->winType eq 'dialogue') {
23483  
23484 return undef;
23485 }
23486  
23487 # Make the window visible
23488 if (! $winObj->winSetup()) {
23489  
23490 return undef;
23491 }
23492  
23493 if (! $winObj->winEnable()) {
23494  
23495 return undef;
23496 }
23497  
23498 # Update IVs
23499 $axmud::CLIENT->desktopObj->add_freeWin($winObj);
23500 $self->add_childFreeWin($winObj);
23501  
23502 return $winObj;
23503 }
23504  
23505 sub quickFreeWin {
23506  
23507 # Shortcut to $self->createFreeWin, allowing the calling code to specify only the bare
23508 # minimum of arguments
23509 #
23510 # Expected arguments
23511 # $packageName - The Perl object for the child 'free' window
23512 #
23513 # Optional arguments
23514 # $session - The GA::Session from which this function was called. If 'undef',
23515 # the new window's ->session is the same as this window's session
23516 # (which might be 'undef', too)
23517 # %configHash - Hash containing any number of key-value pairs needed for this
23518 # particular 'free' window; for example, for example,
23519 # GA::PrefWin::TaskStart uses it to specify a task name and type.
23520 # Set to an empty hash if not required
23521 #
23522 # Return values
23523 # 'undef' on improper arguments or if the child 'free' window can't be created
23524 # Otherwise returns the blessed reference to the child window
23525  
23526 my ($self, $packageName, $session, %configHash) = @_;
23527  
23528 # Check for improper arguments
23529 if (! defined $packageName) {
23530  
23531 return $axmud::CLIENT->writeImproper($self->_objClass . '->quickFreeWin', @_);
23532 }
23533  
23534 return $self->createFreeWin(
23535 $packageName, # Compulsory
23536 undef,
23537 $session, # May be 'undef'
23538 undef,
23539 undef,
23540 undef,
23541 %configHash,
23542 );
23543 }
23544  
23545 # 'dialogue' windows
23546  
23547 sub closeDialogueWin {
23548  
23549 # Can be called by anything to close a 'dialogue' window early (especially one that won't
23550 # close itself)
23551 # For example, called by GA::Client->start and GA::Session->setupProfiles after an earlier
23552 # call to the 'dialogue' window created by $self->showBusyWin
23553 #
23554 # Expected arguments
23555 # $dialogueWin - The 'dialogue' window to close
23556 #
23557 # Return values
23558 # 'undef' on improper arguments
23559 # 1 otherwise
23560  
23561 my ($self, $dialogueWin, $check) = @_;
23562  
23563 # Check for improper arguments
23564 if (! defined $dialogueWin || defined $check) {
23565  
23566 return $axmud::CLIENT->writeImproper($self->_objClass . '->closeDialogueWin', @_);
23567 }
23568  
23569 # Close the window
23570 $dialogueWin->destroy();
23571  
23572 # For a 'dialogue' window created by $self->showBusyWin, we need to update a GA::Client IV
23573 if ($axmud::CLIENT->busyWin && $axmud::CLIENT->busyWin eq $dialogueWin) {
23574  
23575 $axmud::CLIENT->set_busyWin();
23576 }
23577  
23578 return 1;
23579 }
23580  
23581 sub addDialogueIcon {
23582  
23583 # Called by many of the following functions that open some kind of Gtk3::Dialogue
23584 # Takes the 'dialogue' window's main Gtk3::VBox, and splits it (using a Gtk3::HBox) into
23585 # two, with a standard icon on the left, and a new Gtk3::VBox on the right
23586 # Makes a simple 'dialogue' window look a lot nicer (see $self->showEntryDialogue for an
23587 # example of how it works)
23588 #
23589 # Expected arguments
23590 # $vBox - The 'dialogue' window's main Gtk3::VBox
23591 #
23592 # Optional arguments
23593 # $path - Full filepath to an image file to use; if 'undef' or the file doesn't
23594 # exist, the standard icon is used
23595 # $noFrameFlag - TRUE if the image should be drawn without an enclosing frame, FALSE
23596 # (or 'undef') otherwise. (Set to TRUE when called by
23597 # $self->showMsgDialogue)
23598 #
23599 # Return values
23600 # 'undef' on improper arguments
23601 # Otherwise returns the new VBox, contained within the existing main one
23602  
23603 my ($self, $vBox, $path, $noFrameFlag, $check) = @_;
23604  
23605 # Local variables
23606 my $spacing;
23607  
23608 # Check for improper arguments
23609 if (! defined $vBox || defined $check) {
23610  
23611 return $axmud::CLIENT->writeImproper($self->_objClass . '->addDialogueIcon', @_);
23612 }
23613  
23614 # Set the correct spacing size for 'dialogue' windows
23615 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
23616  
23617 # Draw widgets
23618 my $hBox = Gtk3::HBox->new(FALSE, 0);
23619 $vBox->pack_start($hBox, TRUE, TRUE, 0);
23620  
23621 my $vBox2 = Gtk3::VBox->new(FALSE, 0);
23622 $hBox->pack_start($vBox2, TRUE, TRUE, $spacing);
23623  
23624 my $vBox3 = Gtk3::VBox->new(FALSE, 0);
23625 $hBox->pack_start($vBox3, TRUE, TRUE, $spacing);
23626  
23627 if (! $noFrameFlag) {
23628  
23629 # (This code block is designed for Axmud icons, sized 64x64 and above)
23630 my $frame = Gtk3::Frame->new(undef);
23631 $vBox2->pack_start($frame, FALSE, FALSE, $spacing);
23632 $frame->set_size_request(64, 64);
23633 $frame->set_shadow_type($axmud::CLIENT->constShadowType);
23634  
23635 if (! $path || ! -e $path) {
23636  
23637 $path = $axmud::CLIENT->getDialogueIcon();
23638 }
23639  
23640 my $image = Gtk3::Image->new_from_file($path);
23641 $frame->add($image);
23642  
23643 } else {
23644  
23645 # (This code block is designed for the Gtk dialogue icon replacements, sized 32x32)
23646 $vBox2->set_size_request(48, 48);
23647  
23648 my $image = Gtk3::Image->new_from_file($path);
23649 $vBox2->pack_start($image, FALSE, FALSE, $spacing);
23650 }
23651  
23652 return $vBox3;
23653 }
23654  
23655 sub showMsgDialogue {
23656  
23657 # Can be called by any function
23658 # Creates a standard Gtk3::MessageDialog and returns the response (if any)
23659 #
23660 # Expected arguments
23661 # $title - The title to display, e.g. 'File Save'
23662 # $icon - 'info', 'warning', 'error', 'question'
23663 # $text - The message to display. Can be pango markup text, or just plain text
23664 # $buttonType - 'none', 'ok', 'close', 'cancel', 'yes-no', 'ok-cancel'
23665 #
23666 # Optional arguments
23667 # $defaultResponse
23668 # - If defined, the default button ('yes', 'no', etc)
23669 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
23670 # lines (because the calling function has already added newline
23671 # characters as it requires). If FALSE (or 'undef'), the message
23672 # $text is split into lines of no more than 40 characters
23673 #
23674 # Return values
23675 # 'undef' on improper arguments, or if unrecognised values for $icon and/or $buttonType
23676 # are specified
23677 # Otherwise returns the user response (e.g. returns 'yes' if the user clicks on the 'yes'
23678 # button)
23679  
23680 my ($self, $title, $icon, $text, $buttonType, $defaultResponse, $noSplitFlag, $check) = @_;
23681  
23682 # Local variables
23683 my (
23684 $spacing, $response,
23685 @argList, @list,
23686 %buttonHash,
23687 );
23688  
23689 # Check for improper arguments
23690 if (
23691 ! defined $title || ! defined $icon || ! defined $text || ! defined $buttonType
23692 || defined $check
23693 ) {
23694 return $axmud::CLIENT->writeImproper($self->_objClass . '->showMsgDialogue', @_);
23695 }
23696  
23697 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
23698 # be visible above the new dialogue window)
23699 if ($axmud::CLIENT->busyWin) {
23700  
23701 $self->closeDialogueWin($axmud::CLIENT->busyWin);
23702 }
23703  
23704 # Set the correct spacing size for 'dialogue' windows
23705 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
23706  
23707 # Check that $icon and $buttonType are valid values
23708 if (
23709 $icon ne 'info' && $icon ne 'warning' && $icon ne 'error' && $icon ne 'question'
23710 ) {
23711 return $axmud::CLIENT->writeError(
23712 'Unrecognised value \'' . $icon . '\' for icon argument',
23713 $self->_objClass . '->showMsgDialogue',
23714 );
23715 }
23716  
23717 # Convert $buttonType into an argument list
23718 if ($buttonType eq 'ok') {
23719 @argList = ('gtk-ok', 'ok');
23720 } elsif ($buttonType eq 'close') {
23721 @argList = ('gtk-close', 'close');
23722 } elsif ($buttonType eq 'cancel') {
23723 @argList = ('gtk-cancel', 'cancel');
23724 } elsif ($buttonType eq 'yes-no') {
23725 @argList = ('gtk-no', 'no', 'gtk-yes', 'yes');
23726 } elsif ($buttonType eq 'ok-cancel') {
23727 @argList = ('gtk-cancel', 'cancel', 'gtk-ok', 'ok');
23728 } elsif ($buttonType ne 'none') {
23729  
23730 return $axmud::CLIENT->writeError(
23731 'Unrecognised value \'' . $icon . '\' for button type argument',
23732 $self->_objClass . '->showMsgDialogue',
23733 );
23734 }
23735  
23736 # Show the 'dialogue' window
23737 my $dialogueWin = Gtk3::Dialog->new(
23738 $title,
23739 $self->winWidget,
23740 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
23741 @argList,
23742 );
23743  
23744 $dialogueWin->set_position('center-always');
23745 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
23746  
23747 $dialogueWin->signal_connect('delete-event' => sub {
23748  
23749 $dialogueWin->destroy();
23750 $self->restoreFocus();
23751  
23752 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
23753 # the window is visibly closed)
23754 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showMsgDialogue');
23755 });
23756  
23757 # Set the default response, if specified
23758 if (defined $defaultResponse) {
23759  
23760 $dialogueWin->set_default_response($defaultResponse);
23761 }
23762  
23763 # Add widgets to the 'dialogue' window
23764 my $vBox = $dialogueWin->get_content_area();
23765 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
23766 # Gtk3::VBox on the right, into which we put everything
23767 my $vBox2 = $self->addDialogueIcon(
23768 $vBox,
23769 $axmud::SHARE_DIR . '/icons/replace/dialogue_replace_' . $icon . '.png',
23770 TRUE, # Don't draw the image inside a frame
23771 );
23772  
23773 my $label = Gtk3::Label->new();
23774 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
23775 $label->set_alignment(0, 0);
23776  
23777 # If $text is long, it produces a wider window than was produced in earlier version of Gtk.
23778 # This doesn't look very nice, so split $text into lines with a maximum length
23779 # At the same time, we need to escape any < or > characters, or we'll get a Pango error)
23780 if (! $noSplitFlag) {
23781  
23782 $label->set_markup(
23783 Glib::Markup::escape_text(
23784 $axmud::CLIENT->splitText(
23785 $text,
23786 0, # No maximum rows
23787 $axmud::CLIENT->constDialogueLabelSize,
23788 # Maximum characters per line
23789 FALSE, # No ellipsis required
23790 TRUE, # Don't use hyphens when splitting words
23791 )
23792 ),
23793 );
23794  
23795 } else {
23796  
23797 # Calling function has already added newline characters, so no split required
23798 $label->set_markup(Glib::Markup::escape_text($text));
23799 }
23800  
23801 # For the benefit of visually-impaired users who are using the 'tab' key to switch buttons,
23802 # don't allow the label to receive focus
23803 $label->set_can_focus(FALSE);
23804  
23805 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
23806 # consistently active (don't know why this works; it just does)
23807 $dialogueWin->show_all();
23808 $dialogueWin->present();
23809 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
23810  
23811 # Prepare text-to-speech (TTS) code. Get a hash of possible response buttons, in the form
23812 # $buttonHash{'response'} = Gtk3::Button (if the button is used), or 'undef' (if not)
23813 %buttonHash = (
23814 'ok', $dialogueWin->get_widget_for_response('ok'),
23815 'close', $dialogueWin->get_widget_for_response('close'),
23816 'cancel', $dialogueWin->get_widget_for_response('cancel'),
23817 'yes', $dialogueWin->get_widget_for_response('yes'),
23818 'no', $dialogueWin->get_widget_for_response('no'),
23819 );
23820  
23821 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23822  
23823 # Perform TTS for this window
23824 $axmud::CLIENT->ttsAddUrgentJob($title, 'dialogue');
23825 $axmud::CLIENT->ttsAddUrgentJob($text, 'dialogue');
23826  
23827 foreach my $response (keys %buttonHash) {
23828  
23829 my $button = $buttonHash{$response};
23830  
23831 if (defined $button) {
23832  
23833 # Handy list of responses that are available in this dialogue
23834 push (@list, $response);
23835  
23836 $button->signal_connect('grab-focus' => sub {
23837  
23838 my $label = $button->get_label();
23839  
23840 # $label is in the form 'gtk-yes', 'gtk-no' etc
23841 $axmud::CLIENT->ttsAddUrgentJob(
23842 substr($label, 4) . ' button',
23843 'dialogue',
23844 # Override other TTS urgent jobs, such as the $title and $text above
23845 TRUE,
23846 );
23847 });
23848 }
23849 }
23850  
23851 # (No need to read this message, if there's only one button)
23852 if (@list == 1) {
23853  
23854 $axmud::CLIENT->ttsAddUrgentJob(
23855 $list[0] . ' button selected',
23856 'dialogue',
23857 );
23858  
23859 } else {
23860  
23861 $axmud::CLIENT->ttsAddUrgentJob(
23862 'Select ' . join (', or, ', @list),
23863 'dialogue',
23864 );
23865 }
23866 }
23867 # (end of TTS code)
23868  
23869 # Get the response
23870 $response = $dialogueWin->run();
23871 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23872  
23873 if ($response && exists $buttonHash{$response}) {
23874  
23875 $axmud::CLIENT->ttsAddUrgentJob(
23876 $response . ' selected',
23877 'dialogue',
23878 TRUE,
23879 );
23880  
23881 } else {
23882  
23883 $axmud::CLIENT->ttsAddUrgentJob(
23884 'Cancelled',
23885 'dialogue',
23886 TRUE,
23887 );
23888 }
23889 }
23890  
23891 # Destroy the window and return the response
23892 $dialogueWin->destroy();
23893 $self->restoreFocus();
23894  
23895 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
23896 # window is visibly closed)
23897 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showMsgDialogue');
23898  
23899 return $response;
23900 }
23901  
23902 sub showFileChooser {
23903  
23904 # Can be called by any function
23905 # Creates a standard Gtk3::FileChooserDialog and returns the response (if any)
23906 #
23907 # Expected arguments
23908 # $title - The title of the window, e.g. 'Select file to load'
23909 # $type - 'open', 'save', 'select-folder', 'create-folder'
23910 #
23911 # Optional arguments
23912 # $arg - If $type = 'open', set the current folder (this behaviour is
23913 # discouraged, but it's sometimes appropriate for Axmud code). If
23914 # $type = 'save', suggest a filename using $arg. Ignored if 'undef' or
23915 # if $type is not 'open' or 'save'
23916 #
23917 # Return values
23918 # 'undef' on improper arguments, if $type is invalid, if the file chooser window can't be
23919 # opened or if no file is selected
23920 # Otherwise returns a path to the selected file
23921  
23922 my ($self, $title, $type, $arg, $check) = @_;
23923  
23924 # Local variables
23925 my $fileName;
23926  
23927 # Check for improper arguments
23928 if (! defined $title || ! defined $type || defined $check) {
23929  
23930 return $axmud::CLIENT->writeImproper($self->_objClass . '->showFileChooser', @_);
23931 }
23932  
23933 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
23934 # be visible above the new dialogue window)
23935 if ($axmud::CLIENT->busyWin) {
23936  
23937 $self->closeDialogueWin($axmud::CLIENT->busyWin);
23938 }
23939  
23940 # Check that $type is a valid type
23941 if (
23942 $type ne 'open' && $type ne 'save' && $type ne 'select-folder'
23943 && $type ne 'create-folder'
23944 ) {
23945 return $self->writeError(
23946 'Unrecognised file choose type \'' . $type . '\'',
23947 $self->_objClass . '->showFileChooser',
23948 );
23949 }
23950  
23951 # Open the file chooser window
23952 my $dialogueWin = Gtk3::FileChooserDialog->new(
23953 $title,
23954 $self->winWidget,
23955 $type,
23956 'gtk-cancel' => 'cancel',
23957 'gtk-ok' => 'ok'
23958 );
23959  
23960 if (! $dialogueWin) {
23961  
23962 return undef;
23963 }
23964  
23965 $dialogueWin->set_position('center-always');
23966 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
23967  
23968 $dialogueWin->signal_connect('delete-event' => sub {
23969  
23970 $dialogueWin->destroy();
23971 $self->restoreFocus();
23972 });
23973  
23974 if (defined $arg) {
23975  
23976 # If loading a file, set the current folder
23977 if ($type eq 'open') {
23978  
23979 $dialogueWin->set_current_folder($arg);
23980  
23981 # If saving a file, suggest a filename
23982 } elsif ($type eq 'save' && defined $arg) {
23983  
23984 $dialogueWin->set_current_name($arg);
23985 }
23986 }
23987  
23988 # Get the file
23989 if ($dialogueWin->run eq 'ok') {
23990  
23991 $fileName = $dialogueWin->get_filename();
23992 }
23993  
23994 # Close the window
23995 $dialogueWin->destroy();
23996 $self->restoreFocus();
23997  
23998 # For saving, show a confirmation message
23999 if (defined $fileName){
24000  
24001 if (-f $fileName && $type eq 'save') {
24002  
24003 my $choice = $self->showMsgDialogue(
24004 'Replace existing file',
24005 'question',
24006 'Overwrite existing file ' . $fileName . ' ?',
24007 'yes-no',
24008 );
24009  
24010 # If the user selects 'no', return false
24011 if ($choice eq 'no') {
24012  
24013 return undef;
24014 }
24015 }
24016  
24017 # Return the path of the selected file
24018 return $fileName;
24019  
24020 } else {
24021  
24022 # No file selected
24023 return undef;
24024 }
24025 }
24026  
24027 sub showEntryDialogue {
24028  
24029 # Can be called by any function
24030 # Prompts the user to enter some text into the entry box; returns the response if the 'ok'
24031 # button is pressed, but 'undef' if either the cancel button is pressed or the window is
24032 # closed
24033 #
24034 # Expected arguments
24035 # $title - The title to display, e.g. 'File Save'
24036 # $text - The message to display. Can be pango markup text, or just plain text
24037 #
24038 # Optional arguments
24039 # $maxChars - The maximum number of chars allowed in the entry box (if 'undef', no
24040 # maximum)
24041 # $entryText - The initial text to put in the entry box (if 'undef', no initial text)
24042 # $obscureModeFlag
24043 # - If set to TRUE, text in the entry box is obscured. If set to FALSE (or
24044 # 'undef'), text is visible
24045 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24046 # lines (because the calling function has already added newline
24047 # characters as it requires). If FALSE (or 'undef'), the message
24048 # $text is split into lines of no more than 40 characters
24049 # $singleFlag - Set when called by GA::CLIENT->connectBlind (or by any other code that
24050 # might want to remove the 'Cancel' button). If TRUE, only an 'OK'
24051 # button is used. If FALSE (or 'undef'), both an 'OK' and 'Cancel'
24052 # buttons are used
24053 #
24054 # Return values
24055 # 'undef' on improper arguments or if the user doesn't enter some text
24056 # Otherwise returns the user response (the contents of the entry box)
24057  
24058 my (
24059 $self, $title, $text, $maxChars, $entryText, $obscureModeFlag, $noSplitFlag,
24060 $singleFlag, $check
24061 ) = @_;
24062  
24063 # Local variables
24064 my (
24065 $spacing, $starText, $lastThing, $response, $responseText, $confirmMsg,
24066 %buttonHash,
24067 );
24068  
24069 # Check for improper arguments
24070 if (! defined $title || ! defined $text || defined $check) {
24071  
24072 return $axmud::CLIENT->writeImproper($self->_objClass . '->showEntryDialogue', @_);
24073 }
24074  
24075 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24076 # be visible above the new dialogue window)
24077 if ($axmud::CLIENT->busyWin) {
24078  
24079 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24080 }
24081  
24082 # Set the correct spacing size for 'dialogue' windows
24083 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24084  
24085 # Show the dialogue window
24086 my $dialogueWin;
24087 if ($singleFlag) {
24088  
24089 $dialogueWin = Gtk3::Dialog->new(
24090 $title,
24091 $self->winWidget,
24092 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
24093 'gtk-ok' => 'accept',
24094 );
24095  
24096 } else {
24097  
24098 $dialogueWin = Gtk3::Dialog->new(
24099 $title,
24100 $self->winWidget,
24101 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
24102 'gtk-cancel' => 'reject',
24103 'gtk-ok' => 'accept',
24104 );
24105 }
24106  
24107 $dialogueWin->set_position('center-always');
24108 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24109  
24110 $dialogueWin->signal_connect('delete-event' => sub {
24111  
24112 $dialogueWin->destroy();
24113 $self->restoreFocus();
24114  
24115 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
24116 # the window is visibly closed)
24117 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryDialogue');
24118 });
24119  
24120 # Add widgets to the 'dialogue' window
24121 my $vBox = $dialogueWin->get_content_area();
24122 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24123 # Gtk3::VBox on the right, into which we put everything
24124 my $vBox2 = $self->addDialogueIcon($vBox);
24125  
24126 my $label = Gtk3::Label->new();
24127 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24128 $label->set_alignment(0, 0);
24129 if (! $noSplitFlag) {
24130  
24131 $label->set_markup(
24132 Glib::Markup::escape_text(
24133 $axmud::CLIENT->splitText(
24134 $text,
24135 0, # No maximum rows
24136 $axmud::CLIENT->constDialogueLabelSize,
24137 # Maximum characters per line
24138 FALSE, # No ellipsis required
24139 TRUE, # Don't use hyphens when splitting words
24140 )
24141 ),
24142 );
24143  
24144 } else {
24145  
24146 $label->set_markup(Glib::Markup::escape_text($text));
24147 }
24148  
24149 my $entry = Gtk3::Entry->new();
24150 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
24151 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24152  
24153 $entry->set_max_length($maxChars);
24154 }
24155  
24156 if ($obscureModeFlag) {
24157  
24158 $entry->set_visibility(FALSE);
24159  
24160 if ($entryText) {
24161  
24162 # Set the string to be used to disguise the number of characters in $entryText
24163 $starText = '********';
24164 # Just in case $entryText happens to be the same string, use a different string!
24165 if ($entryText eq $starText) {
24166  
24167 $starText = 'xxxxxxxx';
24168 }
24169  
24170 $entry->set_text($starText);
24171  
24172 } else {
24173  
24174 # (Don't hide the fact that $entryText is an empty string, if it is so)
24175 $starText = '';
24176 }
24177  
24178 } elsif ($entryText) {
24179  
24180 # $obscureModeFlag is not set, so display $entryText
24181 $entry->set_text($entryText);
24182 }
24183  
24184 $entry->signal_connect('button_press_event' => sub {
24185  
24186 # In obscure mode, user can change the entry box's text in two ways - clicking on the
24187 # box itself, in which case this event occurs (and we need to empty the box), or by
24188 # tabbing focus through widgets, until the focus falls onto the box, in which case
24189 # the box is emptied and replaced with the first keypress
24190 if ($obscureModeFlag && defined $starText) {
24191  
24192 $entry->set_text('');
24193 # When this function returns a value (below), we need to know whether the
24194 # obscured text has been modified. Only need to do this once
24195 $starText = undef;
24196 }
24197 });
24198  
24199 $entry->signal_connect('changed' => sub {
24200  
24201 # If the text in the entry box has been modified, then we reset $starText (for the
24202 # reasons described just above)
24203 $starText = undef;
24204 });
24205  
24206 $entry->signal_connect('activate' => sub {
24207  
24208 # Get the entry's text, because the code at the bottom of this function won't be
24209 # able to retrieve it...
24210 $responseText = $entry->get_text();
24211 # ...after we destroy the 'dialogue' window
24212 $dialogueWin->destroy();
24213 $self->restoreFocus();
24214 });
24215  
24216 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
24217 # consistently active (don't know why this works; it just does)
24218 $dialogueWin->show_all();
24219 $dialogueWin->present();
24220 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryDialogue');
24221  
24222 # Prepare text-to-speech (TTS) code. Get a hash of the response buttons, in the form
24223 # $buttonHash{'response'} = Gtk3::Button
24224 $buttonHash{'ok'} = $dialogueWin->get_widget_for_response('accept');
24225 if (! $singleFlag) {
24226  
24227 $buttonHash{'cancel'} = $dialogueWin->get_widget_for_response('reject');
24228 }
24229  
24230 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
24231  
24232 # Perform TTS for this window
24233 $axmud::CLIENT->ttsAddUrgentJob($title, 'dialogue');
24234 $axmud::CLIENT->ttsAddUrgentJob($text, 'dialogue');
24235  
24236 # Read out buttons, when in focus
24237 foreach my $response (keys %buttonHash) {
24238  
24239 my $button = $buttonHash{$response};
24240  
24241 $button->signal_connect('grab-focus' => sub {
24242  
24243 my $label = $button->get_label();
24244  
24245 if (! defined $lastThing || $lastThing ne $button) {
24246  
24247 $axmud::CLIENT->ttsAddUrgentJob(
24248 # ($label is in the form 'gtk-yes', 'gtk-no' etc)
24249 substr($label, 4) . ' button',
24250 'dialogue',
24251 # Override other TTS urgent jobs, such as the $title and $text above
24252 TRUE,
24253 );
24254 }
24255  
24256 # Don't use TTS to read out the same widget consecutively
24257 $lastThing = $button;
24258 });
24259 }
24260  
24261 $entry->signal_connect('grab-focus' => sub {
24262  
24263 # (Don't read anything out the first time, but if the user cycles through the keys
24264 # and returns to the entry, using the tab key, read out something)
24265 if ($lastThing) {
24266  
24267 if (! $entry->get_text()) {
24268  
24269 $axmud::CLIENT->ttsAddUrgentJob(
24270 'Type something here',
24271 'dialogue',
24272 TRUE,
24273 );
24274  
24275 } else {
24276  
24277 $axmud::CLIENT->ttsAddUrgentJob(
24278 'Entered: ' . $entry->get_text(),
24279 'dialogue',
24280 TRUE,
24281 );
24282 }
24283 }
24284  
24285 # Don't use TTS to read out the same widget consecutively
24286 $lastThing = $entry;
24287 });
24288 }
24289  
24290 # Get the response
24291 $response = $dialogueWin->run();
24292 if ($response eq 'accept' || $response eq 'none') {
24293  
24294 # If the user pressed the ENTER key, the entry's ->signal_connect for 'activate' stored
24295 # the entry's text in $responseText, before destroying the window
24296 if (! $responseText) {
24297  
24298 $responseText = $entry->get_text();
24299 }
24300  
24301 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
24302  
24303 if ($obscureModeFlag) {
24304  
24305 $axmud::CLIENT->ttsAddUrgentJob(
24306 'Text accepted',
24307 'dialogue',
24308 TRUE,
24309 );
24310  
24311 } else {
24312  
24313 $axmud::CLIENT->ttsAddUrgentJob(
24314 'Entered: ' . $responseText,
24315 'dialogue',
24316 TRUE,
24317 );
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 . '->showEntryDialogue');
24336  
24337 # Return the response
24338 if ($obscureModeFlag && defined $starText) {
24339  
24340 # The obscured '********' text has not been modified, so we can return the original
24341 # unmodified $entryText
24342 return $entryText;
24343  
24344 } else {
24345  
24346 # Otherwise, return the contents of the entry box
24347 return $responseText;
24348 }
24349 }
24350  
24351 sub showDoubleEntryDialogue {
24352  
24353 # Can be called by any function
24354 # Similar to $self->showEntryDialogue, but contains two entry boxes; returns the contents of
24355 # both boxes
24356 #
24357 # Expected arguments
24358 # $title - The title to display, e.g. 'File Save'
24359 # $labelText - The label above the first entry box. Can be pango markup text, or just
24360 # plain text
24361 #
24362 # Optional arguments
24363 # $labelText2 - The label above the second entry box. If 'undef', no second label is
24364 # used (but the second entry box is still used)
24365 # $maxChars - The maximum number of chars allowed in both entry boxes (if 'undef',
24366 # no maximum)
24367 # $obscureMode - Sets which of the entry boxes has its text obscured
24368 # - 'default' (or 'undef') - no text is obscured
24369 # - 'first' - first box is obscured
24370 # - 'second' - second box is obscured
24371 # - 'both' - both boxes are obscured
24372 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24373 # lines (because the calling function has already added newline
24374 # characters as it requires). If FALSE (or 'undef'), the message
24375 # $text is split into lines of no more than 40 characters
24376 #
24377 # Return values
24378 # An empty list on improper arguments or if the user doesn't enter some text in either
24379 # entry box
24380 # Otherwise a list of two elements, containing the text in both entry boxes
24381  
24382 my (
24383 $self, $title, $labelText, $labelText2, $maxChars, $obscureMode, $noSplitFlag, $check
24384 ) = @_;
24385  
24386 # Local variables
24387 my (
24388 $spacing, $response, $responseText, $responseText2,
24389 @emptyList,
24390 );
24391  
24392 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24393 # be visible above the new dialogue window)
24394 if ($axmud::CLIENT->busyWin) {
24395  
24396 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24397 }
24398  
24399 # Set the correct spacing size for 'dialogue' windows
24400 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24401  
24402 # Check for improper arguments
24403 if (! defined $title || ! defined $labelText || defined $check) {
24404  
24405 $axmud::CLIENT->writeImproper($self->_objClass . '->showDoubleEntryDialogue', @_);
24406 return @emptyList;
24407 }
24408  
24409 # Show the 'dialogue' window
24410 my $dialogueWin = Gtk3::Dialog->new(
24411 $title,
24412 $self->winWidget,
24413 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
24414 'gtk-cancel' => 'reject',
24415 'gtk-ok' => 'accept',
24416 );
24417  
24418 $dialogueWin->set_position('center-always');
24419 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24420  
24421 $dialogueWin->signal_connect('delete-event' => sub {
24422  
24423 $dialogueWin->destroy();
24424 $self->restoreFocus();
24425  
24426 return @emptyList;
24427 });
24428  
24429 # Add widgets to the 'dialogue' window
24430 my $vBox = $dialogueWin->get_content_area();
24431 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24432 # Gtk3::VBox on the right, into which we put everything
24433 my $vBox2 = $self->addDialogueIcon($vBox);
24434  
24435 # First label and entry
24436 my $label = Gtk3::Label->new();
24437 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24438 $label->set_alignment(0, 0);
24439 if (! $noSplitFlag) {
24440  
24441 $label->set_markup(
24442 Glib::Markup::escape_text(
24443 $axmud::CLIENT->splitText(
24444 $labelText,
24445 0, # No maximum rows
24446 $axmud::CLIENT->constDialogueLabelSize,
24447 # Maximum characters per line
24448 FALSE, # No ellipsis required
24449 TRUE, # Don't use hyphens when splitting words
24450 )
24451 ),
24452 );
24453  
24454 } else {
24455  
24456 $label->set_markup(Glib::Markup::escape_text($labelText));
24457 }
24458  
24459 my $entry = Gtk3::Entry->new();
24460 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
24461 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24462  
24463 $entry->set_max_length($maxChars);
24464 }
24465  
24466 # Second label and entry
24467 if ($labelText2) {
24468  
24469 my $label2 = Gtk3::Label->new();
24470 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
24471 $label2->set_alignment(0, 0);
24472  
24473 if (! $noSplitFlag) {
24474  
24475 $label2->set_markup(
24476 Glib::Markup::escape_text(
24477 $axmud::CLIENT->splitText(
24478 $labelText2,
24479 0, # No maximum rows
24480 $axmud::CLIENT->constDialogueLabelSize,
24481 # Maximum characters per line
24482 FALSE, # No ellipsis required
24483 TRUE, # Don't use hyphens when splitting words
24484 )
24485 ),
24486 );
24487  
24488 } else {
24489  
24490 $label2->set_markup(Glib::Markup::escape_text($labelText2));
24491 }
24492 }
24493  
24494 my $entry2 = Gtk3::Entry->new();
24495 $vBox2->pack_start($entry2, FALSE, FALSE, $spacing);
24496 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24497  
24498 $entry2->set_max_length($maxChars);
24499 }
24500  
24501 # Obscure text in the entry boxes, if necessary
24502 if ($obscureMode && $obscureMode ne 'default') {
24503  
24504 if ($obscureMode eq 'first' || $obscureMode eq 'both') {
24505  
24506 $entry->set_visibility(FALSE);
24507 }
24508  
24509 if ($obscureMode eq 'second' || $obscureMode eq 'both') {
24510  
24511 $entry2->set_visibility(FALSE);
24512 }
24513 }
24514  
24515 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
24516 # consistently active (don't know why this works; it just does)
24517 $dialogueWin->show_all();
24518 $dialogueWin->present();
24519 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showDoubleEntryDialogue');
24520  
24521 # Get the response. If the user clicked 'cancel', $response will be 'reject'
24522 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
24523 $response = $dialogueWin->run();
24524 if ($response eq 'accept') {
24525  
24526 $responseText = $entry->get_text();
24527 $responseText2 = $entry2->get_text();
24528  
24529 # Destroy the window
24530 $dialogueWin->destroy();
24531 $self->restoreFocus();
24532  
24533 # Return the response
24534 return ($responseText, $responseText2);
24535  
24536 } else {
24537  
24538 # Destroy the window
24539 $dialogueWin->destroy();
24540 $self->restoreFocus();
24541  
24542 # Return the response
24543 return @emptyList;
24544 }
24545 }
24546  
24547 sub showTripleEntryDialogue {
24548  
24549 # Can be called by any function
24550 # Similar to $self->showEntryDialogue, but contains three entry boxes; returns the contents
24551 # of all three boxes
24552 #
24553 # Expected arguments
24554 # $title - The title to display, e.g. 'File Save'
24555 # $labelText - The label above the first entry box. Can be pango markup text, or just
24556 # plain text
24557 #
24558 # Optional arguments
24559 # $labelText2 - The label above the second entry box. If 'undef', no second label is
24560 # used (but the second entry box is still used)
24561 # $labelText3 - The label above the third entry box. If 'undef', no third label is
24562 # used (but the third entry box is still used)
24563 # $maxChars - The maximum number of chars allowed in all entry boxes (if 'undef',
24564 # no maximum)
24565 # $obscureMode - Sets which of the entry boxes has its text obscured
24566 # - 0 (or 'undef') - no text is obscured (000)
24567 # - 1 - first box is obscured (001)
24568 # - 2 - second box is obscured (010)
24569 # - 3 - first/second boxes are obscured (011)
24570 # - 4 - third box is obscured (100)
24571 # - 5 - first/third boxes are obscured (101)
24572 # - 6 - second/third boxes are obscured (110)
24573 # - 7 - all boxes are obscured (111)
24574 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24575 # lines (because the calling function has already added newline
24576 # characters as it requires). If FALSE (or 'undef'), the message
24577 # $text is split into lines of no more than 40 characters
24578 #
24579 # Return values
24580 # An empty list on improper arguments or if the user doesn't enter some text in either
24581 # entry box
24582 # Otherwise a list of three elements, containing the text in both entry boxes
24583  
24584 my (
24585 $self, $title, $labelText, $labelText2, $labelText3, $maxChars, $obscureMode,
24586 $noSplitFlag, $check,
24587 ) = @_;
24588  
24589 # Local variables
24590 my (
24591 $spacing, $response, $responseText, $responseText2, $responseText3,
24592 @emptyList,
24593 );
24594  
24595 # Check for improper arguments
24596 if (! defined $title || ! defined $labelText || defined $check) {
24597  
24598 $axmud::CLIENT->writeImproper($self->_objClass . '->showTripleEntryDialogue', @_);
24599 return @emptyList;
24600 }
24601  
24602 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24603 # be visible above the new dialogue window)
24604 if ($axmud::CLIENT->busyWin) {
24605  
24606 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24607 }
24608  
24609 # Set the correct spacing size for 'dialogue' windows
24610 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24611  
24612 # Show the 'dialogue' window
24613 my $dialogueWin = Gtk3::Dialog->new(
24614 $title,
24615 $self->winWidget,
24616 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
24617 'gtk-cancel' => 'reject',
24618 'gtk-ok' => 'accept',
24619 );
24620  
24621 $dialogueWin->set_position('center-always');
24622 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24623  
24624 $dialogueWin->signal_connect('delete-event' => sub {
24625  
24626 $dialogueWin->destroy();
24627 $self->restoreFocus();
24628  
24629 return @emptyList;
24630 });
24631  
24632 # Add widgets to the 'dialogue' window
24633 my $vBox = $dialogueWin->get_content_area();
24634 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24635 # Gtk3::VBox on the right, into which we put everything
24636 my $vBox2 = $self->addDialogueIcon($vBox);
24637  
24638 # First label and entry
24639 my $label = Gtk3::Label->new();
24640 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24641 $label->set_alignment(0, 0);
24642 if (! $noSplitFlag) {
24643  
24644 $label->set_markup(
24645 Glib::Markup::escape_text(
24646 $axmud::CLIENT->splitText(
24647 $labelText,
24648 0, # No maximum rows
24649 $axmud::CLIENT->constDialogueLabelSize,
24650 # Maximum characters per line
24651 FALSE, # No ellipsis required
24652 TRUE, # Don't use hyphens when splitting words
24653 )
24654 ),
24655 );
24656  
24657 } else {
24658  
24659 $label->set_markup(Glib::Markup::escape_text($labelText));
24660 }
24661  
24662 my $entry = Gtk3::Entry->new();
24663 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
24664 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24665  
24666 $entry->set_max_length($maxChars);
24667 }
24668  
24669 # Second label and entry
24670 if ($labelText2) {
24671  
24672 my $label2 = Gtk3::Label->new();
24673 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
24674 $label2->set_alignment(0, 0);
24675  
24676 if (! $noSplitFlag) {
24677  
24678 $label2->set_markup(
24679 Glib::Markup::escape_text(
24680 $axmud::CLIENT->splitText(
24681 $labelText2,
24682 0, # No maximum rows
24683 $axmud::CLIENT->constDialogueLabelSize,
24684 # Maximum characters per line
24685 FALSE, # No ellipsis required
24686 TRUE, # Don't use hyphens when splitting words
24687 )
24688 ),
24689 );
24690  
24691 } else {
24692  
24693 $label2->set_markup(Glib::Markup::escape_text($labelText2));
24694 }
24695 }
24696  
24697 my $entry2 = Gtk3::Entry->new();
24698 $vBox2->pack_start($entry2, FALSE, FALSE, $spacing);
24699 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24700  
24701 $entry2->set_max_length($maxChars);
24702 }
24703  
24704 # Third label and entry
24705 if ($labelText3) {
24706  
24707 my $label3 = Gtk3::Label->new();
24708 $vBox2->pack_start($label3, FALSE, FALSE, $spacing);
24709 $label3->set_alignment(0, 0);
24710  
24711 if (! $noSplitFlag) {
24712  
24713 $label3->set_markup(
24714 Glib::Markup::escape_text(
24715 $axmud::CLIENT->splitText(
24716 $labelText3,
24717 0, # No maximum rows
24718 $axmud::CLIENT->constDialogueLabelSize,
24719 # Maximum characters per line
24720 FALSE, # No ellipsis required
24721 TRUE, # Don't use hyphens when splitting words
24722 )
24723 ),
24724 );
24725  
24726 } else {
24727  
24728 $label3->set_markup(Glib::Markup::escape_text($labelText3));
24729 }
24730 }
24731  
24732 my $entry3 = Gtk3::Entry->new();
24733 $vBox2->pack_start($entry3, FALSE, FALSE, $spacing);
24734 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24735  
24736 $entry3->set_max_length($maxChars);
24737 }
24738  
24739 # Obscure text in the entry boxes, if necessary
24740 if ($obscureMode) {
24741  
24742 if ($obscureMode == 1 || $obscureMode == 3 || $obscureMode == 5 || $obscureMode == 7) {
24743  
24744 $entry->set_visibility(FALSE);
24745 }
24746  
24747 if ($obscureMode == 2 || $obscureMode == 3 || $obscureMode >= 6) {
24748  
24749 $entry2->set_visibility(FALSE);
24750 }
24751  
24752 if ($obscureMode >= 4) {
24753  
24754 $entry3->set_visibility(FALSE);
24755 }
24756 }
24757  
24758 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
24759 # consistently active (don't know why this works; it just does)
24760 $dialogueWin->show_all();
24761 $dialogueWin->present();
24762 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showTripleComboDialogue');
24763  
24764 # Get the responses. If the user clicked 'cancel', $response will be 'reject'
24765 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
24766 $response = $dialogueWin->run();
24767 if ($response eq 'accept') {
24768  
24769 $responseText = $entry->get_text();
24770 $responseText2 = $entry2->get_text();
24771 $responseText3 = $entry3->get_text();
24772  
24773 # Destroy the window
24774 $dialogueWin->destroy();
24775 $self->restoreFocus();
24776  
24777 # Return the response
24778 return ($responseText, $responseText2, $responseText3);
24779  
24780 } else {
24781  
24782 # Destroy the window
24783 $dialogueWin->destroy();
24784 $self->restoreFocus();
24785  
24786 # Return the response
24787 return @emptyList;
24788 }
24789 }
24790  
24791 sub showComboDialogue {
24792  
24793 # Can be called by any function
24794 # Shows a short message in a 'dialogue' window with the buttons 'ok' and 'cancel'
24795 # Prompts the user to choose a line from a combobox; returns the chosen line if the 'ok'
24796 # button is pressed, but 'undef' if either the cancel button is pressed or the window is
24797 # closed
24798 #
24799 # Expected arguments
24800 # $title - The title to display, e.g. 'File Save'
24801 # $text - The message to display. Can be pango markup text, or just plain text
24802 #
24803 # Optional arguments
24804 # $listRef - Reference to a list of scalars to be used in the combo box. If
24805 # 'undef', the combo box will be empty
24806 # $singleFlag - Set when called by GA::CLIENT->connectBlind (or by any other code that
24807 # might want to remove the 'Cancel' button). If TRUE, only an 'OK'
24808 # button is used. If FALSE (or 'undef'), both an 'OK' and 'Cancel'
24809 # buttons are used
24810 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24811 # lines (because the calling function has already added newline
24812 # characters as it requires). If FALSE (or 'undef'), the message
24813 # $text is split into lines of no more than 40 characters
24814 #
24815 # Return values
24816 # 'undef' on improper arguments, if the user doesn't choose a line or if @lineList is
24817 # empty
24818 # Otherwise returns the user response (the text of the selected line)
24819  
24820 my ($self, $title, $text, $listRef, $singleFlag, $noSplitFlag, $check) = @_;
24821  
24822 # Local variables
24823 my (
24824 $spacing, $lastThing, $response, $responseText,
24825 %buttonHash,
24826 );
24827  
24828 # Check for improper arguments
24829 if (! defined $title || ! defined $text || defined $check) {
24830  
24831 return $axmud::CLIENT->writeImproper($self->_objClass . '->showComboDialogue', @_);
24832 }
24833  
24834 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24835 # be visible above the new dialogue window)
24836 if ($axmud::CLIENT->busyWin) {
24837  
24838 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24839 }
24840  
24841 # Set the correct spacing size for 'dialogue' windows
24842 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24843  
24844 # If $listRef was not specified, use an empty list
24845 if (! defined $listRef) {
24846  
24847 @$listRef = ();
24848 }
24849  
24850 # Show the 'dialogue' window. If $listRef is empty, don't show a 'cancel' button
24851 my $dialogueWin;
24852 if (! @$listRef || $singleFlag) {
24853  
24854 $dialogueWin = Gtk3::Dialog->new(
24855 $title,
24856 $self->winWidget,
24857 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
24858 'gtk-ok' => 'accept',
24859 );
24860  
24861 } else {
24862  
24863 $dialogueWin = Gtk3::Dialog->new(
24864 $title,
24865 $self->winWidget,
24866 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
24867 'gtk-cancel' => 'reject',
24868 'gtk-ok' => 'accept',
24869 );
24870 }
24871  
24872 $dialogueWin->set_position('center-always');
24873 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24874  
24875 $dialogueWin->signal_connect('delete-event' => sub {
24876  
24877 $dialogueWin->destroy();
24878 $self->restoreFocus();
24879  
24880 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
24881 # the window is visibly closed)
24882 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
24883 });
24884  
24885 # Add widgets to the 'dialogue' window
24886 my $vBox = $dialogueWin->get_content_area();
24887 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24888 # Gtk3::VBox on the right, into which we put everything
24889 my $vBox2 = $self->addDialogueIcon($vBox);
24890  
24891 my $label = Gtk3::Label->new();
24892 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24893 $label->set_alignment(0, 0);
24894  
24895 if (! $noSplitFlag) {
24896  
24897 $label->set_markup(
24898 Glib::Markup::escape_text(
24899 $axmud::CLIENT->splitText(
24900 $text,
24901 0, # No maximum rows
24902 $axmud::CLIENT->constDialogueLabelSize,
24903 # Maximum characters per line
24904 FALSE, # No ellipsis required
24905 TRUE, # Don't use hyphens when splitting words
24906 )
24907 ),
24908 );
24909  
24910 } else {
24911  
24912 $label->set_markup(Glib::Markup::escape_text($text));
24913 }
24914  
24915 my $comboBox = Gtk3::ComboBoxText->new();
24916 $vBox2->pack_start($comboBox, FALSE, FALSE, $spacing);
24917 # Fill the combobox with the specified lines, and display the first line
24918 foreach my $line (@$listRef) {
24919  
24920 $comboBox->append_text($line);
24921 }
24922 $comboBox->set_active(0);
24923  
24924 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
24925 # consistently active (don't know why this works; it just does)
24926 $dialogueWin->show_all();
24927 $dialogueWin->present();
24928 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
24929  
24930 # Prepare text-to-speech (TTS) code. Get a hash of the response buttons, in the form
24931 # $buttonHash{'response'} = Gtk3::Button
24932 $buttonHash{'ok'} = $dialogueWin->get_widget_for_response('accept');
24933 if (@$listRef && ! $singleFlag) {
24934  
24935 $buttonHash{'cancel'} = $dialogueWin->get_widget_for_response('reject');
24936 }
24937  
24938 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
24939  
24940 # Perform TTS for this window
24941 $axmud::CLIENT->ttsAddUrgentJob($title, 'dialogue');
24942 $axmud::CLIENT->ttsAddUrgentJob($text, 'dialogue');
24943  
24944 # Read out buttons, when in focus
24945 foreach my $response (keys %buttonHash) {
24946  
24947 my $button = $buttonHash{$response};
24948  
24949 $button->signal_connect('grab-focus' => sub {
24950  
24951 my $label = $button->get_label();
24952  
24953 if (! defined $lastThing || $lastThing ne $button) {
24954  
24955 $axmud::CLIENT->ttsAddUrgentJob(
24956 # ($label is in the form 'gtk-yes', 'gtk-no' etc)
24957 substr($label, 4) . ' button',
24958 'dialogue',
24959 # Override other TTS urgent jobs, such as the $title and $text above
24960 TRUE,
24961 );
24962 }
24963  
24964 # Don't use TTS to read out the same button label consecutively
24965 $lastThing = $button;
24966 });
24967 }
24968  
24969 # Intercept page up/page down, and make it skip 10 lines, rather than going to the
24970 # top/bottom
24971 $comboBox->signal_connect('key-press-event' => sub {
24972  
24973 my ($widget, $event) = @_;
24974  
24975 # Local variables
24976 my ($keycode, $standard, $index);
24977  
24978 # Get the system keycode for this keypress
24979 $keycode = Gtk3::Gdk::keyval_name($event->keyval);
24980 # Translate it into a standard Axmud keycode
24981 $standard = $axmud::CLIENT->reverseKeycode($keycode);
24982  
24983 if ($standard eq 'page_up' || $standard eq 'page_down') {
24984  
24985 $index = $comboBox->get_active();
24986 if ($index > -1) {
24987  
24988 if ($standard eq 'page_up') {
24989  
24990 $index -= 10;
24991 if ($index < 0) {
24992  
24993 $index = 0;
24994 }
24995  
24996 } else {
24997  
24998 $index += 10;
24999 if ($index >= (scalar @$listRef)) {
25000  
25001 $index = (scalar @$listRef) - 1;
25002 }
25003 }
25004  
25005 $comboBox->set_active($index);
25006  
25007 # Return 1 to show that we have interfered with this keypress
25008 return 1;
25009 }
25010 }
25011  
25012 # Return 'undef' to show that we haven't interfered with this keypress
25013 return undef;
25014 });
25015  
25016 # Read out selected items
25017 $comboBox->signal_connect('key-release-event' => sub {
25018  
25019 my $text = $comboBox->get_active_text();
25020  
25021 # (Use tab/cursor keys to nagivate the widgets)
25022 if (! defined $lastThing || $lastThing ne $text) {
25023  
25024 $axmud::CLIENT->ttsAddUrgentJob(
25025 $text . ' selected',
25026 'dialogue',
25027 TRUE,
25028 );
25029 }
25030  
25031 # Don't use TTS to read out the same combo item consecutively
25032 $lastThing = $text;
25033  
25034 return undef;
25035 });
25036  
25037 $comboBox->signal_connect('changed' => sub {
25038  
25039 my $text = $comboBox->get_active_text();
25040  
25041 # (Use the mouse to focus on the combobox)
25042 if (! defined $lastThing || $lastThing ne $text) {
25043  
25044 $axmud::CLIENT->ttsAddUrgentJob(
25045 $text . ' selected',
25046 'dialogue',
25047 TRUE,
25048 );
25049 }
25050  
25051 # Don't use TTS to read out the same combo item consecutively
25052 $lastThing = $text;
25053  
25054 return undef;
25055 });
25056  
25057 # Make sure that the first item in the combobox has been read out
25058 if (! defined $lastThing || (@$listRef && $lastThing ne $$listRef[0])) {
25059  
25060 if (@$listRef) {
25061  
25062 $axmud::CLIENT->ttsAddUrgentJob(
25063 $$listRef[0] . ' selected',
25064 'dialogue',
25065 );
25066  
25067 } else {
25068  
25069 $axmud::CLIENT->ttsAddUrgentJob(
25070 'There is nothing to select',
25071 'dialogue',
25072 );
25073 }
25074 }
25075  
25076 # Don't use TTS to read out the same combo item consecutively
25077 if (@$listRef) {
25078  
25079 $lastThing = $$listRef[0];
25080 }
25081 }
25082  
25083 # Get the response
25084 $response = $dialogueWin->run();
25085 if ($response eq 'accept') {
25086  
25087 $responseText = $comboBox->get_active_text();
25088  
25089 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
25090  
25091 $axmud::CLIENT->ttsAddUrgentJob(
25092 $responseText . ' entered',
25093 'dialogue',
25094 TRUE,
25095 );
25096 }
25097  
25098 } else {
25099  
25100 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
25101  
25102 $axmud::CLIENT->ttsAddUrgentJob('Cancelled', 'dialogue', TRUE);
25103 }
25104 }
25105  
25106 # Destroy the window
25107 $dialogueWin->destroy();
25108 $self->restoreFocus();
25109  
25110 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
25111 # window is visibly closed)
25112 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
25113  
25114 return $responseText;
25115 }
25116  
25117 sub showDoubleComboDialogue {
25118  
25119 # Can be called by any function
25120 # Similar to $self->showDoubleEntryDialogue, but contains two combo boxes; returns the
25121 # contents of both boxes
25122 #
25123 # Expected arguments
25124 # $title - The title to display, e.g. 'File Save'
25125 #
25126 # Optional arguments
25127 # $labelText - The label above the first combo box. Can be pango markup text, or just
25128 # plain text. If 'undef', no first label is used (but the combo box is
25129 # still used)
25130 # $labelText2 - The label above the second combo box. If 'undef', no second label is
25131 # used (but the combo box is still used)
25132 # $listRef - Reference to a list of scalars to be used in the first combo box. If
25133 # 'undef', the first combo box will be empty
25134 # $listRef2 - Reference to a list of scalars to be used in the second combo box. If
25135 # 'undef', the second combo box will be empty
25136 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
25137 # lines (because the calling function has already added newline
25138 # characters as it requires). If FALSE (or 'undef'), the message
25139 # $text is split into lines of no more than 40 characters
25140 #
25141 # Return values
25142 # An empty list on improper arguments
25143 # Otherwise a list of two elements, containing the contents of the two combo boxes
25144  
25145 my ($self, $title, $labelText, $labelText2, $listRef, $listRef2, $noSplitFlag, $check) = @_;
25146  
25147 # Local variables
25148 my (
25149 $spacing, $response, $responseText, $responseText2,
25150 @emptyList,
25151 );
25152  
25153 # Check for improper arguments
25154 if (! defined $title || defined $check) {
25155  
25156 $axmud::CLIENT->writeImproper($self->_objClass . '->showDoubleComboDialogue', @_);
25157 return @emptyList;
25158 }
25159  
25160 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
25161 # be visible above the new dialogue window)
25162 if ($axmud::CLIENT->busyWin) {
25163  
25164 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25165 }
25166  
25167 # Set the correct spacing size for 'dialogue' windows
25168 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
25169  
25170 # If $listRef/$listRef2 were not specified, use empty lists
25171 if (! defined $listRef) {
25172  
25173 @$listRef = ();
25174 }
25175  
25176 if (! defined $listRef2) {
25177  
25178 @$listRef2 = ();
25179 }
25180  
25181 # Show the 'dialogue' window
25182 my $dialogueWin = Gtk3::Dialog->new(
25183 $title,
25184 $self->winWidget,
25185 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
25186 'gtk-cancel' => 'reject',
25187 'gtk-ok' => 'accept',
25188 );
25189  
25190 $dialogueWin->set_position('center-always');
25191 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25192  
25193 $dialogueWin->signal_connect('delete-event' => sub {
25194  
25195 $dialogueWin->destroy();
25196 $self->restoreFocus();
25197  
25198 return @emptyList;
25199 });
25200  
25201 # Add widgets to the 'dialogue' window
25202 my $vBox = $dialogueWin->get_content_area();
25203 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
25204 # Gtk3::VBox on the right, into which we put everything
25205 my $vBox2 = $self->addDialogueIcon($vBox);
25206  
25207 # First label (optional) and combo (not optional)
25208 my $label;
25209 if ($labelText) {
25210  
25211 $label = Gtk3::Label->new();
25212 $label->set_alignment(0, 0);
25213  
25214 if (! $noSplitFlag) {
25215  
25216 $label->set_markup(
25217 Glib::Markup::escape_text(
25218 $axmud::CLIENT->splitText(
25219 $labelText,
25220 0, # No maximum rows
25221 $axmud::CLIENT->constDialogueLabelSize,
25222 # Maximum characters per line
25223 FALSE, # No ellipsis required
25224 TRUE, # Don't use hyphens when splitting words
25225 )
25226 ),
25227 );
25228  
25229 } else {
25230  
25231 $label->set_markup(Glib::Markup::escape_text($labelText));
25232 }
25233  
25234 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
25235 }
25236  
25237 my $combo = Gtk3::ComboBoxText->new();
25238 $vBox2->pack_start($combo, FALSE, FALSE, $spacing);
25239  
25240 # Fill the combo box with the specified lines, and display the first line
25241 if (@$listRef) {
25242  
25243 foreach my $line (@$listRef) {
25244  
25245 $combo->append_text($line);
25246 }
25247  
25248 $combo->set_active(0);
25249 }
25250  
25251 # Second label (optional) and combo (not optional)
25252 my $label2;
25253 if ($labelText2) {
25254  
25255 $label2 = Gtk3::Label->new();
25256 $label2->set_alignment(0, 0);
25257  
25258 if (! $noSplitFlag) {
25259  
25260 $label2->set_markup(
25261 Glib::Markup::escape_text(
25262 $axmud::CLIENT->splitText(
25263 $labelText2,
25264 0, # No maximum rows
25265 $axmud::CLIENT->constDialogueLabelSize,
25266 # Maximum characters per line
25267 FALSE, # No ellipsis required
25268 TRUE, # Don't use hyphens when splitting words
25269 )
25270 ),
25271 );
25272  
25273 } else {
25274  
25275 $label2->set_markup(Glib::Markup::escape_text($labelText2));
25276 }
25277  
25278 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
25279 }
25280  
25281 my $combo2 = Gtk3::ComboBoxText->new();
25282 $vBox2->pack_start($combo2, FALSE, FALSE, $spacing);
25283  
25284 # Fill the combo box with the specified lines, and display the first line
25285 if (@$listRef2) {
25286  
25287 foreach my $line (@$listRef2) {
25288  
25289 $combo2->append_text($line);
25290 }
25291  
25292 $combo2->set_active(0);
25293 }
25294  
25295 # Display the 'dialogue' window
25296 $dialogueWin->show_all();
25297 $dialogueWin->present();
25298  
25299 # Get the response. If the user clicked 'cancel', $response will be 'reject'
25300 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
25301 $response = $dialogueWin->run();
25302 if ($response eq 'accept') {
25303  
25304 $responseText = $combo->get_active_text();
25305 $responseText2 = $combo2->get_active_text();
25306  
25307 # Destroy the window
25308 $dialogueWin->destroy();
25309 $self->restoreFocus();
25310  
25311 # Return the response
25312 return ($responseText, $responseText2);
25313  
25314 } else {
25315  
25316 # Destroy the window
25317 $dialogueWin->destroy();
25318 $self->restoreFocus();
25319  
25320 # Return the response
25321 return @emptyList;
25322 }
25323 }
25324  
25325 sub showEntryComboDialogue {
25326  
25327 # Can be called by any function
25328 # Similar to $self->showDoubleEntryDialogue, but contains an entry box above a combo box;
25329 # returns the contents of both boxes
25330 # Optionally displays a combo above an entry box, but note that the order of the arguments
25331 # remains unchanged
25332 #
25333 # Expected arguments
25334 # $title - The title to display, e.g. 'File Save'
25335 #
25336 # Optional arguments
25337 # $labelText - The label above the entry box. Can be pango markup text, or just plain
25338 # text. If 'undef', no first label is used (but the entry box is still
25339 # used)
25340 # $labelText2 - The label above the combo box. If 'undef', no second label is used
25341 # (but the combo box is still used)
25342 # $listRef - Reference to a list of scalars to be used in the combo box. If
25343 # 'undef', the combo box will be empty
25344 # $maxChars - The maximum number of chars allowed in the entry box (if 'undef', no
25345 # maximum)
25346 # $reverseFlag - If set to TRUE, shows a combo above an entry box; if set to FALSE (or
25347 # 'undef'), shows an entry above a combo box
25348 # $quickFlag - If set to TRUE, pressing the ENTER key while the cursor is in the
25349 # entry box closes the window; FALSE or 'undef' if the user must
25350 # actually click the 'OK' or 'Cancel' buttons
25351 # buttons are used
25352 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
25353 # lines (because the calling function has already added newline
25354 # characters as it requires). If FALSE (or 'undef'), the message
25355 # $text is split into lines of no more than 40 characters
25356 #
25357 # Return values
25358 # An empty list on improper arguments or if the user doesn't enter some text in the entry
25359 # box
25360 # Otherwise a list of two elements, containing the contents of the entry box and the
25361 # active contents of the combo box
25362  
25363 my (
25364 $self, $title, $labelText, $labelText2, $listRef, $maxChars, $reverseFlag, $quickFlag,
25365 $noSplitFlag, $check,
25366 ) = @_;
25367  
25368 # Local variables
25369 my (
25370 $spacing, $response, $responseText, $responseText2,
25371 @emptyList,
25372 );
25373  
25374 # Check for improper arguments
25375 if (! defined $title || defined $check) {
25376  
25377 $axmud::CLIENT->writeImproper($self->_objClass . '->showEntryComboDialogue', @_);
25378 return @emptyList;
25379 }
25380  
25381 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
25382 # be visible above the new dialogue window)
25383 if ($axmud::CLIENT->busyWin) {
25384  
25385 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25386 }
25387  
25388 # Set the correct spacing size for 'dialogue' windows
25389 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
25390  
25391 # If $listRef was not specified, use an empty list
25392 if (! defined $listRef) {
25393  
25394 @$listRef = ();
25395 }
25396  
25397 # Show the 'dialogue' window
25398 my $dialogueWin = Gtk3::Dialog->new(
25399 $title,
25400 $self->winWidget,
25401 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
25402 'gtk-cancel' => 'reject',
25403 'gtk-ok' => 'accept',
25404 );
25405  
25406 $dialogueWin->set_position('center-always');
25407 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25408  
25409 $dialogueWin->signal_connect('delete-event' => sub {
25410  
25411 $dialogueWin->destroy();
25412 $self->restoreFocus();
25413  
25414 return @emptyList;
25415 });
25416  
25417 # Add widgets to the 'dialogue' window
25418 my $vBox = $dialogueWin->get_content_area();
25419 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
25420 # Gtk3::VBox on the right, into which we put everything
25421 my $vBox2 = $self->addDialogueIcon($vBox);
25422  
25423 # First label (optional) and entry (not optional)
25424 my $label;
25425 if ($labelText) {
25426  
25427 $label = Gtk3::Label->new();
25428 $label->set_alignment(0, 0);
25429  
25430 if (! $noSplitFlag) {
25431  
25432 $label->set_markup(
25433 Glib::Markup::escape_text(
25434 $axmud::CLIENT->splitText(
25435 $labelText,
25436 0, # No maximum rows
25437 $axmud::CLIENT->constDialogueLabelSize,
25438 # Maximum characters per line
25439 FALSE, # No ellipsis required
25440 TRUE, # Don't use hyphens when splitting words
25441 )
25442 ),
25443 );
25444  
25445 } else {
25446  
25447 $label->set_markup(Glib::Markup::escape_text($labelText));
25448 }
25449  
25450 }
25451  
25452 my $entry = Gtk3::Entry->new();
25453 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
25454  
25455 $entry->set_max_length($maxChars);
25456 }
25457  
25458 # Second label (optional) and combo (not optional)
25459 my $label2;
25460 if ($labelText2) {
25461  
25462 $label2 = Gtk3::Label->new();
25463 $label2->set_alignment(0, 0);
25464  
25465 if (! $noSplitFlag) {
25466  
25467 $label2->set_markup(
25468 Glib::Markup::escape_text(
25469 $axmud::CLIENT->splitText(
25470 $labelText2,
25471 0, # No maximum rows
25472 $axmud::CLIENT->constDialogueLabelSize,
25473 # Maximum characters per line
25474 FALSE, # No ellipsis required
25475 TRUE, # Don't use hyphens when splitting words
25476 )
25477 ),
25478 );
25479  
25480 } else {
25481  
25482 $label2->set_markup(Glib::Markup::escape_text($labelText2));
25483 }
25484 }
25485  
25486 my $combo = Gtk3::ComboBoxText->new();
25487 # Fill the combo box with the specified lines, and display the first line
25488 if (@$listRef) {
25489  
25490 foreach my $line (@$listRef) {
25491  
25492 $combo->append_text($line);
25493 }
25494  
25495 $combo->set_active(0);
25496 }
25497  
25498 # Arrange the entry and combo in the specified order
25499 if (! $reverseFlag) {
25500  
25501 if ($labelText) {
25502  
25503 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
25504 }
25505  
25506 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
25507  
25508 if ($labelText2) {
25509  
25510 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
25511 }
25512  
25513 $vBox2->pack_start($combo, FALSE, FALSE, $spacing);
25514  
25515 } else {
25516  
25517 if ($labelText2) {
25518  
25519 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
25520 }
25521  
25522 $vBox2->pack_start($combo, FALSE, FALSE, $spacing);
25523  
25524 if ($labelText) {
25525  
25526 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
25527 }
25528  
25529 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
25530 }
25531  
25532 if ($quickFlag) {
25533  
25534 $entry->signal_connect('activate' => sub {
25535  
25536 $responseText = $entry->get_text();
25537 $responseText2 = $combo->get_active_text();
25538  
25539 # Destroy the window
25540 $dialogueWin->destroy();
25541 });
25542 }
25543  
25544 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
25545 # consistently active (don't know why this works; it just does)
25546 $dialogueWin->show_all();
25547 $dialogueWin->present();
25548 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryComboDialogue');
25549  
25550 # Get the response. If the user clicked 'cancel', $response will be 'reject'
25551 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
25552 $response = $dialogueWin->run();
25553 if (defined $responseText) {
25554  
25555 # (User pressed their ENTER key when $quickFlag is TRUE)
25556  
25557 # Destroy the window
25558 $dialogueWin->destroy();
25559 $self->restoreFocus();
25560  
25561 # Return the response
25562 return ($responseText, $responseText2);
25563  
25564 } elsif ($response eq 'accept' || defined $responseText) {
25565  
25566 $responseText = $entry->get_text();
25567 $responseText2 = $combo->get_active_text();
25568  
25569 # Destroy the window
25570 $dialogueWin->destroy();
25571 $self->restoreFocus();
25572  
25573 # Return the response
25574 return ($responseText, $responseText2);
25575  
25576 } else {
25577  
25578 # Destroy the window
25579 $dialogueWin->destroy();
25580 $self->restoreFocus();
25581  
25582 # Return the response
25583 return @emptyList;
25584 }
25585 }
25586  
25587 sub showColourSelectionDialogue {
25588  
25589 # Can be called by any function
25590 # Creates a standard Gtk3::ColorSelectionDialog and returns the response (if any)
25591 #
25592 # Expected arguments
25593 # $title - The title to display, e.g. 'Select colour'
25594 #
25595 # Optional arguments
25596 # $initialColour - The initial colour to use, in the form '#FFFFFF'. If not specified,
25597 # the dialogue's default colour ('#FFFFFF') is used
25598 #
25599 # Return values
25600 # 'undef' on expected arguments or if the user doesn't close the 'dialogue' window by
25601 # clicking the 'ok' button
25602 # Otherwise, returns the colour selected, in the form '#FFFFFF'
25603  
25604 my ($self, $title, $initialColour, $check) = @_;
25605  
25606 # Local variables
25607 my ($colorSelectionObj, $red, $green, $blue, $colorObj, $response, $hex);
25608  
25609 # Check for improper arguments
25610 if (! defined $title || defined $check) {
25611  
25612 return $axmud::CLIENT->writeImproper(
25613 $self->_objClass . '->showColourSelectionDialogue',
25614 @_,
25615 );
25616 }
25617  
25618 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
25619 # be visible above the new dialogue window)
25620 if ($axmud::CLIENT->busyWin) {
25621  
25622 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25623 }
25624  
25625 # Show the 'dialogue' window
25626 my $dialogueWin = Gtk3::ColorSelectionDialog->new($title);
25627 $dialogueWin->set_transient_for($self->winWidget);
25628  
25629 $dialogueWin->set_position('center-always');
25630 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25631  
25632 $colorSelectionObj = $dialogueWin->get_color_selection();
25633  
25634 if ($initialColour) {
25635  
25636 # Split a string like '#FFFFFF' into three seperate colours (red, green and blue),
25637 # convert them to decimals (in the range 0-255), and then convert that to a range of
25638 # 0-65535 - which is what Gtk3::Gdk::Color expects
25639 $red = hex(substr($initialColour, 1, 2)) * 257;
25640 $green = hex(substr($initialColour, 3, 2)) * 257;
25641 $blue = hex(substr($initialColour, 5, 2)) * 257;
25642  
25643 $colorObj = Gtk3::Gdk::Color->new($red, $green, $blue, 0);
25644  
25645 # Tell the Gtk3::ColorSelectionDialog to use this colour, initially
25646 $colorSelectionObj->set_current_color($colorObj);
25647 }
25648  
25649 # Get the response
25650 $response = $dialogueWin->run();
25651 if ($response eq 'ok') {
25652  
25653 # This is probably not the best way of converting #ffff25812581 to #FF2525, but it will
25654 # have to do, for now
25655 $hex = '#' . uc(
25656 sprintf('%02x', int($colorSelectionObj->get_current_color->red() / 256))
25657 . sprintf('%02x', int($colorSelectionObj->get_current_color->green() / 256))
25658 . sprintf('%02x', int($colorSelectionObj->get_current_color->blue() / 256))
25659 );
25660 }
25661  
25662 # Destroy the window
25663 $dialogueWin->destroy();
25664  
25665 # Return the colour (or 'undef' if no colour was selected)
25666 return $hex;
25667 }
25668  
25669 sub showFontSelectionDialogue {
25670  
25671 # Can be called by any function
25672 # Creates a standard Gtk3::FontSelectionDialog and returns the response (if any)
25673 #
25674 # Expected arguments
25675 # $title - The title to display, e.g. 'Select font'
25676 #
25677 # Optional arguments
25678 # $initialFont - The initial font and size to use, a string in the form 'Monospace 10'
25679 #
25680 # Return values
25681 # 'undef' on expected arguments or if the user doesn't close the 'dialogue' window by
25682 # clicking the 'ok' button
25683 # Otherwise, returns the font selected as a string in the form 'Monospace 10'
25684  
25685 my ($self, $title, $initialFont, $check) = @_;
25686  
25687 # Local variables
25688 my ($response, $newFont);
25689  
25690 # Check for improper arguments
25691 if (! defined $title || defined $check) {
25692  
25693 return $axmud::CLIENT->writeImproper(
25694 $self->_objClass . '->showFontSelectionDialogue',
25695 @_,
25696 );
25697 }
25698  
25699 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
25700 # be visible above the new dialogue window)
25701 if ($axmud::CLIENT->busyWin) {
25702  
25703 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25704 }
25705  
25706 # Show the 'dialogue' window
25707 my $dialogueWin = Gtk3::FontChooserDialog->new($title, $self->winWidget);
25708 $dialogueWin->set_position('center-always');
25709 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25710  
25711 if ($initialFont) {
25712  
25713 $dialogueWin->set_font($initialFont);
25714 }
25715  
25716 # Get the response
25717 $response = $dialogueWin->run();
25718 if ($response eq 'ok') {
25719  
25720 # Get the selected font
25721 $newFont = $dialogueWin->get_font();
25722 }
25723  
25724 # Close the 'dialogue' window
25725 $dialogueWin->destroy();
25726  
25727 # Return the font (or 'undef' if no font was selected)
25728 return $newFont;
25729 }
25730  
25731 sub promptRoomFlag {
25732  
25733 # Called by GA::EditWin::WorldModel->roomFlags1Tab
25734 # Prompts the user for the attributes of a new custom room flag
25735 #
25736 # Expected arguments
25737 # (none besides $self)
25738 #
25739 # Return values
25740 # An empty list on improper arguments or if the user closes the window without clicking
25741 # the 'OK' button
25742 # Otherwise returns a list in the form
25743 # (name, short_name, descrip, colour)
25744 # ...roughly corresponding to IVs in the new GA::Obj::RoomFlag object
25745  
25746 my ($self, $check) = @_;
25747  
25748 # Local variables
25749 my (
25750 $colour, $response,
25751 @emptyList, @returnList,
25752 );
25753  
25754 # Check for improper arguments
25755 if (defined $check) {
25756  
25757 $axmud::CLIENT->writeImproper($self->_objClass . '->promptRoomFlag', @_);
25758 return @emptyList;
25759 }
25760  
25761 # Show the 'dialogue' window
25762 my $dialogueWin = Gtk3::Dialog->new(
25763 'Add custom room flag',
25764 $self->winWidget,
25765 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
25766 'gtk-cancel' => 'reject',
25767 'gtk-ok' => 'accept',
25768 );
25769  
25770 $dialogueWin->set_position('center-always');
25771 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25772  
25773 $dialogueWin->signal_connect('delete-event' => sub {
25774  
25775 $dialogueWin->destroy();
25776 $self->restoreFocus();
25777  
25778 return @emptyList;
25779 });
25780  
25781 # Add widgets to the 'dialogue' window
25782 my $vBox = $dialogueWin->get_content_area();
25783 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
25784 # Gtk3::VBox on the right, into which we put everything
25785 my $vBox2 = $self->addDialogueIcon($vBox);
25786  
25787 # Need a grid as it's the quicket way to draw the room flag colour
25788 my $grid = Gtk3::Grid->new();
25789 $vBox2->pack_start($grid, TRUE, TRUE, $axmud::CLIENT->constFreeSpacingPixels);
25790 $grid->set_column_spacing($axmud::CLIENT->constFreeSpacingPixels);
25791 $grid->set_row_spacing($axmud::CLIENT->constFreeSpacingPixels);
25792  
25793 # Name
25794 my $label = Gtk3::Label->new();
25795 $grid->attach($label, 0, 0, 3, 1);
25796 $label->set_alignment(0, 0);
25797 $label->set_markup('Room flag name (max 16 chars)');
25798  
25799 my $entry = Gtk3::Entry->new();
25800 $grid->attach($entry, 0, 1, 3, 1);
25801 $entry->set_width_chars(16);
25802 $entry->set_max_length(16);
25803  
25804 # Short name
25805 my $label2 = Gtk3::Label->new();
25806 $grid->attach($label2, 0, 2, 3, 1);
25807 $label2->set_alignment(0, 0);
25808 $label2->set_markup('Short name (max 2 chars)');
25809  
25810 my $entry2 = Gtk3::Entry->new();
25811 $grid->attach($entry2, 0, 3, 3, 1);
25812 $entry2->set_width_chars(2);
25813 $entry2->set_max_length(2);
25814  
25815 # Description
25816 my $label3 = Gtk3::Label->new();
25817 $grid->attach($label3, 0, 4, 3, 1);
25818 $label3->set_alignment(0, 0);
25819 $label3->set_markup('Description');
25820  
25821 my $entry3 = Gtk3::Entry->new();
25822 $grid->attach($entry3, 0, 5, 3, 1);
25823  
25824 # Colour
25825 $colour = '#FFFFFF'; # Default new colour is white
25826  
25827 my $label4 = Gtk3::Label->new();
25828 $grid->attach($label4, 0, 6, 1, 1);
25829 $label4->set_markup('Use colour');
25830 $label4->set_alignment(0, 0.5);
25831  
25832 my ($frame, $canvas, $canvasObj) = $self->addSimpleCanvas($grid,
25833 $colour,
25834 undef, # No neutral colour
25835 1, 2, 6, 7,
25836 );
25837  
25838 my $button = Gtk3::Button->new('Set');
25839 $grid->attach($button, 2, 6, 1, 1);
25840 $button->signal_connect('clicked' => sub {
25841  
25842 my $choice = $self->showColourSelectionDialogue(
25843 'Colour',
25844 $colour,
25845 );
25846  
25847 if ($choice) {
25848  
25849 $colour = $choice;
25850 $canvasObj = $self->fillSimpleCanvas($canvas, $canvasObj, $colour);
25851 }
25852 });
25853  
25854 # Display the dialogue window
25855 $vBox->show_all();
25856  
25857 # If the user clicked 'cancel', $response will be 'reject'
25858 $response = $dialogueWin->run();
25859  
25860 if ($response ne 'accept') {
25861  
25862 $dialogueWin->destroy();
25863 $self->restoreFocus();
25864  
25865 return @emptyList;
25866  
25867 # Otherwise, user clicked 'ok'
25868 } else {
25869  
25870 @returnList = ($entry->get_text(), $entry2->get_text(), $entry3->get_text(), $colour);
25871  
25872 $dialogueWin->destroy();
25873 $self->restoreFocus();
25874  
25875 return @returnList;
25876 }
25877 }
25878  
25879 sub showIrreversibleTest {
25880  
25881 # Called by GA::Cmd::ToggleIrreversible->do
25882 # Shows a 'dialogue' window with a non-functional button that contains both an icon and
25883 # some text, to test whether the user's system allows both (some systems will show only
25884 # the text)
25885 #
25886 # Expected arguments
25887 # (none besides $self)
25888 #
25889 # Return values
25890 # 'undef' on improper arguments or if the user closes the 'dialogue' window
25891 # 1 otherwise
25892  
25893 my ($self, $check) = @_;
25894  
25895 # Check for improper arguments
25896 if (defined $check) {
25897  
25898 return $axmud::CLIENT->writeImproper($self->_objClass . '->showIrreversibleTest', @_);
25899 }
25900  
25901 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
25902 # be visible above the new dialogue window)
25903 if ($axmud::CLIENT->busyWin) {
25904  
25905 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25906 }
25907  
25908 # Show the 'dialogue' window
25909 my $dialogueWin = Gtk3::Dialog->new(
25910 'Irreversible icon test',
25911 $self->winWidget,
25912 Gtk3::DialogFlags->new([qw/modal destroy-with-parent/]),
25913 'gtk-ok' => 'accept',
25914 );
25915  
25916 $dialogueWin->set_position('center-always');
25917 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25918  
25919 $dialogueWin->signal_connect('delete-event' => sub {
25920  
25921 $dialogueWin->destroy();
25922 $self->restoreFocus();
25923  
25924 return undef;
25925 });
25926  
25927 # Add widgets to the 'dialogue' window
25928 my $vBox = $dialogueWin->get_content_area();
25929 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
25930 # Gtk3::VBox on the right, into which we put everything
25931 my $vBox2 = $self->addDialogueIcon($vBox);
25932  
25933 my $label = Gtk3::Label->new();
25934 $vBox2->pack_start($label, FALSE, FALSE, $axmud::CLIENT->constFreeSpacingPixels);
25935 $label->set_alignment(0, 0);
25936 $label->set_markup(
25937 "<i>If button icons are available on your\nsystem, the button below contains\nboth an"
25938 . " icon and some text</i>"
25939 );
25940  
25941 my $button = Gtk3::Button->new('Hello world!');
25942 $vBox2->pack_start($button, FALSE, FALSE, $axmud::CLIENT->constFreeSpacingPixels);
25943  
25944 my $image = Gtk3::Image->new_from_file(
25945 $axmud::SHARE_DIR . '/icons/system/irreversible.png',
25946 );
25947  
25948 $button->set_image($image);
25949  
25950 my $label2 = Gtk3::Label->new();
25951 $vBox2->pack_start($label2, FALSE, FALSE, $axmud::CLIENT->constFreeSpacingPixels);
25952 $label2->set_alignment(0, 0);
25953 $label2->set_markup(
25954 "<i>Click 'OK' to end the test</i>"
25955 );
25956  
25957 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
25958 # consistently active (don't know why this works; it just does)
25959 $dialogueWin->show_all();
25960 $dialogueWin->present();
25961 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showIrreversibleTest');
25962  
25963 # If the user clicked 'cancel', $response will be 'reject'
25964 # Otherwise, user clicked 'ok', and we might need to add initial tasks
25965 $dialogueWin->run();
25966 $dialogueWin->destroy();
25967 $self->restoreFocus();
25968  
25969 return 1;
25970 }
25971  
25972 sub showBusyWin {
25973  
25974 # Displays a temporary popup window (still an Axmud 'dialogue' window)
25975 # By default, displays the Axmud icon and the caption 'Loading...', but the calling function
25976 # can specify a different logo and caption, if required
25977 # The popup window must be closed by the calling function, when no longer required (via a
25978 # call to $self->closeDialogueWin)
25979 #
25980 # Expected arguments
25981 # (none besides $self)
25982 #
25983 # Optional arguments
25984 # $path - Path of the file containing the image to show as an icon. If not
25985 # specified, the standard Axmud icon
25986 # $caption - A short piece of text to show next to the image. If not specified, the
25987 # caption 'Loading...' is used
25988 #
25989 # Return values
25990 # 'undef' on improper arguments or if the window is not opened
25991 # 1 otherwise
25992  
25993 my ($self, $path, $caption, $check) = @_;
25994  
25995 # Check for improper arguments
25996 if (defined $check) {
25997  
25998 return $axmud::CLIENT->writeImproper($self->_objClass . '->showBusyWin', @_);
25999 }
26000  
26001 # Don't show the popup window at all, if not allowed
26002 if (! $axmud::CLIENT->allowBusyWinFlag) {
26003  
26004 return undef;
26005 }
26006  
26007 # Only one of these temporary popup windows can exist at a time. If one already exists,
26008 # close it
26009 if ($axmud::CLIENT->busyWin) {
26010  
26011 $self->closeDialogueWin($axmud::CLIENT->busyWin);
26012 }
26013  
26014 # Set the file path and caption text, if not specified
26015 if (! defined $path || ! (-e $path)) {
26016  
26017 $path = $axmud::CLIENT->getDialogueIcon('medium');
26018 }
26019  
26020 if (! $caption) {
26021  
26022 $caption = 'Loading...';
26023 }
26024  
26025 # Show the window widget
26026 my $dialogueWin = Gtk3::Window->new('popup');
26027 $dialogueWin->set_position('center-always');
26028 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
26029 $dialogueWin->set_title($axmud::SCRIPT);
26030 $dialogueWin->set_border_width(0);
26031 $dialogueWin->set_transient_for($self->winWidget);
26032  
26033 $dialogueWin->signal_connect('delete-event' => sub {
26034  
26035 $dialogueWin->destroy();
26036 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showBusyWin');
26037 });
26038  
26039 # Add widgets to the 'dialogue' window
26040 my $frame = Gtk3::Frame->new();
26041 $dialogueWin->add($frame);
26042  
26043 my $hBox = Gtk3::HBox->new(FALSE, 0);
26044 $frame->add($hBox);
26045 $hBox->set_border_width(10);
26046  
26047 my $image = Gtk3::Image->new_from_file($path);
26048 $hBox->pack_start($image, FALSE, FALSE, 5);
26049  
26050 my $label = Gtk3::Label->new();
26051 $hBox->pack_start($label, FALSE, FALSE, 5);
26052 $label->set_markup('<i><big>' . $caption . '</big></i>');
26053 $label->set_alignment(0.5, 0.5);
26054  
26055 $dialogueWin->show_all();
26056  
26057 # For some reason, during certain operations the icon and text are not shown in the
26058 # window; the following lines make them appear
26059 $dialogueWin->present();
26060 # Update Gtk3's events queue
26061 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showBusyWin');
26062 # Update the Client IV
26063 $axmud::CLIENT->set_busyWin($dialogueWin);
26064  
26065 return $dialogueWin;
26066 }
26067  
26068 # Functions to add widgets to a Gtk3::Grid
26069  
26070 sub addLabel {
26071  
26072 # Adds a Gtk3::Label at the specified position in a Gtk3::Grid
26073 #
26074 # Example calls:
26075 # my $label = $self->addLabel($grid, 'Some plain text',
26076 # 0, 6, 0, 1);
26077 # my $label = $self->addLabel($grid, '<b>Some pango markup text</b>',
26078 # 0, 6, 0, 1,
26079 # 0, 0.5);
26080 #
26081 # Expected arguments
26082 # $grid - The Gtk3::Grid itself
26083 # $text - The text to display (plain text or pango markup text)
26084 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26085 # - The position of the label in the table
26086 #
26087 # Optional arguments
26088 # $alignLeft, $alignRight
26089 # - Used in the call to ->set_alignment; two values in the range 0-1
26090 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
26091 #
26092 # Return values
26093 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26094 # Otherwise the Gtk3::Label created
26095  
26096 my (
26097 $self, $grid, $text, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $alignLeft,
26098 $alignRight, $check
26099 ) = @_;
26100  
26101 # Check for improper arguments
26102 if (
26103 ! defined $grid || ! defined $text || ! defined $leftAttach || ! defined $rightAttach
26104 || ! defined $topAttach || ! defined $bottomAttach || defined $check
26105 ) {
26106 return $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
26107 }
26108  
26109 # Check that the position in the table makes sense
26110 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26111  
26112 return undef;
26113 }
26114  
26115 # Set default alignment, if none specified
26116 if (! defined $alignLeft) {
26117  
26118 $alignLeft = 0;
26119 }
26120  
26121 if (! defined $alignRight) {
26122  
26123 $alignRight = 0.5;
26124 }
26125  
26126 # Create the label
26127 my $label = Gtk3::Label->new();
26128 $label->set_markup($text);
26129  
26130 # Set its alignment
26131 $label->set_alignment($alignLeft, $alignRight);
26132  
26133 # Add the label to the grid
26134 $label->set_hexpand(TRUE);
26135 $label->set_vexpand(FALSE);
26136 $grid->attach(
26137 $label,
26138 $leftAttach,
26139 $topAttach,
26140 ($rightAttach - $leftAttach),
26141 ($bottomAttach - $topAttach),
26142 );
26143  
26144 return $label;
26145 }
26146  
26147 sub addButton {
26148  
26149 # Adds a Gtk3::Button at the specified position in a Gtk3::Grid
26150 # NB This function does not contain a ->signal_connect method - the calling function must
26151 # specify its own one
26152 #
26153 # Example calls:
26154 # my $button = $self->addButton($grid, \&buttonClicked, 'button_label', 'tooltips',
26155 # 0, 6, 0, 1);
26156 # my $button = $self->addButton($grid, undef, 'button_label', 'tooltips',
26157 # 0, 6, 0, 1);
26158 # my $button = $self->addButton($grid, \&buttonClicked, 'button_label', '',
26159 # 0, 6, 0, 1);
26160 #
26161 # The referenced function (if specified) receives an argument list in the form:
26162 # ($self, button_widget)
26163 #
26164 # Expected arguments
26165 # $grid - The Gtk3::Grid itself
26166 # $funcRef - Reference to the function to call when the button is clicked. If 'undef',
26167 # it's up to the calling function to create a ->signal_connect method
26168 # $label - The label text displayed on the button
26169 # $tooltips - Tooltips to use for the button; empty strings are not used
26170 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26171 # - The position of the button in the table
26172 #
26173 # Return values
26174 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26175 # Otherwise the Gtk3::Button created
26176  
26177 my (
26178 $self, $grid, $funcRef, $label, $tooltips, $leftAttach, $rightAttach, $topAttach,
26179 $bottomAttach, $check,
26180 ) = @_;
26181  
26182 # Local variables
26183 my $current;
26184  
26185 # Check for improper arguments
26186 if (
26187 ! defined $grid || ! defined $label || ! defined $tooltips || ! defined $leftAttach
26188 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
26189 || defined $check
26190 ) {
26191 return $axmud::CLIENT->writeImproper($self->_objClass . '->addButton', @_);
26192 }
26193  
26194 # Check that the position in the table makes sense
26195 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26196  
26197 return undef;
26198 }
26199  
26200 # Create the button
26201 my $button = Gtk3::Button->new($label);
26202  
26203 # Use tooltips, if any were specified
26204 if ($tooltips) {
26205  
26206 $button->set_tooltip_text($tooltips);
26207 }
26208  
26209 # If a callback function was specified, apply it
26210 if ($funcRef) {
26211  
26212 $button->signal_connect('clicked' => sub {
26213  
26214 &$funcRef($self, $button);
26215 });
26216 }
26217  
26218 # Add the button to the grid
26219 $button->set_hexpand(TRUE);
26220 $button->set_vexpand(FALSE);
26221 $grid->attach(
26222 $button,
26223 $leftAttach,
26224 $topAttach,
26225 ($rightAttach - $leftAttach),
26226 ($bottomAttach - $topAttach),
26227 );
26228  
26229 return $button;
26230 }
26231  
26232 sub addCheckButton {
26233  
26234 # Adds a Gtk3::CheckButton with an accompanying label at the specified position in a
26235 # Gtk3::Grid
26236 # NB This function does not contain a ->signal_connect method - the calling function must
26237 # specify its own one
26238 #
26239 # Example calls:
26240 # my $checkButton = $self->addCheckButton($grid, 'Click me', \&buttonClicked, TRUE, TRUE,
26241 # 0, 6, 0, 1);
26242 # my $checkButton = $self->addCheckButton($grid, undef, \&buttonClicked, TRUE, TRUE,
26243 # 0, 6, 0, 1);
26244 #
26245 # The referenced function (if specified) receives an argument list in the form:
26246 # ($self, button_widget, button_selected_flag)
26247 #
26248 # Expected arguments
26249 # $grid - The Gtk3::Grid itself
26250 # $name - A 'name' for the checkbutton (displayed next to the button); if 'undef',
26251 # no name is displayed
26252 # $funcRef - Reference to the function to call when the button is toggled. If 'undef',
26253 # it's up to the calling function to create a ->signal_connect method
26254 # $selectFlag - Flag set to FALSE if the checkbutton shouldn't be selected initially, TRUE
26255 # if it should be selected initially
26256 # $stateFlag - Flag set to FALSE if the checkbutton's state should be 'insensitive',
26257 # TRUE if it should be 'normal'
26258 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26259 # - The position of the checkbutton in the table
26260 #
26261 # Return values
26262 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26263 # Otherwise the Gtk3::CheckButton created
26264  
26265 my (
26266 $self, $grid, $name, $funcRef, $selectFlag, $stateFlag, $leftAttach, $rightAttach,
26267 $topAttach, $bottomAttach, $check,
26268 ) = @_;
26269  
26270 # Check for improper arguments
26271 if (
26272 ! defined $grid || ! defined $selectFlag || ! defined $stateFlag
26273 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
26274 || ! defined $bottomAttach || defined $check
26275 ) {
26276 return $axmud::CLIENT->writeImproper($self->_objClass . '->addCheckButton', @_);
26277 }
26278  
26279 # Check that the position in the table makes sense
26280 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26281  
26282 return undef;
26283 }
26284  
26285 # Create the check button
26286 my $checkButton;
26287 if (defined $name && $name ne '') {
26288 $checkButton = Gtk3::CheckButton->new_with_label($name);
26289 } else {
26290 $checkButton = Gtk3::CheckButton->new();
26291 }
26292  
26293 # Set the checkbutton's initial value
26294 $checkButton->set_active($selectFlag);
26295  
26296 # Make the checkbutton insensitive, if $stateFlag is FALSE
26297 if (! $stateFlag) {
26298  
26299 $checkButton->set_state('insensitive');
26300 }
26301  
26302 # If a callback function was specified, apply it
26303 if ($funcRef) {
26304  
26305 $checkButton->signal_connect('toggled' => sub {
26306  
26307 &$funcRef($self, $checkButton, $checkButton->get_active());
26308 });
26309 }
26310  
26311 # Add the check button to the grid
26312 $checkButton->set_hexpand(TRUE);
26313 $checkButton->set_vexpand(FALSE);
26314 $grid->attach(
26315 $checkButton,
26316 $leftAttach,
26317 $topAttach,
26318 ($rightAttach - $leftAttach),
26319 ($bottomAttach - $topAttach),
26320 );
26321  
26322 return $checkButton;
26323 }
26324  
26325 sub addRadioButton {
26326  
26327 # Adds a Gtk3::RadioButton at the specified position in a Gtk3::Grid
26328 # NB This function does not contain a ->signal_connect method - the calling function must
26329 # specify its own one
26330 #
26331 # Example calls:
26332 # my ($group, $button) = $self->addRadioButton(
26333 # $grid, \&buttonClicked, undef, $name,
26334 # TRUE, TRUE,
26335 # 0, 6, 0, 1);
26336 # my ($group2, $button2) = $self->addRadioButton(
26337 # $grid, undef, $group, $name,
26338 # FALSE, TRUE,
26339 # 0, 6, 0, 1, 0, 0.5);
26340 #
26341 # The referenced function (if specified) receives an argument list in the form:
26342 # ($self, button_widget)
26343 #
26344 # Expected arguments
26345 # $grid - The Gtk3::Grid itself
26346 # $funcRef - Reference to the function to call when the button becomes active
26347 # (selected). If 'undef', it's up to the calling function to create a
26348 # ->signal_connect method
26349 # $group - Reference to the radio button group created, when the first button in the
26350 # group was added (if set to 'undef', this is the first button, and a
26351 # group will be created for it)
26352 # $name - A 'name' for the radio button (displayed next to the button); if 'undef',
26353 # no name is displayed
26354 # $selectFlag - Flag set to FALSE if the radio button shouldn't be selected initially,
26355 # TRUE if it should be selected initially
26356 # $stateFlag - Flag set to FALSE if the radiobutton's state should be 'insensitive',
26357 # TRUE if it should be 'normal'
26358 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26359 # - The position of the radiobutton in the table
26360 #
26361 # Optional arguments
26362 # $alignLeft, $alignRight
26363 # - Used in the call to ->set_alignment; two values in the range 0-1
26364 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
26365 #
26366 # Return values
26367 # An empty list on improper arguments or if the widget's position in the Gtk3::Grid is
26368 # invalid
26369 # Otherwise a list containing two elements: the radio button $group and the
26370 # Gtk3::RadioButton created
26371  
26372 my (
26373 $self, $grid, $funcRef, $group, $name, $selectFlag, $stateFlag, $leftAttach,
26374 $rightAttach, $topAttach, $bottomAttach, $alignLeft, $alignRight, $check,
26375 ) = @_;
26376  
26377 # Local variables
26378 my @emptyList;
26379  
26380 # Check for improper arguments
26381 if (
26382 ! defined $grid || ! defined $selectFlag || ! defined $stateFlag
26383 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
26384 || ! defined $bottomAttach || defined $check
26385 ) {
26386 $axmud::CLIENT->writeImproper($self->_objClass . '->addRadioButton', @_);
26387 return @emptyList;
26388 }
26389  
26390 # Check that the position in the table makes sense
26391 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26392  
26393 return @emptyList;
26394 }
26395  
26396 # Set default alignment, if none specified
26397 if (! defined $alignLeft) {
26398  
26399 $alignLeft = 0;
26400 }
26401 if (! defined $alignRight) {
26402  
26403 $alignRight = 0.5;
26404 }
26405  
26406 # Create the radio button
26407 my $radioButton = Gtk3::RadioButton->new();
26408 # Add it to the existing group, if one was specified
26409 if (defined $group) {
26410  
26411 $radioButton->set_group($group);
26412 }
26413  
26414 # Set the radiobutton's initial value
26415 $radioButton->set_active($selectFlag);
26416  
26417 # Give the radio button a name, if one was specified
26418 if ($name) {
26419  
26420 $radioButton->set_label($name);
26421 }
26422  
26423 # Make the radiobutton insensitive, if $stateFlag is FALSE
26424 if (! $stateFlag) {
26425  
26426 $radioButton->set_state('insensitive');
26427 }
26428  
26429 # Set radiobutton's alignment
26430 $radioButton->set_alignment($alignLeft, $alignRight);
26431  
26432 # If a callback function was specified, apply it
26433 if ($funcRef) {
26434  
26435 $radioButton->signal_connect('toggled' => sub {
26436  
26437 # Only call the function if this radio button has been selected
26438 if ($radioButton->get_active()) {
26439  
26440 &$funcRef($self, $radioButton);
26441 }
26442 });
26443 }
26444  
26445 # Add the radio button to the grid
26446 $radioButton->set_hexpand(FALSE);
26447 $radioButton->set_vexpand(FALSE);
26448 $grid->attach(
26449 $radioButton,
26450 $leftAttach,
26451 $topAttach,
26452 ($rightAttach - $leftAttach),
26453 ($bottomAttach - $topAttach),
26454 );
26455  
26456 return ($radioButton->get_group(), $radioButton);
26457 }
26458  
26459 sub addEntry {
26460  
26461 # Adds a Gtk3::Entry at the specified position in a Gtk3::Grid
26462 # NB This function does not contain a ->signal_connect method - the calling function must
26463 # specify its own one
26464 #
26465 # Example calls:
26466 # my $entry = $self->addEntry($grid, \&returnPressed, $value, TRUE,
26467 # 0, 6, 0, 1);
26468 # my $entry = $self->addEntry($grid, undef, $value, FALSE,
26469 # 0, 6, 0, 1, 16, 16);
26470 #
26471 # The referenced function (if specified) receives an argument list in the form:
26472 # ($self, entry_widget, entry_text)
26473 #
26474 # Expected arguments
26475 # $grid - The Gtk3::Grid itself
26476 # $funcRef - Reference to the function to call when the user types something in the
26477 # entry and presses 'return'. If 'undef', it's up to the calling function
26478 # to create a ->signal_connect method
26479 # $value - The initial contents of the entry box. Set to 'undef' if you want it to be
26480 # empty
26481 # $stateFlag - Flag set to FALSE if the entry box's state should be 'insensitive', TRUE
26482 # if it should be 'normal'
26483 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26484 # - The position of the entry box in the table
26485 #
26486 # Optional arguments
26487 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
26488 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
26489 #
26490 # Return values
26491 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26492 # Otherwise the Gtk3::Entry created
26493  
26494 my (
26495 $self, $grid, $funcRef, $value, $stateFlag, $leftAttach, $rightAttach, $topAttach,
26496 $bottomAttach, $widthChars, $maxChars, $check,
26497 ) = @_;
26498  
26499 # Check for improper arguments
26500 if (
26501 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
26502 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
26503 || defined $check
26504 ) {
26505 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntry', @_);
26506 }
26507  
26508 # Check that the position in the table makes sense
26509 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26510  
26511 return undef;
26512 }
26513  
26514 # Create the entry
26515 my $entry = Gtk3::Entry->new();
26516  
26517 # Set the entry's value
26518 if ($value) {
26519  
26520 $entry->set_text($value);
26521 }
26522  
26523 # Make the entry insensitive, if $stateFlag is FALSE
26524 if (! $stateFlag) {
26525  
26526 $entry->set_state('insensitive');
26527 }
26528  
26529 # Set the width, if specified
26530 if (defined $widthChars) {
26531  
26532 $entry->set_width_chars($widthChars);
26533 }
26534  
26535 # Set the maximum number of characters, if specified
26536 if (defined $maxChars) {
26537  
26538 $entry->set_max_length($maxChars);
26539 }
26540  
26541 # If a callback function was specified, apply it
26542 if ($funcRef) {
26543  
26544 $entry->signal_connect('activate' => sub {
26545  
26546 &$funcRef($self, $entry, $entry->get_text());
26547 });
26548 }
26549  
26550 # Add the entry to the grid
26551 $entry->set_hexpand(TRUE);
26552 $entry->set_vexpand(FALSE);
26553 $grid->attach(
26554 $entry,
26555 $leftAttach,
26556 $topAttach,
26557 ($rightAttach - $leftAttach),
26558 ($bottomAttach - $topAttach),
26559 );
26560  
26561 return $entry;
26562 }
26563  
26564 sub addComboBox {
26565  
26566 # Adds a Gtk3::ComboBox at the specified position in a Gtk3::Grid
26567 # NB This function does not contain a ->signal_connect method - the calling function must
26568 # specify its own one
26569 #
26570 # Example calls:
26571 # my $comboBox = $self->addComboBox(
26572 # $grid, \&itemSelected, \@comboList, 'some_title', TRUE,
26573 # 0, 6, 0, 1);
26574 # my $comboBox = $self->addComboBox(
26575 # $grid, undef, \@comboList, '', FALSE,
26576 # 0, 6, 0, 1);
26577 #
26578 # The referenced function (if specified) receives an argument list in the form:
26579 # ($self, combo_box_widget, selected_text)
26580 #
26581 # Expected arguments
26582 # $grid - The Gtk3::Grid itself
26583 # $funcRef - Reference to the function to call when the user selects something in
26584 # the combobox. If 'undef', it's up to the calling function to create
26585 # a ->signal_connect method
26586 # $listRef - Reference to a list with initial values (can be an empty list)
26587 # $title - A string used as a title, e.g. 'Choose your favourite colour' - if
26588 # 'undef', a title isn't used (use an empty string for an initially-
26589 # empty combobox)
26590 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26591 # - The position of the combo box in the table
26592 #
26593 # Return values
26594 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26595 # Otherwise the Gtk3::ComboBox created
26596  
26597 my (
26598 $self, $grid, $funcRef, $listRef, $title, $leftAttach, $rightAttach, $topAttach,
26599 $bottomAttach, $check,
26600 ) = @_;
26601  
26602 # Check for improper arguments
26603 if (
26604 ! defined $grid || ! defined $listRef || ! defined $leftAttach
26605 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
26606 || defined $check
26607 ) {
26608 return $axmud::CLIENT->writeImproper($self->_objClass . '->addComboBox', @_);
26609 }
26610  
26611 # Check that the position in the table makes sense
26612 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26613  
26614 return undef;
26615 }
26616  
26617 # Create the combobox
26618 my $comboBox = Gtk3::ComboBoxText->new();
26619  
26620 # Populate the combobox
26621 if (defined $title) {
26622  
26623 # The first item in the combobox list is a title
26624 $comboBox->append_text($title);
26625 }
26626  
26627 foreach my $item (@$listRef) {
26628  
26629 $comboBox->append_text($item);
26630 }
26631  
26632 $comboBox->set_active(0);
26633  
26634 # If a callback function was specified, apply it
26635 if ($funcRef) {
26636  
26637 $comboBox->signal_connect('changed' => sub {
26638  
26639 my $text = $comboBox->get_active_text();
26640  
26641 # If the user has selected the title, ignore it
26642 if (! defined $title || $text ne $title) {
26643  
26644 &$funcRef($self, $comboBox, $text);
26645 }
26646 });
26647 }
26648  
26649 # Add the combobox to the grid
26650 $comboBox->set_hexpand(TRUE);
26651 $comboBox->set_vexpand(FALSE);
26652 $grid->attach(
26653 $comboBox,
26654 $leftAttach,
26655 $topAttach,
26656 ($rightAttach - $leftAttach),
26657 ($bottomAttach - $topAttach),
26658 );
26659  
26660 return $comboBox;
26661 }
26662  
26663 sub addTextView {
26664  
26665 # Adds a Gtk3::TextView at the specified position in a Gtk3::Grid
26666 # NB This function does not contain a ->signal_connect method - the calling function must
26667 # specify its own one
26668 #
26669 # Example calls:
26670 # my $textView = $self->addTextView($grid, $self->winType, undef, undef, TRUE,
26671 # 0, 6, 0, 1);
26672 # my $textView = $self->addTextView($grid, undef, undef, "Hello\nworld", FALSE,
26673 # 0, 6, 0, 1,
26674 # -1, 120);
26675 #
26676 # The referenced function (if specified) receives an argument list in the form:
26677 # ($self, textview_widget, buffer_widget, buffer_text)
26678 # ...where 'buffer_text' is a string containing one or more lines, separated by newline
26679 # characters
26680 #
26681 # Expected arguments
26682 # $grid - The Gtk3::Grid itself
26683 # $colourScheme - The name of the colour scheme to use (matches a key in
26684 # GA::Client->colourSchemeHash; you should normally use the window
26685 # type, as in the example above). If 'undef', the system's
26686 # preferred colours/fonts are used. If the specified colour scheme
26687 # doesn't exist, the colour scheme matching the window type is used
26688 # $funcRef - Reference to the function to call when the user edits the contents of
26689 # the textview. If 'undef', it's up to the calling function to create
26690 # a ->signal_connect method
26691 # $string - String composed of one or lines separated by newline characters. If
26692 # 'undef', the textview is initially empty
26693 # $editableFlag - Flag set to TRUE if the textView should be editable, FALSE if it
26694 # shouldn't be editable
26695 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26696 # - The position of the textview in the table
26697 #
26698 # Optional arguments
26699 # $width, $height
26700 # - The width and height (in pixels) of the frame containing the list. If
26701 # specified, values of -1 mean 'don't set this value'. The default values
26702 # are (-1, -1)
26703 #
26704 # Return values
26705 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26706 # Otherwise the Gtk3::TextView created (inside a Gtk::ScrolledWindow)
26707  
26708 my (
26709 $self, $grid, $colourScheme, $funcRef, $string, $editableFlag, $leftAttach,
26710 $rightAttach, $topAttach, $bottomAttach, $width, $height, $check,
26711 ) = @_;
26712  
26713 # Check for improper arguments
26714 if (
26715 ! defined $grid || ! defined $editableFlag || ! defined $leftAttach
26716 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
26717 || defined $check
26718 ) {
26719 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTextView', @_);
26720 }
26721  
26722 # Check that the position in the table makes sense
26723 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26724  
26725 return undef;
26726 }
26727  
26728 # Set defaults
26729 if (! defined $width) {
26730  
26731 $width = -1; # Let Gtk3 set the width
26732 }
26733  
26734 if (! defined $height) {
26735  
26736 $height = -1; # Let Gtk3 set the height
26737 }
26738  
26739 # Creating a containing Gtk3::ScrolledWindow
26740 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
26741 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
26742 $scroll->set_policy('automatic', 'automatic');
26743 $scroll->set_size_request($width, $height);
26744 # $scroll->set_border_width($self->spacingPixels);
26745  
26746 # Create a textview and apply a CSS style
26747 my $textView = Gtk3::TextView->new();
26748 $scroll->add($textView);
26749 my $buffer = Gtk3::TextBuffer->new();
26750 $textView->set_buffer($buffer);
26751 $textView->set_cursor_visible(FALSE);
26752  
26753 if ($string) {
26754  
26755 $buffer->set_text(join("\n", $string));
26756 }
26757  
26758 # Make the textview editable or not editable
26759 $textView->set_editable($editableFlag);
26760  
26761 # Apply a CSS style to the textview
26762 if (defined $colourScheme && $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
26763 $axmud::CLIENT->desktopObj->setTextViewStyle($colourScheme, $textView);
26764 } else {
26765 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);
26766 }
26767  
26768 # If a callback function was specified, apply it
26769 if ($funcRef) {
26770  
26771 $buffer->signal_connect('changed' => sub {
26772  
26773 &$funcRef(
26774 $self,
26775 $textView,
26776 $buffer,
26777 $axmud::CLIENT->desktopObj->bufferGetText($buffer),
26778 );
26779 });
26780 }
26781  
26782 # Add the textview to the grid
26783 $scroll->set_hexpand(TRUE);
26784 $scroll->set_vexpand(TRUE);
26785 $grid->attach(
26786 $scroll,
26787 $leftAttach,
26788 $topAttach,
26789 ($rightAttach - $leftAttach),
26790 ($bottomAttach - $topAttach),
26791 );
26792  
26793 return $textView;
26794 }
26795  
26796 sub addSimpleList {
26797  
26798 # Adds a GA::Obj::SimpleList at the specified position in a Gtk3::Grid
26799 # NB This function does not contain a ->signal_connect method - the calling function must
26800 # specify its own one
26801 #
26802 # Example calls:
26803 # my $slWidget = $self->addSimpleList($grid, \@columnList, $dataRef,
26804 # 0, 6, 0, 1);
26805 # my $slWidget = $self->addSimpleList($grid, \@columnList, undef,
26806 # 0, 6, 0, 1,
26807 # -1, 120);
26808 # my $slWidget = $self->addSimpleList($grid, \@columnList, $dataRef,
26809 # 0, 6, 0, 1,
26810 # -1, -1,
26811 # GA::Client->getMethodRef('function_name'));
26812 #
26813 # Expected arguments
26814 # $grid - The Gtk3::Grid itself
26815 # $columnListRef - Reference to a list of column headings and types, in the form
26816 # ('heading', 'column_type', 'heading', 'column_type'...)
26817 # - 'column_type' is one of the column types specified by
26818 # GA::Obj::SimpleList, e.g. 'scalar', 'int'
26819 # - 'column_type' can also be 'bool' for a non-clickable checkbox, or
26820 # 'bool_editable' for a clickable checkbox
26821 # $dataRef - Reference to a list of values, used to fill the simple list. If
26822 # 'undef', it's up to the calling function to add data
26823 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26824 # - The position of the simple list in the table
26825 #
26826 # Optional arguments
26827 # $width, $height - The width and height (in pixels) of the scroller containing the list.
26828 # If specified, values of -1 mean 'don't set this value'. The default
26829 # values are (-1, -1)
26830 # $funcRef - Reference to the function to call when a (sensitised) checkbutton is
26831 # clicked. If 'undef', it's up to the calling function to create a
26832 # ->signal_connect method. Function references can be obtained by a
26833 # call to GA::Client->getMethodRef
26834 #
26835 # Return values
26836 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26837 # Otherwise the GA::Obj::SimpleList created
26838  
26839 my (
26840 $self, $grid, $columnListRef, $dataRef, $leftAttach, $rightAttach, $topAttach,
26841 $bottomAttach, $width, $height, $funcRef, $check,
26842 ) = @_;
26843  
26844 # Local variables
26845 my (
26846 $refType, $count,
26847 @columnList, @spareList,
26848 );
26849  
26850 # Check for improper arguments
26851 if (
26852 ! defined $grid || ! defined $columnListRef || ! defined $leftAttach
26853 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
26854 || defined $check
26855 ) {
26856 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleList', @_);
26857 }
26858  
26859 # Check that the position in the table makes sense
26860 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26861  
26862 return undef;
26863 }
26864  
26865 # Set defaults
26866 if (! defined $width) {
26867  
26868 $width = -1; # Let Gtk3 set the width
26869 }
26870  
26871 if (! defined $height) {
26872  
26873 $height = -1; # Let Gtk3 set the height
26874 }
26875  
26876 # Dereference the list of columns, and convert 'bool_editable' to 'bool' values for Gtk's
26877 # convenience
26878 foreach my $item (@$columnListRef) {
26879  
26880 if ($item eq 'bool_editable') {
26881 push(@columnList, 'bool');
26882 } else {
26883 push(@columnList, $item);
26884 }
26885 }
26886  
26887 # Add a simple list
26888 my $frame = Gtk3::Frame->new(undef);
26889 $frame->set_border_width(0);
26890  
26891 my $scroller = Gtk3::ScrolledWindow->new();
26892 $frame->add($scroller);
26893 $scroller->set_shadow_type($axmud::CLIENT->constShadowType);
26894 $scroller->set_policy('automatic', 'automatic');
26895 $scroller->set_border_width(0);
26896 $scroller->set_size_request($width, $height);
26897  
26898 my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList);
26899 $scroller->add($slWidget);
26900  
26901 # No interactive searches required
26902 $slWidget->set_enable_search(FALSE);
26903  
26904 # Fill the columns with data (if any was provided)
26905 if (defined $dataRef) {
26906  
26907 if (ref($dataRef) eq 'HASH') {
26908  
26909 # Sort the hash by key, before adding it to the simple list
26910 $self->resetSortListData($slWidget, $dataRef);
26911  
26912 } else {
26913  
26914 # Assume that the list/hash IV can be displayed in its current order
26915 $self->resetListData($slWidget, $dataRef, (scalar @columnList / 2));
26916 }
26917 }
26918  
26919 # Make all columns of type 'bool' (which are composed of checkbuttons) non-activatable, so
26920 # that the user can't click them on and off (if specified)
26921 $count = -1;
26922 @spareList = @$columnListRef;
26923 do {
26924  
26925 my $title = shift @spareList;
26926 my $type = shift @spareList;
26927  
26928 $count++;
26929  
26930 if ($type eq 'bool') {
26931  
26932 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
26933 $cellRenderer->set(activatable => FALSE);
26934  
26935 } elsif ($type eq 'bool_editable') {
26936  
26937 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
26938 $cellRenderer->set(activatable => TRUE);
26939  
26940 if (defined $funcRef) {
26941  
26942 $cellRenderer->signal_connect('toggled' => sub {
26943  
26944 my ($widget, $path) = @_;
26945  
26946 my $model = $slWidget->get_model();
26947 my $iter = $model->get_iter(Gtk3::TreePath->new_from_string($path));
26948  
26949 # Pass on the contents of each cell in the clicked row; it's up to the
26950 # called code to check the contents of multiple checkboxes, if they exist
26951 my @dataList = ();
26952 for (my $i = 0; $i < scalar (@columnList / 2); $i++) {
26953  
26954 push(@dataList, $model->get($iter, $i));
26955 }
26956  
26957 &$funcRef($slWidget, $model, $iter, @dataList);
26958 });
26959 }
26960 }
26961  
26962 } until (! @spareList);
26963  
26964 # Add the simple list to the grid
26965 $frame->set_hexpand(TRUE);
26966 $frame->set_vexpand(TRUE);
26967 $grid->attach(
26968 $frame,
26969 $leftAttach,
26970 $topAttach,
26971 ($rightAttach - $leftAttach),
26972 ($bottomAttach - $topAttach),
26973 );
26974  
26975 return $slWidget;
26976 }
26977  
26978 sub addImage {
26979  
26980 # Adds a Gtk3::Image from a specified file, inside a frame (optionally using scrollbars) at
26981 # the specified position in a Gtk3::Grid
26982 #
26983 # Example calls:
26984 # my ($image, $frame, $viewPort) = $self->addImage($grid, $filePath, $pixBuffer, TRUE,
26985 # 128, 128,
26986 # 0, 12, 1, 12);
26987 # my ($image, $frame) = $self->addImage($grid, undef, undef, FALSE,
26988 # 128, 128,
26989 # 0, 12, 1, 12);
26990 #
26991 # Expected arguments
26992 # $grid - The Gtk3::Grid itself
26993 # $filePath - Full path to the file containing the image to be displayed (or 'undef'
26994 # if not using a file)
26995 # $pixBuffer - A Gtk3::Gdk::Pixbuf containing the image to be displayed (or 'undef'
26996 # if not using a pixbuf)
26997 # $scrollFlag - Flag set to TRUE if the image's viewport should use scrollbars,
26998 # FALSE if not
26999 # $width, $height - The size of the frame in which the image is shown (in pixels)
27000 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
27001 # - The position of the frame in the table
27002 #
27003 # Return values
27004 # An empty list on improper arguments or if a $filePath is specified which doesn't exist
27005 # Otherwise returns a list in the form
27006 # (Gtk3_image, Gtk3_frame, Gtk3_viewport)
27007 # NB If neither $filePath nor $pixBuffer are specified, or if the Gtk3::Image can't be
27008 # created, the 'Gtk3_image' return value will be set to 'undef'
27009 # NB If $scrollFlag is FALSE, the 'Gtk3_viewport' return value will be set to 'undef'
27010  
27011 my (
27012 $self, $grid, $filePath, $pixBuffer, $scrollFlag, $width, $height, $leftAttach,
27013 $rightAttach, $topAttach, $bottomAttach, $check,
27014 ) = @_;
27015  
27016 # Local variables
27017 my @emptyList;
27018  
27019 # Check for improper arguments
27020 if (
27021 ! defined $grid || ! defined $scrollFlag || ! defined $width || ! defined $height
27022 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
27023 || ! defined $bottomAttach || defined $check
27024 ) {
27025 $axmud::CLIENT->writeImproper($self->_objClass . '->addImage', @_);
27026 return @emptyList;
27027 }
27028  
27029 # Check that the position in the table makes sense, and that filename (if specified) exists
27030 if (
27031 ! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)
27032 || (defined $filePath && ! -e $filePath)
27033 ) {
27034 return @emptyList;
27035 }
27036  
27037 # Create a frame
27038 my $frame = Gtk3::Frame->new(undef);
27039 $frame->set_border_width(3);
27040 $frame->set_size_request($width, $height);
27041  
27042 # Create the Gtk3::Image
27043 my $image;
27044 if ($filePath) {
27045 $image = Gtk3::Image->new_from_file($filePath);
27046 } elsif ($pixBuffer) {
27047 $image = Gtk3::Image->new_from_pixbuf($pixBuffer);
27048 }
27049  
27050 my $viewPort;
27051 if ($scrollFlag) {
27052  
27053 # Create a scrolled window
27054 my $scroller = Gtk3::ScrolledWindow->new();
27055 $scroller->set_border_width(3);
27056  
27057 # Create a viewport
27058 my $viewPort = Gtk3::Viewport->new(undef, undef);
27059  
27060 # If a Gtk3::Image was created, add it to the viewport
27061 if ($image) {
27062  
27063 $viewPort->add($image);
27064 }
27065  
27066 # Add the viewport to the scrolled window
27067 $scroller->add($viewPort);
27068 # Add the scrolled window to the frame
27069 $frame->add($scroller);
27070  
27071 } else {
27072  
27073 # If a Gtk3::Image was created, add it to the frame
27074 if ($image) {
27075  
27076 $frame->add($image);
27077 }
27078 }
27079  
27080 # Add the frame to the table (even if a Gtk3::Image wasn't created)
27081 $frame->set_hexpand(FALSE);
27082 $frame->set_vexpand(FALSE);
27083 $grid->attach(
27084 $frame,
27085 $leftAttach,
27086 $topAttach,
27087 ($rightAttach - $leftAttach),
27088 ($bottomAttach - $topAttach),
27089 );
27090  
27091 return ($image, $frame, $viewPort);
27092 }
27093  
27094 sub changeImage {
27095  
27096 # Changes the image shown as the result of a call to $self->addImage
27097 #
27098 # Expected arguments
27099 # (none besides $self)
27100 #
27101 # Optional arguments
27102 # $viewPort - The Gtk3::Viewport which contains the image ('undef' if no scrolling
27103 # viewport was used)
27104 # $frame - The Gtk3::Frame which contains the image ('undef' if a scrolling
27105 # viewport was used; ignored if $viewPort is defined)
27106 # $oldImage - The Gtk3::Image it currently contains. If it contains no image, set to
27107 # 'undef'
27108 # $filePath - Full path to the file containing the image to be displayed (or 'undef' if
27109 # not using a file)
27110 # $pixBuffer - A Gtk3::Gdk::Pixbuf containing the image to be displayed (or 'undef'
27111 # if not using a pixbuf)
27112 #
27113 # Return values
27114 # 'undef' on improper arguments, if the specified file doesn't exist or if a Gtk3::Image
27115 # can't be created
27116 # Otherwise returns the Gtk3::Image created, or 'undef' if none is created
27117  
27118 my ($self, $viewPort, $frame, $oldImage, $filePath, $pixBuffer, $check) = @_;
27119  
27120 # Check for improper arguments
27121 if ((! defined $viewPort && ! defined $frame) || defined $check) {
27122  
27123 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeImage', @_);
27124 }
27125  
27126 # Create a new Gtk3::Image
27127 my $newImage;
27128 if ($filePath) {
27129 $newImage = Gtk3::Image->new_from_file($filePath);
27130 } elsif ($pixBuffer) {
27131 $newImage = Gtk3::Image->new_from_pixbuf($pixBuffer);
27132 }
27133  
27134 if ($viewPort) {
27135  
27136 # Remove the old image from its viewport, if an old image was specified
27137 if ($oldImage) {
27138  
27139 $axmud::CLIENT->desktopObj->removeWidget($viewPort, $oldImage);
27140 }
27141  
27142 # Add the new image to the viewport, if a new image was created
27143 if ($newImage) {
27144  
27145 $viewPort->add($newImage);
27146 }
27147  
27148 } else {
27149  
27150 # Remove the old image from its frame, if an old image was specified
27151 if ($oldImage) {
27152  
27153 $axmud::CLIENT->desktopObj->removeWidget($frame, $oldImage);
27154 }
27155  
27156 # Add the new image to the frame, if a new image was created
27157 if ($newImage) {
27158  
27159 $frame->add($newImage);
27160 }
27161 }
27162  
27163 # Update the window to show the changes
27164 $self->winShowAll($self->_objClass . '->changeImage');
27165  
27166 return $newImage; # May be 'undef'
27167 }
27168  
27169 sub addSimpleImage {
27170  
27171 # Adds a Gtk3::Image from a specified file at the specified position in a Gtk3::Grid (but
27172 # not inside a frame: call ->addImage to do that)
27173 #
27174 # Example calls:
27175 # my $image = $self->addImage($grid, $filePath, $pixBuffer,
27176 # 0, 12, 1, 12);
27177 # my $image = $self->addImage($grid, undef, undef,
27178 # 0, 12, 1, 12);
27179 #
27180 # Expected arguments
27181 # $grid - The Gtk3::Grid itself
27182 # $filePath - Full path to the file containing the image to be displayed (or 'undef'
27183 # if not using a file)
27184 # $pixBuffer - A Gtk3::Gdk::Pixbuf containing the image to be displayed (or 'undef'
27185 # if not using a pixbuf)
27186 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
27187 # - The position of the frame in the table
27188 #
27189 # Return values
27190 # 'undef' on improper arguments or if a $filePath is specified which doesn't exist
27191 # Otherwise the Gtk3::Image created
27192  
27193 my (
27194 $self, $grid, $filePath, $pixBuffer, $leftAttach, $rightAttach, $topAttach,
27195 $bottomAttach, $check,
27196 ) = @_;
27197  
27198 # Check for improper arguments
27199 if (
27200 ! defined $grid || ! defined $leftAttach || ! defined $rightAttach
27201 || ! defined $topAttach || ! defined $bottomAttach || defined $check
27202 ) {
27203 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleImage', @_);
27204 }
27205  
27206 # Check that the position in the table makes sense, and that filename (if specified) exists
27207 if (
27208 ! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)
27209 || (defined $filePath && ! -e $filePath)
27210 ) {
27211 return undef;
27212 }
27213  
27214 # Create the Gtk3::Image
27215 my $image;
27216 if ($filePath) {
27217 $image = Gtk3::Image->new_from_file($filePath);
27218 } elsif ($pixBuffer) {
27219 $image = Gtk3::Image->new_from_pixbuf($pixBuffer);
27220 }
27221  
27222 if ($image) {
27223  
27224 # Add the image to the grid
27225 $image->set_hexpand(FALSE);
27226 $image->set_vexpand(FALSE);
27227 $grid->attach(
27228 $image,
27229 $leftAttach,
27230 $topAttach,
27231 ($rightAttach - $leftAttach),
27232 ($bottomAttach - $topAttach),
27233 );
27234 }
27235  
27236 return $image;
27237 }
27238  
27239 sub addSimpleCanvas {
27240  
27241 # Adds a GooCanvas2::Canvas to the table which is painted using a single colour
27242 # Call $self->fillSimpleCanvas to change the colour. Use ->addDrawingCanvas for more
27243 # complex drawing operations
27244 #
27245 # Example calls:
27246 # my ($frame, $canvas, $canvasObj) = $self->addSimpleCanvas($grid, '#FF0000', '#FFFFFF',
27247 # 6, 7, 6, 7,
27248 # 50, 50);
27249 # my ($frame, $canvas, $canvasObj) = $self->addSimpleCanvas($grid, 'red', undef,
27250 # 6, 7, 6, 7);
27251 #
27252 # Expected arguments
27253 # $grid - The Gtk3::Grid displayed in the current tab
27254 # $colour - The initial colour of the canvas. Can be any valid Axmud colour tag
27255 # (e.g. 'red', 'x255', '#FF0000')
27256 # $noColour - If $colour is not specified or if it is invalid, this colour is used.
27257 # If $noColour is also not specified or invalid, then no colour is
27258 # drawn (no canvas object is drawn on the canvas)
27259 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
27260 # - The position of the canvas in the table
27261 #
27262 # Optional arguments
27263 # $width, $height - The size, in pixels, of the canvas. If not specified, a default size
27264 # is applied that should fill the containing frame (assuming a
27265 # Gtk3::Grid using horizontal rows)
27266 #
27267 # Return values
27268 # An empty list on improper arguments or if the table coordinates don't make sense
27269 # Otherwise, a list in the form
27270 # (Gtk3::Frame, GooCanvas2::Canvas, GooCanvas2::CanvasRect)
27271 # ...where the last value will be 'undef' if no colour was drawn
27272  
27273 my (
27274 $self, $grid, $colour, $noColour, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
27275 $width, $height, $check
27276 ) = @_;
27277  
27278 # Local variables
27279 my (
27280 $type, $canvasObj,
27281 @emptyList,
27282 );
27283  
27284 # Check for improper arguments
27285 if (
27286 ! defined $grid || ! defined $leftAttach || ! defined $rightAttach
27287 || ! defined $topAttach || ! defined $bottomAttach || defined $check
27288 ) {
27289 $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleCanvas', @_);
27290 return @emptyList;
27291 }
27292  
27293 # Check that the position in table makes sense
27294 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
27295  
27296 return @emptyList;
27297 }
27298  
27299 # Use default $colour/width/height, if not specified
27300 if ($colour) {
27301  
27302 ($type) = $axmud::CLIENT->checkColourTags($colour);
27303 }
27304  
27305 if (! $colour || ! $type ) {
27306  
27307 # Check the neutral colour
27308 if ($noColour) {
27309  
27310 ($type) = $axmud::CLIENT->checkColourTags($noColour);
27311 }
27312  
27313 if (! $type) {
27314  
27315 # No colour is drawn
27316 $colour = undef;
27317  
27318 } else {
27319  
27320 # Use the neutral colour
27321 $colour = $noColour;
27322 }
27323 }
27324  
27325 # Make sure we have an RGB tag, not a different kind of colour tag
27326 if ($colour) {
27327  
27328 $colour = $axmud::CLIENT->returnRGBColour($colour);
27329 }
27330  
27331 # Use default width/height, if values not specified
27332 if (! defined $width) {
27333  
27334 $width = 30;
27335 }
27336  
27337 if (! defined $height) {
27338  
27339 $height = 30;
27340 }
27341  
27342 # Create a frame
27343 my $frame = Gtk3::Frame->new(undef);
27344 $frame->set_border_width(0);
27345 $frame->set_size_request($width, $height);
27346  
27347 # Create the canvas
27348 my $canvas = GooCanvas2::Canvas->new();
27349 $frame->add($canvas);
27350 $canvas->set_size_request($width, $height);
27351 $canvas->set_bounds(0, 0, $width, $height);
27352 $canvas->set_halign('GTK_ALIGN_CENTER');
27353 $canvas->set_valign('GTK_ALIGN_CENTER');
27354  
27355 # Add the frame to the table
27356 $frame->set_hexpand(FALSE);
27357 $frame->set_vexpand(FALSE);
27358 $grid->attach(
27359 $frame,
27360 $leftAttach,
27361 $topAttach,
27362 ($rightAttach - $leftAttach),
27363 ($bottomAttach - $topAttach),
27364 );
27365  
27366 # Fill the canvas with colour (if a colour was specified)
27367 if ($colour) {
27368  
27369 $canvasObj
27370 = $self->fillSimpleCanvas($canvas, undef, $colour, $noColour, $width, $height);
27371 }
27372  
27373 return ($frame, $canvas, $canvasObj);
27374 }
27375  
27376 sub fillSimpleCanvas {
27377  
27378 # Sets the background colour of the canvas drawn in the earlier call to
27379 # $self->addSimpleCanvas
27380 #
27381 # Expected arguments
27382 # $canvas - The existing GooCanvas2::Canvas
27383 #
27384 # Optional arguments
27385 # $oldObj - The existing GooCanvas2::CanvasRect, if there is one. Set to 'undef'
27386 # if this function is being called by $self->addSimpleCanvas, or if no
27387 # colour was drawn on the earlier call to ->addSimpleCanvas
27388 # $colour - The colour to draw on the canvas. Can be any valid Axmud colour tag
27389 # (e.g. 'red', 'x255', '#FF0000')
27390 # $noColour - If $colour is not specified or if it is invalid, this colour is used.
27391 # If $noColour is also not specified or invalid, then no colour is
27392 # drawn (no canvas object is drawn on the canvas)
27393 #
27394 # Optional arguments
27395 # $width, $height - The size, in pixels, of the canvas. If not specified, a default size
27396 # is applied that should fill the containing frame (assuming a
27397 # Gtk3::Grid using horizontal rows)
27398 #
27399 # Return values
27400 # 'undef' on improper arguments
27401 # The replacement GooCanvas2::CanvasRect otherwise
27402  
27403 my ($self, $canvas, $oldObj, $colour, $noColour, $width, $height, $check) = @_;
27404  
27405 # Local variables
27406 my ($type, $partX, $partY, $canvasObj);
27407  
27408 # Check for improper arguments
27409 if (! defined $canvas || defined $check) {
27410  
27411 return $axmud::CLIENT->writeImproper($self->_objClass . '->fillSimpleCanvas', @_);
27412 }
27413  
27414 # Use default $colour/width/height, if not specified
27415 if ($colour) {
27416  
27417 ($type) = $axmud::CLIENT->checkColourTags($colour);
27418 }
27419  
27420 if (! $colour || ! $type ) {
27421  
27422 # Check the neutral colour
27423 if ($noColour) {
27424  
27425 ($type) = $axmud::CLIENT->checkColourTags($noColour);
27426 }
27427  
27428 if (! $type) {
27429  
27430 # No colour is drawn
27431 $colour = undef;
27432  
27433 } else {
27434  
27435 # Use the neutral colour
27436 $colour = $noColour;
27437 }
27438 }
27439  
27440 # Make sure we have an RGB tag, not a different kind of colour tag
27441 if ($colour) {
27442  
27443 $colour = $axmud::CLIENT->returnRGBColour($colour);
27444 }
27445  
27446 # Use default width/height, if values not specified
27447 if (! defined $width) {
27448  
27449 $width = 30;
27450 }
27451  
27452 if (! defined $height) {
27453  
27454 $height = 30;
27455 }
27456  
27457 # Destroy the old background rectangle, if there is one
27458 if ($oldObj) {
27459  
27460 $oldObj->remove();
27461 }
27462  
27463 # Draw the canvas object (if a colour was specified)
27464 if ($colour) {
27465  
27466 $canvasObj = GooCanvas2::CanvasRect->new(
27467 'parent' => $canvas->get_root_item(),
27468 'x' => 0,
27469 'y' => 0,
27470 'width' => $width,
27471 'height' => $height,
27472 # 'line-width' => 2,
27473 'stroke-color' => $colour,
27474 'fill-color' => $colour,
27475 );
27476  
27477 $canvasObj->lower();
27478 }
27479  
27480 # Drawing complete
27481 return $canvasObj;
27482 }
27483  
27484 sub addDrawingCanvas {
27485  
27486 # Adds a GooCanvas2::Canvas to the table for general drawing operations. For painting a
27487 # canvas as a single colour, use $self->addSimpleCanvas instead
27488 #
27489 # Example calls:
27490 # $self->addDrawingCanvas($grid,
27491 # undef, undef,
27492 # FALSE, FALSE,
27493 # 0, 12, 1, 12);
27494 # $self->addDrawingCanvas($grid,
27495 # 'motionFunc', 'clickFunc',
27496 # TRUE, TRUE,
27497 # 0, 12, 1, 12,
27498 # 500, 500);
27499 #
27500 # Expected arguments
27501 # $grid - The tab's Gtk3::Grid object
27502 # $clickFunc - A function to call whenever the user clicks on the canvas (which emits
27503 # the 'button-press-event' signal). If 'undef', the signal is ignored
27504 # ignored
27505 # $motionFunc - A function to call whenever mouse motion over the canvas is detected
27506 # which emits the 'motion-notify-event' signal). If 'undef', the
27507 # signal is ignored
27508 # $scrollHorizFlag, $scrollVertFlag
27509 # - Flags set to TRUE if the scolled window, in which the canvas appears,
27510 # scrolls; set to FALSE (or 'undef') otherwise
27511 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
27512 # - The position of the canvas in the table
27513 #
27514 # Optional arguments
27515 # $width, $height - The width and height of the canvas, in pixels. If not specified,
27516 # a default size of 300x200 is used
27517 #
27518 # Return values
27519 # 'undef' on improper arguments, or if a drawing canvas can't be created
27520 # Otherwise returns the GooCanvas2::Canvas created
27521  
27522 my (
27523 $self, $grid, $clickFunc, $motionFunc, $scrollHorizFlag, $scrollVertFlag, $leftAttach,
27524 $rightAttach, $topAttach, $bottomAttach, $width, $height, $check
27525 ) = @_;
27526  
27527 # Check for improper arguments
27528 if (
27529 ! defined $grid || ! defined $leftAttach || ! defined $rightAttach
27530 || ! defined $topAttach || ! defined $bottomAttach || defined $check
27531 ) {
27532 return $axmud::CLIENT->writeImproper($self->_objClass . '->addDrawingCanvas', @_);
27533 }
27534  
27535 # Check that the position in the table makes sense
27536 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
27537  
27538 return undef;
27539 }
27540  
27541 # Set default width/height, if necessary
27542 if (! defined $width) {
27543  
27544 $width = 300;
27545 }
27546  
27547 if (! defined $height) {
27548  
27549 $height = 200;
27550 }
27551  
27552 # Create a frame containing a scrolled window
27553 my $frame = Gtk3::Frame->new(undef);
27554 $frame->set_shadow_type($axmud::CLIENT->constShadowType);
27555  
27556 my $scrolledWin = Gtk3::ScrolledWindow->new();
27557 $frame->add($scrolledWin);
27558 $scrolledWin->set_size_request($width, $height);
27559 $scrolledWin->set_border_width(3);
27560  
27561 my $viewPort = Gtk3::Viewport->new(undef,undef);
27562 $scrolledWin->add($viewPort);
27563  
27564 # Set its scrolling policy
27565 if ($scrollHorizFlag && $scrollVertFlag) {
27566 $scrolledWin->set_policy('always','always');
27567 } elsif ($scrollHorizFlag) {
27568 $scrolledWin->set_policy('always', 'never');
27569 } elsif ($scrollVertFlag) {
27570 $scrolledWin->set_policy('never', 'always');
27571 } else {
27572 $scrolledWin->set_policy('never', 'never');
27573 }
27574  
27575 # Add the frame to the table
27576 $frame->set_hexpand(FALSE);
27577 $frame->set_vexpand(FALSE);
27578 $grid->attach(
27579 $frame,
27580 $leftAttach,
27581 $topAttach,
27582 ($rightAttach - $leftAttach),
27583 ($bottomAttach - $topAttach),
27584 );
27585  
27586 # Create the GooCanvas2 inside an event box (to detect the user's mouse)
27587 my $eventBox = Gtk3::EventBox->new();
27588 $viewPort->add($eventBox);
27589 $eventBox->add_events(['pointer-motion-mask', 'pointer-motion-hint-mask']);
27590  
27591 my $canvasWidget = GooCanvas2::Canvas->new();
27592 $eventBox->add($canvasWidget);
27593 $canvasWidget->set_size_request($width, $height);
27594 $canvasWidget->set_bounds(0, 0, $width, $height);
27595  
27596 # Detect mouse clicks over the drawing area
27597 $eventBox->signal_connect ('button-press-event' => sub {
27598  
27599 my ($widget, $event) = @_;
27600  
27601 if (! $clickFunc) {
27602  
27603 return undef;
27604  
27605 } else {
27606  
27607 # Inform the specified function of the co-ords of the mouse above the canvas
27608 return $self->$clickFunc($event->x, $event->y);
27609 }
27610 });
27611  
27612 # Detect mouse motion over the drawing area
27613 $eventBox->signal_connect ('motion-notify-event' => sub {
27614  
27615 my ($widget, $event) = @_;
27616  
27617 if (! $motionFunc) {
27618  
27619 return undef;
27620  
27621 } else {
27622  
27623 # Inform the specified function of the co-ords of the mouse above the canvas
27624 return $self->$motionFunc($event->x, $event->y);
27625 }
27626 });
27627  
27628 return $canvasWidget;
27629 }
27630  
27631 # Support functions for adding widgets
27632  
27633 sub checkPosn {
27634  
27635 # Called by $self->addLabel, etc
27636 # Checks the position of a widget in the Gtk3::Grid, to make sure the coordinates make
27637 # sense (that the right coordinate isn't lower than the left coordinate, for example)
27638 #
27639 # Expected arguments
27640 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
27641 # - The coordinates of the object in the page's table
27642 #
27643 # Return values
27644 # 'undef' on improper arguments or if the coordinates don't make sense
27645 # 1 otherwise
27646  
27647 my ($self, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $check) = @_;
27648  
27649 # Check for improper arguments
27650 if (
27651 ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
27652 || ! defined $bottomAttach || defined $check
27653 ) {
27654 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPosn', @_);
27655 }
27656  
27657 # Check coordinates
27658 if (
27659 $leftAttach < 0 || $topAttach < 0
27660 || $rightAttach < $leftAttach || $bottomAttach < $topAttach
27661 ) {
27662 return $self->writeWarning(
27663 'Bad table coordinates in \'' . $self->winType . '\' window: '
27664 . $leftAttach . ' '
27665 . $rightAttach . ' '
27666 . $topAttach . ' '
27667 . $bottomAttach,
27668 $self->_objClass . '->checkPosn',
27669 );
27670  
27671 } else {
27672  
27673 return 1;
27674 }
27675 }
27676  
27677 # Data accessors
27678  
27679 sub resetListData {
27680  
27681 # Replaces the data stored in a GA::Obj::SimpleList with the data stored in the specified
27682 # list
27683 #
27684 # Expected arguments
27685 # $slWidget - Reference to a GA::Obj::SimpleList
27686 # $listRef - Reference to a list which contains the replacement data
27687 # $number - The list is split into groups (e.g. the elements of
27688 # GA::Profile::World->barPatternList are split into groups of 6); $number
27689 # is the size of the group (6 in that example)
27690 #
27691 # Return values
27692 # 'undef' on improper arguments
27693 # 1 otherwise
27694  
27695 my ($self, $slWidget, $listRef, $number, $check) = @_;
27696  
27697 # Local variables
27698 my @dataList;
27699  
27700 # Check for improper arguments
27701 if (! defined $slWidget || ! defined $listRef || ! defined $number || defined $check) {
27702  
27703 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetListData_listIV', @_);
27704 }
27705  
27706 if (@$listRef) {
27707  
27708 # Insert the replacement data
27709 do {
27710  
27711 my @groupList;
27712  
27713 for (my $count = 0; $count < $number; $count++) {
27714  
27715 push (@groupList, shift @$listRef);
27716 }
27717  
27718 push (@dataList, \@groupList);
27719  
27720 } until (! @$listRef);
27721  
27722 @{$slWidget->{data}} = @dataList;
27723  
27724 } else {
27725  
27726 # Replacement data list is empty
27727 @{$slWidget->{data}} = ();
27728 }
27729  
27730 return 1;
27731 }
27732  
27733 sub resetSortListData {
27734  
27735 # Replaces the data stored in a GA::Obj::SimpleList with the data stored in the specified
27736 # list which we assume represents a hash in the form (key, value, key, value...)
27737 #
27738 # Expected arguments
27739 # $slWidget - Reference to a GA::Obj::SimpleList
27740 # $listRef - Reference to a list which contains the replacement data
27741 #
27742 # Return values
27743 # 'undef' on improper arguments
27744 # 1 otherwise
27745  
27746 my ($self, $slWidget, $listRef, $check) = @_;
27747  
27748 # Local variables
27749 my (
27750 @dataList,
27751 %hash,
27752 );
27753  
27754 # Check for improper arguments
27755 if (! defined $slWidget || ! defined $listRef || defined $check) {
27756  
27757 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetSortListData', @_);
27758 }
27759  
27760 if (@$listRef) {
27761  
27762 # Assuming the contents of the list reference contains a hash flattened into a list,
27763 # convert that data to a hash
27764 %hash = @$listRef;
27765  
27766 # Insert the replacement data
27767 foreach my $key (sort {lc($a) cmp lc($b)} (keys %hash)) {
27768  
27769 push (@dataList, [$key, $hash{$key}]);
27770 }
27771  
27772 @{$slWidget->{data}} = @dataList;
27773  
27774 } else {
27775  
27776 # Replacement data list is empty
27777 @{$slWidget->{data}} = ();
27778 }
27779  
27780 return 1;
27781 }
27782  
27783 sub getSimpleListData {
27784  
27785 # Get items of data from specified cells in the currently selected row of a simple list
27786 #
27787 # Expected arguments
27788 # $slWidget - The GA::Obj::SimpleList
27789 # @columnList - A list of column numbers on the simple list, e.g. the list (0, 2, 3)
27790 # represents the first, third and fourth columns.
27791 #
27792 # Return values
27793 # An empty list on improper arguments or if no row in the simple list is currently
27794 # selected
27795 # Otherwise, returns a list containing the items of data on the selected row, in the
27796 # specified columns
27797  
27798 my ($self, $slWidget, @columnList) = @_;
27799  
27800 # Local variables
27801 my (
27802 $index, $rowRef,
27803 @emptyList, @dataList,
27804 );
27805  
27806 # Check for improper arguments
27807 if (! defined $slWidget || ! @columnList) {
27808  
27809 $axmud::CLIENT->writeImproper($self->_objClass . '->getSimpleListData', @_);
27810 return @emptyList;
27811 }
27812  
27813 # Get the currently selected row's number (if any)
27814 ($index) = $slWidget->get_selected_indices();
27815 if (defined $index) {
27816  
27817 # Get the selected row itself
27818 $rowRef = ${$slWidget->{data}}[$index];
27819  
27820 # Get items of data from this row
27821 foreach my $column (@columnList) {
27822  
27823 push (@dataList, $$rowRef[$column]);
27824 }
27825 }
27826  
27827 return @dataList;
27828 }
27829  
27830 ##################
27831 # Accessors - set
27832  
27833 sub add_childDestroy {
27834  
27835 # Called by anything
27836  
27837 my ($self, $winObj, $func, $argListRef, $check) = @_;
27838  
27839 # Local variables
27840 my $listRef;
27841  
27842 # Check for improper arguments
27843 if (! defined $winObj || ! defined $func || ! defined $argListRef || defined $check) {
27844  
27845 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_childDestroy', @_);
27846 }
27847  
27848 if (! $self->ivExists('childFreeWinHash', $winObj->number)) {
27849  
27850 return undef;
27851  
27852 } else {
27853  
27854 if ($self->ivExists('childDestroyHash', $winObj->number)) {
27855  
27856 $listRef = $self->ivShow('childDestroyHash', $winObj->number);
27857 push (@$listRef, $func, $argListRef);
27858  
27859 } else {
27860  
27861 $self->ivAdd(
27862 'childDestroyHash',
27863 $winObj->number,
27864 [$func, $argListRef],
27865 );
27866 }
27867  
27868 return 1;
27869 }
27870 }
27871  
27872 sub add_childFreeWin {
27873  
27874 # Called by $self->createFreeWin
27875  
27876 my ($self, $obj, $check) = @_;
27877  
27878 # Check for improper arguments
27879 if (! defined $obj || defined $check) {
27880  
27881 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_childFreeWin', @_);
27882 }
27883  
27884 $self->ivAdd('childFreeWinHash', $obj->number, $obj);
27885  
27886 return 1;
27887 }
27888  
27889 sub del_childFreeWin {
27890  
27891 # Called by GA::Generic::FreeWin->winDestroy
27892  
27893 my ($self, $obj, $check) = @_;
27894  
27895 # Local variables
27896 my $listRef;
27897  
27898 # Check for improper arguments
27899 if (! defined $obj || defined $check) {
27900  
27901 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_childFreeWin', @_);
27902 }
27903  
27904 if (! $self->ivExists('childFreeWinHash', $obj->number)) {
27905  
27906 return undef;
27907  
27908 } else {
27909  
27910 # Call some of this window's own functions to obj->number various widgets/IVs
27911 $listRef = $self->ivShow('childDestroyHash', $obj->number);
27912 if (defined $listRef) {
27913  
27914 do {
27915  
27916 my ($func, $argListRef);
27917  
27918 $func = shift @$listRef;
27919 $argListRef = shift @$listRef;
27920  
27921 if (defined $func && defined $argListRef) {
27922  
27923 $self->$func(@$argListRef);
27924 }
27925  
27926 } until (! @$listRef);
27927 }
27928  
27929 # Update IVs
27930 $self->ivDelete('childFreeWinHash', $obj->number);
27931 $self->ivDelete('childDestroyHash', $obj->number);
27932  
27933 return 1;
27934 }
27935 }
27936  
27937 sub set_enabledFlag {
27938  
27939 my ($self, $flag, $check) = @_;
27940  
27941 # Check for improper arguments
27942 if (! defined $flag || defined $check) {
27943  
27944 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_enabledFlag', @_);
27945 }
27946  
27947 if ($flag) {
27948 $self->ivPoke('enabledFlag', TRUE);
27949 } else {
27950 $self->ivPoke('enabledFlag', FALSE);
27951 }
27952  
27953 return 1;
27954 }
27955  
27956 sub set_owner {
27957  
27958 my ($self, $owner, $check) = @_;
27959  
27960 # Check for improper arguments
27961 if (defined $check) {
27962  
27963 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_owner', @_);
27964 }
27965  
27966 $self->ivPoke('owner', $owner);
27967  
27968 return 1;
27969 }
27970  
27971 sub set_session {
27972  
27973 my ($self, $session, $check) = @_;
27974  
27975 # Check for improper arguments
27976 if (defined $check) {
27977  
27978 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_session', @_);
27979 }
27980  
27981 $self->ivPoke('session', $session);
27982  
27983 return 1;
27984 }
27985  
27986 sub set_winBox {
27987  
27988 my ($self, $winBox, $check) = @_;
27989  
27990 # Check for improper arguments
27991 if (defined $check) {
27992  
27993 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winBox', @_);
27994 }
27995  
27996 $self->ivPoke('winBox', $winBox);
27997  
27998 return 1;
27999 }
28000  
28001 sub set_winWidget {
28002  
28003 my ($self, $winWidget, $check) = @_;
28004  
28005 # Check for improper arguments
28006 if (defined $check) {
28007  
28008 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winWidget', @_);
28009 }
28010  
28011 $self->ivPoke('winWidget', $winWidget);
28012  
28013 return 1;
28014 }
28015  
28016 sub set_workspaceObj {
28017  
28018 my ($self, $workspaceObj, $check) = @_;
28019  
28020 # Check for improper arguments
28021 if (! defined $workspaceObj || defined $check) {
28022  
28023 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_workspaceObj', @_);
28024 }
28025  
28026 $self->ivPoke('workspaceObj', $workspaceObj);
28027  
28028 return 1;
28029 }
28030  
28031 sub set_workspaceGridObj {
28032  
28033 my ($self, $gridObj, $check) = @_;
28034  
28035 # Check for improper arguments
28036 if (! defined $gridObj || defined $check) {
28037  
28038 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_workspaceGridObj', @_);
28039 }
28040  
28041 $self->ivPoke('workspaceGridObj', $gridObj);
28042  
28043 return 1;
28044 }
28045  
28046 ##################
28047 # Accessors - get
28048  
28049 sub number
28050 { $_[0]->{number} }
28051 sub winCategory
28052 { $_[0]->{winCategory} }
28053 sub winType
28054 { $_[0]->{winType} }
28055 sub winName
28056 { $_[0]->{winName} }
28057 sub workspaceObj
28058 { $_[0]->{workspaceObj} }
28059 sub owner
28060 { $_[0]->{owner} }
28061 sub session
28062 { $_[0]->{session} }
28063 sub pseudoCmdMode
28064 { $_[0]->{pseudoCmdMode} }
28065  
28066 sub winWidget
28067 { $_[0]->{winWidget} }
28068 sub winBox
28069 { $_[0]->{winBox} }
28070 sub enabledFlag
28071 { $_[0]->{enabledFlag} }
28072 sub visibleFlag
28073 { $_[0]->{visibleFlag} }
28074 sub childFreeWinHash
28075 { my $self = shift; return %{$self->{childFreeWinHash}}; }
28076 sub childDestroyHash
28077 { my $self = shift; return %{$self->{childDestroyHash}}; }
28078  
28079 sub packingBox
28080 { $_[0]->{packingBox} }
28081 }
28082  
28083 { package Games::Axmud::Generic::WizWin;
28084  
28085 use strict;
28086 use warnings;
28087 # use diagnostics;
28088  
28089 use Glib qw(TRUE FALSE);
28090  
28091 our @ISA = qw(
28092 Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud
28093 );
28094  
28095 ##################
28096 # Constructors
28097  
28098 sub new {
28099  
28100 # Called by GA::Generic::Win->createFreeWin
28101 # Creates a new instance of a 'wiz' window
28102 #
28103 # Expected arguments
28104 # $number - Unique number for this window object
28105 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
28106 # should be created
28107 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
28108 # 'free' window object. When this window opens/closes, the owner is
28109 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
28110 # functions
28111 #
28112 # Optional arguments
28113 # $session - The GA::Session from which this function was called. 'undef' if the
28114 # calling function didn't specify a session and $owner's ->session IV
28115 # is also 'undef'
28116 # $title - A string to use as the window title. If 'undef', a generic title is
28117 # used
28118 # $editObj - Ignored if set
28119 # $tempFlag - Ignored if set
28120 # %configHash - Hash containing any number of key-value pairs needed for this
28121 # particular 'wiz' window; for example, for example,
28122 # GA::PrefWin::TaskStart uses it to specify a task name and type. Set
28123 # to an empty hash if not required
28124 # - This type of window object recognises these initialisation settings:
28125 #
28126 # ...
28127 #
28128 # Return values
28129 # 'undef' on improper arguments
28130 # Blessed reference to the newly-created object on success
28131  
28132 my (
28133 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
28134 %configHash,
28135 ) = @_;
28136  
28137 # Check for improper arguments
28138 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
28139  
28140 return $axmud::CLIENT->writeImproper($class . '->new', @_);
28141 }
28142  
28143 # Set the values to use for some standard window IVs
28144 if (! $title) {
28145  
28146 $title = 'Wizard window';
28147 }
28148  
28149 # Setup
28150 my $self = {
28151 _objName => 'wiz_win_' . $number,
28152 _objClass => $class,
28153 _parentFile => undef, # No parent file object
28154 _parentWorld => undef, # No parent file object
28155 _privFlag => TRUE, # All IVs are private
28156  
28157 # Standard window object IVs
28158 # --------------------------
28159  
28160 # Unique number for this window object
28161 number => $number,
28162 # The window category - 'grid' or 'free'
28163 winCategory => 'free',
28164 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
28165 winType => 'wiz',
28166 # A name for the window (for 'config' windows, the same as the window type)
28167 winName => 'wiz',
28168 # The GA::Obj::Workspace object for the workspace in which this window is created
28169 workspaceObj => $workspaceObj,
28170 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
28171 # object. When this window opens/closes, the owner is informed via calls to its
28172 # ->add_childFreeWin / ->del_childFreeWin functions
28173 owner => $owner,
28174 # The GA::Session from which this function was called. 'undef' if the calling function
28175 # didn't specify a session and $owner's ->session IV is also 'undef'
28176 session => $session,
28177 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
28178 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
28179 # displayed in a 'dialogue' window)
28180 pseudoCmdMode => 'win_error',
28181  
28182 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
28183 # parent 'main' window's Gtk3::Window
28184 # The code should use this IV when it wants to do something to the window itself
28185 # (minimise it, make it active, etc)
28186 winWidget => undef,
28187 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
28188 # the parent GA::Table::PseudoWin table object
28189 # The code should use this IV when it wants to add, modify or remove widgets inside the
28190 # window itself
28191 winBox => undef,
28192 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
28193 # FALSE if not
28194 enabledFlag => FALSE,
28195 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
28196 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
28197 visibleFlag => TRUE,
28198 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
28199 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
28200 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
28201 childFreeWinHash => {},
28202 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
28203 # window is informed via a call to $self->del_childFreeWin
28204 # When the child is destroyed, this window might want to call some of its own functions
28205 # to update various widgets and/or IVs, in which case this window adds an entry to
28206 # this hash; a hash in the form
28207 # $childDestroyHash{unique_number} = list_reference
28208 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
28209 # reference to a list in groups of 2, in the form
28210 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
28211 childDestroyHash => {},
28212  
28213 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
28214 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
28215 # area)
28216 packingBox => undef, # Gtk3::VBox
28217  
28218 # Standard IVs for 'free' windows
28219  
28220 # The window's default size, in pixels
28221 widthPixels => $axmud::CLIENT->customFreeWinWidth,
28222 heightPixels => $axmud::CLIENT->customFreeWinHeight,
28223 # Default border/item spacing sizes used in the window, in pixels
28224 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
28225 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
28226  
28227 # A string to use as the window title. If 'undef', a generic title is used
28228 title => $title,
28229 # Hash containing any number of key-value pairs needed for this particular 'wiz'
28230 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
28231 # name and type. Set to an empty hash if not required
28232 configHash => {%configHash},
28233  
28234 # Standard IVs for 'wiz' windows
28235  
28236 # Widgets
28237 scroller => undef, # Gtk3::ScrolledWindow
28238 hAdjustment => undef, # Gtk3::Adjustment
28239 vAdjustment => undef, # Gtk3::Adjustment
28240 grid => undef, # Gtk3::Grid
28241 hBox => undef, # Gtk3::HBox
28242 nextButton => undef, # Gtk3::Button
28243 previousButton => undef, # Gtk3::Button
28244 cancelButton => undef, # Gtk3::Button
28245  
28246 # Three flags that can be set by any page, to prevent one of three buttons from being
28247 # made sensitive (temporarily)
28248 disableNextButtonFlag => FALSE,
28249 disablePreviousButtonFlag => FALSE,
28250 disableCancelButtonFlag => FALSE,
28251  
28252 # The names of pages, in order of appearance
28253 pageList => [
28254 # 'example', # Corresponds to function $self->examplePage
28255 # 'example2',
28256 # 'example3',
28257 ],
28258 # The number of the current page (first page is 0)
28259 currentPage => 0,
28260  
28261 # Two hashes for using the 'Next' / 'Previous' buttons to skip around the pages, rather
28262 # than going to the actual next or previous page (as normal)
28263 # The current page should add an entry to the hash, if necessary; the entry is removed
28264 # by ->buttonPrevious or ->buttonNext as soon as either button is clicked
28265 # Hashes in the form
28266 # $hash{current_page_number} = page_number_if_button_clicked
28267 # NB The first page's number is 0, so the fourth page will be page 3, not page 4
28268 specialNextButtonHash => {},
28269 specialPreviousButtonHash => {},
28270 };
28271  
28272 # Bless the object into existence
28273 bless $self, $class;
28274  
28275 return $self;
28276 }
28277  
28278 ##################
28279 # Methods
28280  
28281 # Standard window object functions
28282  
28283 # sub winSetup {} # Inherited from GA::Generic::FreeWin
28284  
28285 sub winEnable {
28286  
28287 # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup
28288 # After the Gtk3::Window has been setup and moved into position, makes it visible
28289 #
28290 # Expected arguments
28291 # (none besides $self)
28292 #
28293 # Return values
28294 # 'undef' on improper arguments
28295 # 1 on success
28296  
28297 my ($self, $check) = @_;
28298  
28299 # Check for improper arguments
28300 if (defined $check) {
28301  
28302 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
28303 }
28304  
28305 # Make the window appear on the desktop
28306 $self->winShowAll($self->_objClass . '->winEnable');
28307 $self->ivPoke('enabledFlag', TRUE);
28308  
28309 # This type of window is usually unique to its GA::Session (only one can be open at any
28310 # time, per session); inform the session it has opened
28311 # Exception - if $self->session isn't set at all (presumably because there are no sessions
28312 # running), then there's no-one to inform
28313 if ($self->session) {
28314  
28315 $self->session->set_wizWin($self);
28316 }
28317  
28318 return 1;
28319 }
28320  
28321 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
28322  
28323 sub winDestroy {
28324  
28325 # Can be called by anything
28326 # Updates IVs
28327 #
28328 # Expected arguments
28329 # (none besides $self)
28330 #
28331 # Return values
28332 # 'undef' on improper arguments, if the window can't be destroyed or if it has already
28333 # been destroyed
28334 # 1 on success
28335  
28336 my ($self, $check) = @_;
28337  
28338 # Check for improper arguments
28339 if (defined $check) {
28340  
28341 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_);
28342 }
28343  
28344 if (! $self->winBox) {
28345  
28346 # Window already destroyed in a previous call to this function
28347 return undef;
28348 }
28349  
28350 # Close any 'free' windows for which this window is a parent
28351 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
28352  
28353 $winObj->winDestroy();
28354 }
28355  
28356 # Destroy the Gtk3::Window
28357 eval { $self->winBox->destroy(); };
28358 if ($@) {
28359  
28360 # Window can't be destroyed
28361 return undef;
28362  
28363 } else {
28364  
28365 $self->ivUndef('winWidget');
28366 $self->ivUndef('winBox');
28367 }
28368  
28369 # Inform the owner and the desktop object of this 'free' window's demise
28370 $axmud::CLIENT->desktopObj->del_freeWin($self);
28371 if ($self->owner) {
28372  
28373 $self->owner->del_childFreeWin($self);
28374 }
28375  
28376 # This type of window is usually unique to its GA::Session (only one can be open at any
28377 # time, per session); inform the session it has closed
28378 # Exception - if $self->session isn't set at all (presumably because there are no sessions
28379 # running), then there's no-one to inform
28380 if ($self->session) {
28381  
28382 $self->session->set_wizWin();
28383 }
28384  
28385 return 1;
28386 }
28387  
28388 # sub winShowAll {} # Inherited from GA::Generic::Win
28389  
28390 sub drawWidgets {
28391  
28392 # Called by $self->winSetup
28393 # Sets up the 'wiz' window with its standard widgets
28394 #
28395 # Expected arguments
28396 # (none besides $self)
28397 #
28398 # Return values
28399 # 'undef' on improper arguments
28400 # 1 otherwise
28401  
28402 my ($self, $check) = @_;
28403  
28404 # Check for improper arguments
28405 if (defined $check) {
28406  
28407 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
28408 }
28409  
28410 # Create a packing box
28411 my $packingBox = Gtk3::VBox->new(FALSE, 0);
28412 $self->winBox->add($packingBox);
28413 $packingBox->set_border_width(0);
28414  
28415 # Add a grid (inside a scrolled window) in the higher area
28416 my $frame = Gtk3::Frame->new(undef);
28417 $packingBox->pack_start($frame, TRUE, TRUE, 0);
28418 $frame->set_border_width($self->spacingPixels);
28419  
28420 my $scroller = Gtk3::ScrolledWindow->new(undef, undef);
28421 $frame->add($scroller);
28422 $scroller->set_policy('automatic', 'automatic');
28423 $scroller->set_border_width(0);
28424  
28425 my $grid = Gtk3::Grid->new();
28426 $scroller->add_with_viewport($grid);
28427 $grid->set_column_spacing($self->spacingPixels);
28428 $grid->set_row_spacing($self->spacingPixels);
28429 $grid->set_border_width($self->borderPixels);
28430  
28431 # Add a button strip at the bottom, in a horizontal packing box
28432 my $hBox = Gtk3::HBox->new(FALSE, 0);
28433 $packingBox->pack_end($hBox, FALSE, FALSE, 5);
28434  
28435 # Create 'Next'/'Previous'/'Cancel' buttons
28436 my ($nextButton, $previousButton, $cancelButton) = $self->enableButtons($hBox);
28437  
28438 # Update IVs
28439 $self->ivPoke('packingBox', $packingBox);
28440 $self->ivPoke('scroller', $scroller);
28441 $self->ivPoke('hAdjustment', $scroller->get_hadjustment());
28442 $self->ivPoke('vAdjustment', $scroller->get_vadjustment());
28443 $self->ivPoke('grid', $grid);
28444 $self->ivPoke('hBox', $hBox);
28445 $self->ivPoke('nextButton', $nextButton);
28446 $self->ivPoke('previousButton', $previousButton);
28447 $self->ivPoke('cancelButton', $cancelButton);
28448  
28449 # Set up the grid with its initial contents
28450 $self->setupGrid();
28451  
28452 return 1;
28453 }
28454  
28455 # sub redrawWidgets {} # Inherited from GA::Generic::Win
28456  
28457 # ->signal_connects
28458  
28459 # Other functions
28460  
28461 sub enableButtons {
28462  
28463 # Called by $self->drawWidgets
28464 # Creates the Next/Previous/Cancel buttons at the bottom of the window
28465 # Individual 'wiz' windows almost always inherit the generic ->winEnable method, but can
28466 # use their own $self->enableButtons (rather than inherit this one) if they need
28467 # a different set of buttons
28468 #
28469 # Expected arguments
28470 # $hBox - The horizontal packing box in which the buttons live (not yet stored as
28471 # an IV)
28472 #
28473 # Return values
28474 # An empty list on improper arguments
28475 # Otherwise, a list containing the three Gtk::Button objects created
28476  
28477 my ($self, $hBox, $check) = @_;
28478  
28479 # Local variables
28480 my @emptyList;
28481  
28482 # Check for improper arguments
28483 if (! defined $hBox || defined $check) {
28484  
28485 $axmud::CLIENT->writeImproper($self->_objClass . '->enableButtons', @_);
28486 return @emptyList;
28487 }
28488  
28489 # Create the Next button - which also acts as a 'Finish' button once the user has
28490 # finished making changes
28491 my $nextButton = Gtk3::Button->new('Next');
28492 $hBox->pack_end($nextButton, FALSE, FALSE, $self->borderPixels);
28493 $nextButton->get_child->set_width_chars(10);
28494 $nextButton->signal_connect('clicked' => sub {
28495  
28496 $self->buttonNext();
28497 });
28498 $nextButton->set_tooltip_text('Move on to the next page');
28499  
28500 # Create the Previous button
28501 my $prevButton = Gtk3::Button->new('Previous');
28502 $hBox->pack_end($prevButton, FALSE, FALSE, $self->spacingPixels);
28503 $prevButton->get_child->set_width_chars(10);
28504 $prevButton->signal_connect('clicked' => sub {
28505  
28506 $self->buttonPrevious();
28507 });
28508 $prevButton->set_tooltip_text('Go back to the previous page');
28509 $prevButton->set_sensitive(FALSE); # Because 1st page is showing, starts desensitised
28510  
28511 # Create the Cancel button
28512 my $cancelButton = Gtk3::Button->new('Cancel');
28513 $hBox->pack_start($cancelButton, FALSE, FALSE, $self->borderPixels);
28514 $cancelButton->get_child->set_width_chars(10);
28515 $cancelButton->signal_connect('clicked' => sub {
28516  
28517 $self->buttonCancel();
28518 });
28519 $cancelButton->set_tooltip_text('Cancel changes and close this window');
28520  
28521 return ($nextButton, $prevButton, $cancelButton);
28522 }
28523  
28524 sub setupGrid {
28525  
28526 # Called by $self->winEnable
28527 # Creates the first page for the wizard (not really necessary to have a whole function
28528 # dedicated to this task, but having one keeps the design of 'wiz' windows consistent
28529 # with the design of 'edit'/'pref' windows)
28530 #
28531 # Expected arguments
28532 # (none besides $self)
28533 #
28534 # Return values
28535 # 'undef' on improper arguments
28536 # 1 otherwise
28537  
28538 my ($self, $check) = @_;
28539  
28540 # Local variables
28541 my ($func, $rows);
28542  
28543 # Check for improper arguments
28544 if (defined $check) {
28545  
28546 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupGrid', @_);
28547 }
28548  
28549 # Get the name of the function for the first page
28550 $func = $self->ivIndex('pageList', $self->currentPage) . 'Page';
28551 # Call the function
28552 $rows = $self->$func();
28553  
28554 return 1;
28555 }
28556  
28557 sub updateGrid {
28558  
28559 # Called by $self->buttonPrevious and ->buttonNext
28560 # Changes the page currently visible in the 'wiz' window
28561 #
28562 # Expected arguments
28563 # (none besides $self)
28564 #
28565 # Return values
28566 # 'undef' on improper arguments
28567 # 1 otherwise
28568  
28569 my ($self, $check) = @_;
28570  
28571 # Local variables
28572 my ($func, $rows);
28573  
28574 # Check for improper arguments
28575 if (defined $check) {
28576  
28577 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateGrid', @_);
28578 }
28579  
28580 # Empty the grid used for the existing page
28581 foreach my $widget ($self->grid->get_children()) {
28582  
28583 $axmud::CLIENT->desktopObj->removeWidget($self->grid, $widget);
28584 }
28585  
28586 # Get the name of the function for the new current page
28587 $func = $self->ivIndex('pageList', $self->currentPage) . 'Page';
28588 # Call the function
28589 $rows = $self->$func();
28590  
28591 # Set button sensititives ($self->disableNextButtonFlag, etc, override the usual rules, if
28592 # they are set)
28593  
28594 # If it's the first page, the 'Previous' button must not be sensitive
28595 if ($self->currentPage == 0) {
28596  
28597 $self->previousButton->set_sensitive(FALSE);
28598  
28599 if (! $self->disableNextButtonFlag) {
28600 $self->nextButton->set_sensitive(TRUE);
28601 } else {
28602 $self->nextButton->set_sensitive(FALSE);
28603 }
28604  
28605 # Make sure the 'Next' button has the right label
28606 $self->nextButton->set_label('Next');
28607 $self->nextButton->get_child->set_width_chars(10);
28608  
28609 # If it's the last page, the 'Next' button must be converted to a 'Finish' button
28610 } elsif ($self->currentPage >= ((scalar $self->pageList) - 1)) {
28611  
28612 if (! $self->disablePreviousButtonFlag) {
28613 $self->previousButton->set_sensitive(TRUE);
28614 } else {
28615 $self->previousButton->set_sensitive(FALSE);
28616 }
28617  
28618 $self->nextButton->set_sensitive(TRUE);
28619 $self->nextButton->set_label('Finish');
28620 $self->nextButton->get_child->set_width_chars(10);
28621  
28622 # For all other pages, both buttons are sensitised
28623 } else {
28624  
28625 if (! $self->disableNextButtonFlag) {
28626 $self->nextButton->set_sensitive(TRUE);
28627 } else {
28628 $self->nextButton->set_sensitive(FALSE);
28629 }
28630  
28631 if (! $self->disablePreviousButtonFlag) {
28632 $self->previousButton->set_sensitive(TRUE);
28633 } else {
28634 $self->previousButton->set_sensitive(FALSE);
28635 }
28636  
28637 # Make sure the 'Next' button has the right label
28638 $self->nextButton->set_label('Next');
28639 $self->nextButton->get_child->set_width_chars(10);
28640 }
28641  
28642 # Reset the disable flags. It's up to individual pages to set them, when they're needed
28643 $self->ivPoke('disableNextButtonFlag', FALSE);
28644 $self->ivPoke('disablePreviousButtonFlag', FALSE);
28645 $self->ivPoke('disableCancelButtonFlag', FALSE);
28646  
28647 # Make sure the window has scrolled to the top
28648 $self->hAdjustment->set_value(0);
28649 $self->vAdjustment->set_value(0);
28650  
28651 # Make the page visible
28652 $self->winShowAll($self->_objClass . '->updateGrid');
28653  
28654 return 1;
28655 }
28656  
28657 sub saveChanges {
28658  
28659 # Generic ->saveChanges function which doesn't do anything other than to close the 'wiz'
28660 # window
28661 # Each 'wiz' window should have its own ->saveChanges function
28662 #
28663 # Expected arguments
28664 # (none besides $self)
28665 #
28666 # Return values
28667 # 'undef' on improper arguments
28668 # 1 otherwise
28669  
28670 my ($self, $check) = @_;
28671  
28672 # Check for improper arguments
28673 if (defined $check) {
28674  
28675 return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
28676 }
28677  
28678 # Close the 'wiz' window
28679 $self->winDestroy();
28680  
28681 return 1;
28682 }
28683  
28684 sub getPageString {
28685  
28686 # Can be called by any ->XXXPage function
28687 # Returns a string in the format 'page a/b', where 'a' is the number of the current page,
28688 # and 'b' the number of the last page
28689 #
28690 # Expected arguments
28691 # (none besides $self)
28692 #
28693 # Return values
28694 # 'undef' on improper arguments
28695 # 1 otherwise
28696  
28697 my ($self, $check) = @_;
28698  
28699 # Check for improper arguments
28700 if (defined $check) {
28701  
28702 return $axmud::CLIENT->writeImproper($self->_objClass . '->getPageString', @_);
28703 }
28704  
28705 return 'Page ' . ($self->currentPage + 1) . '/' . (scalar $self->pageList);
28706 }
28707  
28708 # Standard callbacks
28709  
28710 sub buttonCancel {
28711  
28712 # 'Cancel' button callback
28713 #
28714 # Expected arguments
28715 # (none besides $self)
28716 #
28717 # Return values
28718 # 'undef' on improper arguments
28719 # 1 otherwise
28720  
28721 my ($self, $check) = @_;
28722  
28723 # Check for improper arguments
28724 if (defined $check) {
28725  
28726 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonCancel', @_);
28727 }
28728  
28729 # Close the window
28730 $self->winDestroy();
28731  
28732 return 1;
28733 }
28734  
28735 sub buttonPrevious {
28736  
28737 # 'Previous' button callback
28738 #
28739 # Expected arguments
28740 # (none besides $self)
28741 #
28742 # Return values
28743 # 'undef' on improper arguments
28744 # 1 otherwise
28745  
28746 my ($self, $check) = @_;
28747  
28748 # Check for improper arguments
28749 if (defined $check) {
28750  
28751 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonPrevious', @_);
28752 }
28753  
28754 # Reset the hash of functions to call when a child window is closed, ready for it to be
28755 # refilled
28756 $self->ivEmpty('childDestroyHash');
28757  
28758 # Has a special rule been set for the current page?
28759 if ($self->ivExists('specialPreviousButtonHash', $self->currentPage)) {
28760  
28761 # Go to the specified page, instead of the next one
28762 $self->ivPoke(
28763 'currentPage',
28764 $self->ivShow('specialPreviousButtonHash', $self->currentPage),
28765 );
28766  
28767 } elsif ($self->currentPage > 0) {
28768  
28769 # Just go to the previous page (unless, for some unlikely reason, we're already there)
28770 $self->ivDecrement('currentPage');
28771 }
28772  
28773 # Cancel any special rules - it's up to the new page to set them, as and when required
28774 $self->ivEmpty('specialNextButtonHash');
28775 $self->ivEmpty('specialPreviousButtonHash');
28776  
28777 # Display the page
28778 $self->updateGrid();
28779  
28780 return 1;
28781 }
28782  
28783 sub buttonNext {
28784  
28785 # 'Next' button callback
28786 #
28787 # Expected arguments
28788 # (none besides $self)
28789 #
28790 # Return values
28791 # 'undef' on improper arguments
28792 # 1 otherwise
28793  
28794 my ($self, $check) = @_;
28795  
28796 # Check for improper arguments
28797 if (defined $check) {
28798  
28799 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonNext', @_);
28800 }
28801  
28802 # If we're on the last page, the 'Finish' button has been clicked
28803 if ($self->currentPage >= ((scalar $self->pageList) - 1)) {
28804  
28805 $self->saveChanges();
28806  
28807 # Otherwise, it's the 'Next' button. Set the next page
28808 } else {
28809  
28810 # Reset the hash of functions to call when a child window is closed, ready for it to be
28811 # refilled
28812 $self->ivEmpty('childDestroyHash');
28813  
28814 # Has a special rule been set for the current page?
28815 if ($self->ivExists('specialNextButtonHash', $self->currentPage)) {
28816  
28817 # Go to the specified page, instead of the next one
28818 $self->ivPoke(
28819 'currentPage',
28820 $self->ivShow('specialNextButtonHash', $self->currentPage),
28821 );
28822  
28823 } else {
28824  
28825 # Just go to the next page
28826 $self->ivIncrement('currentPage');
28827 }
28828  
28829 # Cancel any special rules - it's up to the new page to set them, as and when required
28830 $self->ivEmpty('specialNextButtonHash');
28831 $self->ivEmpty('specialPreviousButtonHash');
28832  
28833 # Display the page
28834 $self->updateGrid();
28835 }
28836  
28837 return 1;
28838 }
28839  
28840 ##################
28841 # Accessors - set
28842  
28843 ##################
28844 # Accessors - get
28845  
28846 sub scroller
28847 { $_[0]->{scroller} }
28848 sub hAdjustment
28849 { $_[0]->{hAdjustment} }
28850 sub vAdjustment
28851 { $_[0]->{vAdjustment} }
28852 sub grid
28853 { $_[0]->{grid} }
28854 sub hBox
28855 { $_[0]->{hBox} }
28856 sub nextButton
28857 { $_[0]->{nextButton} }
28858 sub previousButton
28859 { $_[0]->{previousButton} }
28860 sub cancelButton
28861 { $_[0]->{cancelButton} }
28862  
28863 sub disableNextButtonFlag
28864 { $_[0]->{disableNextButtonFlag} }
28865 sub disablePreviousButtonFlag
28866 { $_[0]->{disablePreviousButtonFlag} }
28867 sub disableCancelButtonFlag
28868 { $_[0]->{disableCancelButtonFlag} }
28869  
28870 sub pageList
28871 { my $self = shift; return @{$self->{pageList}}; }
28872 sub currentPage
28873 { $_[0]->{currentPage} }
28874  
28875 sub specialNextButtonHash
28876 { my $self = shift; return %{$self->{specialNextButtonHash}}; }
28877 sub specialPreviousButtonHash
28878 { my $self = shift; return %{$self->{specialPreviousButtonHash}}; }
28879 }
28880  
28881 # Package must return a true value
28882 1