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

filter: Statementstmt 0.0% 0 / 3513 Branchbran 0.0% 0 / 1086 Conditioncond 0.0% 0 / 618 MC/DCmcdc 0.0% 0 / 362 Subroutinesub 0.0% 0 / 211 Podpod 0.0% 0 / 187 totaltotal 0.0% 0 / 5977 CC 544 SCAR 53.3
CC
544
Cov
0%
drawFileColumn
1190.0
drawGauges
812.0
objEnable
600.0
CRAP 206.6
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::Strip::xxx
16 # Objects handling strips within an 'internal' window's client area
17  
18 { package Games::Axmud::Strip::MenuBar;
19  
20 use strict;
21 use warnings;
22 # use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
27  
28 ##################
29 # Constructors
30  
31 sub new {
32  
33 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
34 # Creates the GA::Strip::MenuBar - a non-compulsory strip object containing a Gtk3::MenuBar
35 #
36 # Expected arguments
37 # $number - The strip object's number within the parent window (matches
38 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
39 # created to access its default IVs)
40 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
41 # objects
42 #
43 # Optional arguments
44 # %initHash - A hash containing arbitrary data to use as the strip object's
45 # initialisation settings. The strip object should use default
46 # initialisation settings unless it can succesfully interpret one or more
47 # of the key-value pairs in the hash, if there are any
48 # - (This type of strip object requires no initialisation settings)
49 #
50 # Return values
51 # 'undef' on improper arguments
52 # Blessed reference to the newly-created object on success
53  
54 my ($class, $number, $winObj, %initHash) = @_;
55  
56 # Local variables
57 my %modHash;
58  
59 # Check for improper arguments
60 if (! defined $class || ! defined $number || ! defined $winObj) {
61  
62 return $axmud::CLIENT->writeImproper($class . '->new', @_);
63 }
64  
65 # Setup
66 my $self = {
67 _objName => 'strip_' . $number,
68 _objClass => $class,
69 _parentFile => undef, # No parent file object
70 _parentWorld => undef, # No parent file object
71 _privFlag => TRUE, # All IVs are private
72  
73 # Standard strip object IVs
74 # -------------------------
75  
76 # The strip object's number within the parent window (matches
77 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
78 # its default IVs)
79 number => $number,
80 # The type of strip object (custom strip objects should use a ->type starting with
81 # 'custom_' to avoid clashing with future built-in strip objects)
82 type => 'menu_bar',
83 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
84 winObj => $winObj,
85  
86 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
87 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
88 # still exists in GA::Win::Internal->stripHash, etc)
89 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
90 # have gauges to draw, or not, depending on current conditions. (Most strip objects
91 # have this flag set to TRUE all the time)
92 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
93 # called by this object's functions
94 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
95 # the flag's value shouldn't be modified by anything other than
96 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
97 # $self->set_visibleFlag)
98 visibleFlag => TRUE,
99 # Flag set to TRUE is the strip object should be given its share of any extra space
100 # within the packing box (the extra space is divided equally between all children of
101 # the box whose ->expandFlag is TRUE)
102 expandFlag => FALSE,
103 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
104 # actually allocated within the strip object, FALSE if it is used as padding outside
105 # it (on both sides)
106 fillFlag => FALSE,
107 # Flag set to TRUE if the strip object should be packed into its window with a small
108 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
109 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
110 # for example in the toolbar strip object)
111 spacingFlag => TRUE,
112 # Flag set to TRUE if only one instance of this strip object should be added to the
113 # parent window, set to FALSE if any number of instances can be added
114 jealousyFlag => TRUE,
115 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
116 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
117 # users)
118 blindFlag => FALSE,
119 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
120 # allowed to accept the focus, FALSE if not. The restriction is applied during the
121 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
122 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
123 # GA::Strip::MenuBar)
124 allowFocusFlag => FALSE,
125  
126 # Initialisation settings stored as a hash (see the comments above)
127 initHash => \%modHash,
128 # Reference to a function to call when some widget is used. This IV is set only when
129 # required by this type of strip object. It can be set by a call to
130 # $self->set_func() or by some setting in $self->initHash, which is applied in the
131 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
132 # generic object function Games::Axmud->getMethodRef()
133 funcRef => undef,
134 # A value passed to ->funcRef when it is called which identifies this strip object and
135 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
136 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
137 # to $self->objEnable()
138 funcID => undef,
139  
140 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
141 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
142 packingBox => undef, # Gtk3::VBox
143  
144 # Other IVs
145 # ---------
146  
147 # Widgets
148 menuBar => undef, # Gtk3::MenuBar
149  
150 # Menu items which will be sensitised or desensitised, depending on the context. Hash
151 # in the form:
152 # $menuItemHash{'item_name'} = Gtk3_widget
153 # ...where:
154 # 'item_name' is a descriptive scalar, e.g. 'move_up_level'
155 # 'Gtk3_widget' is the Gtk3 menu item
156 menuItemHash => {},
157  
158 # The menu column for 'plugins', which can be extended by any loaded plugins
159 pluginMenu => undef, # Gtk3::Menu
160 # Hash of sub-menus in the 'plugins' menu column, one for each plugin that wants one, in
161 # the form
162 # $pluginHash{plugin_name} = menu_widget
163 pluginHash => {},
164 # Additional list of menu items added by plugins, which will be sensitised or
165 # desensitised, depending on the context. Hash in the form:
166 # $pluginMenuItemHash{'plugin_name'} = Gtk3_widget
167 pluginMenuItemHash => {},
168  
169 # Flag set to TRUE when the 'save all sessions' menu item is selected (desensitises
170 # some other menu items)
171 saveAllSessionsFlag => FALSE,
172 };
173  
174 # Bless the object into existence
175 bless $self, $class;
176  
177 return $self;
178 }
179  
180 ##################
181 # Methods
182  
183 # Standard strip object functions
184  
185 sub objEnable {
186  
187 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
188 # Sets up the strip object's widgets
189 #
190 # Expected arguments
191 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
192 # parent window
193 #
194 # Return values
195 # 'undef' on improper arguments
196 # 1 on success
197  
198 my ($self, $winmapObj, $check) = @_;
199  
200 # Check for improper arguments
201 if (! defined $winmapObj || defined $check) {
202  
203 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
204 }
205  
206 # Create a packing box
207 my $vBox = Gtk3::VBox->new(FALSE, 0);
208 $vBox->set_border_width(0);
209  
210 # Create a Gtk3::MenuBar
211 my $menuBar = Gtk3::MenuBar->new();
212 $vBox->pack_start($menuBar, TRUE, TRUE, 0);
213  
214 # 'World' column
215 my $menuColumn_world = $self->drawWorldColumn();
216 my $menuItem_world = Gtk3::MenuItem->new('_World');
217 $menuItem_world->set_submenu($menuColumn_world);
218 $menuBar->append($menuItem_world);
219  
220 # 'File' column
221 my $menuColumn_file = $self->drawFileColumn();
222 my $menuItem_file = Gtk3::MenuItem->new('_File');
223 $menuItem_file->set_submenu($menuColumn_file);
224 $menuBar->append($menuItem_file);
225  
226 # 'Edit' column
227 my $menuColumn_edit = $self->drawEditColumn();
228 my $menuItem_edit = Gtk3::MenuItem->new('_Edit');
229 $menuItem_edit->set_submenu($menuColumn_edit);
230 $menuBar->append($menuItem_edit);
231  
232 # 'Interfaces' column
233 my $menuColumn_interfaces = $self->drawInterfacesColumn();
234 my $menuItem_interfaces = Gtk3::MenuItem->new('_Interfaces');
235 $menuItem_interfaces->set_submenu($menuColumn_interfaces);
236 $menuBar->append($menuItem_interfaces);
237  
238 # 'Tasks' column
239 my $menuColumn_tasks = $self->drawTasksColumn();
240 my $menuItem_tasks = Gtk3::MenuItem->new('_Tasks');
241 $menuItem_tasks->set_submenu($menuColumn_tasks);
242 $menuBar->append($menuItem_tasks);
243  
244 # 'Display' column
245 my $menuColumn_display = $self->drawDisplayColumn();
246 my $menuItem_display = Gtk3::MenuItem->new('_Display');
247 $menuItem_display->set_submenu($menuColumn_display);
248 $menuBar->append($menuItem_display);
249  
250 # 'Commands' column
251 my $menuColumn_commands = $self->drawCommandsColumn();
252 my $menuItem_commands = Gtk3::MenuItem->new('_Commands');
253 $menuItem_commands->set_submenu($menuColumn_commands);
254 $menuBar->append($menuItem_commands);
255  
256 # 'Recordings' column
257 my $menuColumn_recordings = $self->drawRecordingsColumn();
258 my $menuItem_recordings = Gtk3::MenuItem->new('_Recordings');
259 $menuItem_recordings->set_submenu($menuColumn_recordings);
260 $menuBar->append($menuItem_recordings);
261  
262 # 'Axbasic' column
263 my $menuColumn_basic = $self->drawAxbasicColumn();
264 my $menuItem_basic = Gtk3::MenuItem->new('_' . $axmud::BASIC_NAME);
265 $menuItem_basic->set_submenu($menuColumn_basic);
266 $menuBar->append($menuItem_basic);
267  
268 # 'Plugins' column
269 my $menuColumn_plugins = $self->drawPluginsColumn();
270 my $menuItem_plugins = Gtk3::MenuItem->new('_Plugins');
271 $menuItem_plugins->set_submenu($menuColumn_plugins);
272 $menuBar->append($menuItem_plugins);
273  
274 # 'Help' column
275 my $menuColumn_help = $self->drawHelpColumn();
276 my $menuItem_help = Gtk3::MenuItem->new('_Help');
277 $menuItem_help->set_submenu($menuColumn_help);
278 $menuBar->append($menuItem_help);
279  
280 # Update IVs
281 $self->ivPoke('packingBox', $vBox);
282 $self->ivPoke('menuBar', $menuBar);
283 $self->ivPoke('pluginMenu', $menuColumn_plugins);
284  
285 # If any plugins have registered their desire to create sub-menus, call those plugins and
286 # create the sub-menus now
287 foreach my $pluginObj (sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivValues('pluginHash'))) {
288  
289 my ($funcRef, $subMenu);
290  
291 if (
292 $pluginObj->enabledFlag
293 && $axmud::CLIENT->ivExists('pluginMenuFuncHash', $pluginObj->name)
294 ) {
295 $funcRef = $axmud::CLIENT->ivShow('pluginMenuFuncHash', $pluginObj->name);
296 $subMenu = $self->addPluginWidgets($pluginObj->name);
297  
298 if ($funcRef && $subMenu) {
299  
300 &$funcRef($self, $subMenu);
301 }
302 }
303 }
304  
305 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
306 $axmud::CLIENT->desktopObj->restrictWidgets();
307  
308 return 1;
309 }
310  
311 sub objDestroy {
312  
313 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
314 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
315 # to do any necessary tidying up
316 #
317 # Expected arguments
318 # (none besides $self)
319 #
320 # Return values
321 # 'undef' on improper arguments
322 # 1 otherwise
323  
324 my ($self, $check) = @_;
325  
326 # Check for improper arguments
327 if (defined $check) {
328  
329 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
330 }
331  
332 # (No tidying up required for this type of strip object)
333 # ...
334  
335 return 1;
336 }
337  
338 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Strip
339  
340 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Strip
341  
342 # ->signal_connects are stored in $self->drawWorldColumn, etc
343  
344 # Other functions
345  
346 sub drawWorldColumn {
347  
348 # Called by $self->enableMenu
349 # Sets up the menu's 'World' column
350 #
351 # Expected arguments
352 # (none besides $self)
353 #
354 # Return values
355 # 'undef' on improper arguments, or if the menu can't be created
356 # Otherwise returns the Gtk3::Menu created
357  
358 my ($self, $check) = @_;
359  
360 # Local variables
361 my ($mode, $choice);
362  
363 # Check for improper arguments
364 if (defined $check) {
365  
366 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWorldColumn', @_);
367 }
368  
369 # Import IVs (for convenience)
370 $mode = $self->winObj->pseudoCmdMode;
371  
372 # Set up column
373 my $menuColumn_world = Gtk3::Menu->new();
374 if (! $menuColumn_world) {
375  
376 return undef;
377 }
378  
379 my $menuItem_connect = Gtk3::ImageMenuItem->new('_Connect...');
380 my $menuImg_connect = Gtk3::Image->new_from_stock('gtk-connect', 'menu');
381 $menuItem_connect->set_image($menuImg_connect);
382 $menuItem_connect->signal_connect('activate' => sub {
383  
384 my $winObj;
385  
386 if ($self->winObj->visibleSession) {
387  
388 $self->winObj->visibleSession->pseudoCmd('connect', $mode);
389  
390 } else {
391  
392 # Can't use ';connect' because the parent window has no visible session
393  
394 # Check that the Connections window isn't already open
395 if ($axmud::CLIENT->connectWin) {
396  
397 # Window already open; draw attention to the fact by 'present'ing it
398 $axmud::CLIENT->connectWin->restoreFocus();
399  
400 } else {
401  
402 # Open the Connections window
403 $winObj = $self->winObj->quickFreeWin(
404 'Games::Axmud::OtherWin::Connect',
405 $self->winObj->visibleSession,
406 );
407  
408 if ($winObj) {
409  
410 # Only one Connections window can be open at a time
411 $axmud::CLIENT->set_connectWin($winObj);
412 }
413 }
414 }
415 });
416 $menuColumn_world->append($menuItem_connect);
417 # (Desensitised only when the setup wizwin is open)
418 $self->ivAdd('menuItemHash', 'connect', $menuItem_connect);
419  
420 my $menuItem_reconnect = Gtk3::ImageMenuItem->new('_Reconnect');
421 my $menuImg_reconnect = Gtk3::Image->new_from_stock('gtk-connect', 'menu');
422 $menuItem_reconnect->set_image($menuImg_reconnect);
423 $menuItem_reconnect->signal_connect('activate' => sub {
424  
425 $self->winObj->visibleSession->pseudoCmd('reconnect', $mode);
426 });
427 $menuColumn_world->append($menuItem_reconnect);
428 # (Requires a visible session)
429 $self->ivAdd('menuItemHash', 'reconnect', $menuItem_reconnect);
430  
431 my $menuItem_reconnectOffline = Gtk3::MenuItem->new('Reconnect _offline');
432 $menuItem_reconnectOffline->signal_connect('activate' => sub {
433  
434 $self->winObj->visibleSession->pseudoCmd('reconnect -o', $mode);
435 });
436 $menuColumn_world->append($menuItem_reconnectOffline);
437 # (Requires a visible session)
438 $self->ivAdd('menuItemHash', 'reconnect_offline', $menuItem_reconnectOffline);
439  
440 my $menuItem_xConnect = Gtk3::MenuItem->new('Reconnect (_no save)');
441 $menuItem_xConnect->signal_connect('activate' => sub {
442  
443 $self->winObj->visibleSession->pseudoCmd('xconnect', $mode);
444 });
445 $menuColumn_world->append($menuItem_xConnect);
446 # (Requires a visible session)
447 $self->ivAdd('menuItemHash', 'xconnect', $menuItem_xConnect);
448  
449 my $menuItem_xConnectOffline = Gtk3::MenuItem->new('Reconnect offline (no _save)');
450 $menuItem_xConnectOffline->signal_connect('activate' => sub {
451  
452 $self->winObj->visibleSession->pseudoCmd('xconnect -o', $mode);
453 });
454 $menuColumn_world->append($menuItem_xConnectOffline);
455 # (Requires a visible session)
456 $self->ivAdd('menuItemHash', 'xconnect_offline', $menuItem_xConnectOffline);
457  
458 $menuColumn_world->append(Gtk3::SeparatorMenuItem->new()); # Separator
459  
460 my $menuItem_login = Gtk3::ImageMenuItem->new('Character _login');
461 my $menuImg_login = Gtk3::Image->new_from_stock('gtk-network', 'menu');
462 $menuItem_login->set_image($menuImg_login);
463 $menuItem_login->signal_connect('activate' => sub {
464  
465 $self->winObj->visibleSession->pseudoCmd('login', $mode);
466 });
467 $menuColumn_world->append($menuItem_login);
468 # (Requires a visible session whose status is 'connected' or 'offline')
469 $self->ivAdd('menuItemHash', 'login', $menuItem_login);
470  
471 $menuColumn_world->append(Gtk3::SeparatorMenuItem->new()); # Separator
472  
473 my $menuItem_quit = Gtk3::ImageMenuItem->new('Send _quit');
474 my $menuImg_quit = Gtk3::Image->new_from_stock('gtk-disconnect', 'menu');
475 $menuItem_quit->set_image($menuImg_quit);
476 $menuItem_quit->signal_connect('activate' => sub {
477  
478 if (
479 $self->promptUser(
480 'Confirm quit',
481 'Are you sure you want to send the \'quit\' command?',
482 )
483 ) {
484 $self->winObj->visibleSession->pseudoCmd('quit', $mode);
485 }
486 });
487 $menuColumn_world->append($menuItem_quit);
488 # (Requires a visible session whose status is 'connected' or 'offline')
489 $self->ivAdd('menuItemHash', 'quit', $menuItem_quit);
490  
491 my $menuItem_qquit = Gtk3::MenuItem->new('Send quit (no sa_ve)');
492 $menuItem_qquit->signal_connect('activate' => sub {
493  
494 if (
495 $self->promptUser(
496 'Confirm quit',
497 'Are you sure you want to send the \'quit\' command without saving?',
498 )
499 ) {
500 $self->winObj->visibleSession->pseudoCmd('qquit', $mode);
501 }
502 });
503 $menuColumn_world->append($menuItem_qquit);
504 # (Requires a visible session whose status is 'connected' or 'offline')
505 $self->ivAdd('menuItemHash', 'qquit', $menuItem_qquit);
506  
507 my $menuItem_quitAll = Gtk3::MenuItem->new('Send quit (_all sessions)');
508 $menuItem_quitAll->signal_connect('activate' => sub {
509  
510 if (
511 $self->promptUser(
512 'Confirm quit',
513 'Are you sure you want to send the \'quit\' command in all sessions?',
514 )
515 ) {
516 $self->winObj->visibleSession->pseudoCmd('quitall', $mode);
517 }
518 });
519 $menuColumn_world->append($menuItem_quitAll);
520 # (Requires a visible session)
521 $self->ivAdd('menuItemHash', 'quit_all', $menuItem_quitAll);
522  
523 $menuColumn_world->append(Gtk3::SeparatorMenuItem->new()); # Separator
524  
525 my $menuItem_exit = Gtk3::ImageMenuItem->new('_Exit session');
526 my $menuImg_exit = Gtk3::Image->new_from_stock('gtk-disconnect', 'menu');
527 $menuItem_exit->set_image($menuImg_exit);
528 $menuItem_exit->signal_connect('activate' => sub {
529  
530 if (
531 $self->promptUser(
532 'Confirm exit',
533 'Are you sure you want to exit this session?',
534 )
535 ) {
536 $self->winObj->visibleSession->pseudoCmd('exit', $mode);
537 }
538 });
539 $menuColumn_world->append($menuItem_exit);
540 # (Requires a visible session whose status is 'connected' or 'offline')
541 $self->ivAdd('menuItemHash', 'exit', $menuItem_exit);
542  
543 my $menuItem_xxit = Gtk3::MenuItem->new('E_xit session (no save)');
544 $menuItem_xxit->signal_connect('activate' => sub {
545  
546 if (
547 $self->promptUser(
548 'Confirm exit',
549 'Are you sure you want to exit this session without saving?',
550 )
551 ) {
552 $self->winObj->visibleSession->pseudoCmd('xxit', $mode);
553 }
554 });
555 $menuColumn_world->append($menuItem_xxit);
556 # (Requires a visible session whose status is 'connected' or 'offline')
557 $self->ivAdd('menuItemHash', 'xxit', $menuItem_xxit);
558  
559 my $menuItem_exitAll = Gtk3::MenuItem->new('Ex_it all sessions');
560 $menuItem_exitAll->signal_connect('activate' => sub {
561  
562 if (
563 $self->promptUser(
564 'Confirm exit',
565 'Are you sure you want to exit every session?',
566 )
567 ) {
568 $self->winObj->visibleSession->pseudoCmd('exitall', $mode);
569 }
570 });
571 $menuColumn_world->append($menuItem_exitAll);
572 # (Requires a visible session)
573 $self->ivAdd('menuItemHash', 'exit_all', $menuItem_exitAll);
574  
575 $menuColumn_world->append(Gtk3::SeparatorMenuItem->new()); # Separator
576  
577 my $menuItem_stopSession = Gtk3::ImageMenuItem->new('S_top session');
578 my $menuImg_stopSession = Gtk3::Image->new_from_stock('gtk-close', 'menu');
579 $menuItem_stopSession->set_image($menuImg_stopSession);
580 $menuItem_stopSession->signal_connect('activate' => sub {
581  
582 if (
583 $self->winObj->visibleSession->status eq 'connected'
584 && $axmud::CLIENT->confirmCloseMenuFlag
585 ) {
586 $choice = $self->winObj->showMsgDialogue(
587 'Stop session',
588 'question',
589 'This session is connected to a world. Are you sure you want to stop it?',
590 'yes-no',
591 );
592  
593 if ($choice eq 'yes') {
594  
595 $self->winObj->visibleSession->pseudoCmd('stopsession', $mode);
596 }
597  
598 } else {
599  
600 $self->winObj->visibleSession->pseudoCmd('stopsession', $mode);
601 }
602 });
603 $menuColumn_world->append($menuItem_stopSession);
604 # (Requires a visible session)
605 $self->ivAdd('menuItemHash', 'stop_session', $menuItem_stopSession);
606  
607 my $menuItem_stopClient = Gtk3::ImageMenuItem->new('Sto_p client');
608 my $menuImg_stopClient = Gtk3::Image->new_from_stock('gtk-quit', 'menu');
609 $menuItem_stopClient->set_image($menuImg_stopClient);
610 $menuItem_stopClient->signal_connect('activate' => sub {
611  
612 # If there are any connected sessions or unsaved files, prompt the user before executing
613 # the client command; otherwise go ahead and do the ';stopclient' operation
614 if (
615 $axmud::CLIENT->checkSessions()
616 || $self->promptUser(
617 'Confirm stop client',
618 'Are you sure you want to close the ' . $axmud::SCRIPT . ' client?',
619 )
620 ) {
621 if ($self->winObj->visibleSession) {
622  
623 $self->winObj->visibleSession->pseudoCmd('stopclient', $mode);
624  
625 } else {
626  
627 # Can't use ';stopclient' because there is no current session
628 $axmud::CLIENT->stop();
629 }
630 }
631 });
632 $menuColumn_world->append($menuItem_stopClient);
633 # (Desensitised only when the setup wizwin is open)
634 $self->ivAdd('menuItemHash', 'stop_client', $menuItem_stopClient);
635  
636 # Setup complete
637 return $menuColumn_world;
638 }
639  
640 sub drawFileColumn {
641  
642 # Called by $self->enableMenu
643 # Sets up the menu's 'File' column
644 #
645 # Expected arguments
646 # (none besides $self)
647 #
648 # Return values
649 # 'undef' on improper arguments, or if the menu can't be created
650 # Otherwise returns the Gtk3::Menu created
651  
652 my ($self, $check) = @_;
653  
654 # Local variables
655 my ($mode, $forceSwitch, $allSessionSwitch);
656  
657 # Check for improper arguments
658 if (defined $check) {
659  
660 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawFileColumn', @_);
661 }
662  
663 # Import IVs (for convenience)
664 $mode = $self->winObj->pseudoCmdMode;
665  
666 # A pair of radio buttons toggle the value of this string between '' and ' -f', used with
667 # the ';save' command
668 $forceSwitch = '';
669 # Another pair of buttons toggle the value of this string between '' and ' -a', used with
670 # the ';save' command
671 $allSessionSwitch = '';
672  
673 # Set up column
674 my $menuColumn_file = Gtk3::Menu->new();
675 if (! $menuColumn_file) {
676  
677 return undef;
678 }
679  
680 my $menuItem_loadAll = Gtk3::ImageMenuItem->new('_Load all');
681 my $menuImg_loadAll = Gtk3::Image->new_from_stock('gtk-open', 'menu');
682 $menuItem_loadAll->set_image($menuImg_loadAll);
683 $menuItem_loadAll->signal_connect('activate' => sub {
684  
685 $self->winObj->visibleSession->pseudoCmd('load', $mode);
686 });
687 $menuColumn_file->append($menuItem_loadAll);
688 # (Requires a visible session whose status is 'connected' or 'offline')
689 $self->ivAdd('menuItemHash', 'load_all', $menuItem_loadAll);
690  
691 # 'Load files' submenu
692 my $subMenu_loadFile = Gtk3::Menu->new();
693  
694 my $menuItem_loadFile_worldModel = Gtk3::MenuItem->new('_World model file');
695 $menuItem_loadFile_worldModel->signal_connect('activate' => sub {
696  
697 $self->winObj->visibleSession->pseudoCmd('load -m', $mode);
698 });
699 $subMenu_loadFile->append($menuItem_loadFile_worldModel);
700  
701 my $menuItem_loadFile_tasks = Gtk3::MenuItem->new('_Tasks file');
702 $menuItem_loadFile_tasks->signal_connect('activate' => sub {
703  
704 $self->winObj->visibleSession->pseudoCmd('load -t', $mode);
705 });
706 $subMenu_loadFile->append($menuItem_loadFile_tasks);
707  
708 my $menuItem_loadFile_scripts = Gtk3::MenuItem->new('_Scripts file');
709 $menuItem_loadFile_scripts->signal_connect('activate' => sub {
710  
711 $self->winObj->visibleSession->pseudoCmd('load -s', $mode);
712 });
713 $subMenu_loadFile->append($menuItem_loadFile_scripts);
714  
715 my $menuItem_loadFile_contacts = Gtk3::MenuItem->new('_Contacts file');
716 $menuItem_loadFile_contacts->signal_connect('activate' => sub {
717  
718 $self->winObj->visibleSession->pseudoCmd('load -n', $mode);
719 });
720 $subMenu_loadFile->append($menuItem_loadFile_contacts);
721  
722 my $menuItem_loadFile_dicts = Gtk3::MenuItem->new('_Dictionaries file');
723 $menuItem_loadFile_dicts->signal_connect('activate' => sub {
724  
725 $self->winObj->visibleSession->pseudoCmd('load -y', $mode);
726 });
727 $subMenu_loadFile->append($menuItem_loadFile_dicts);
728  
729 my $menuItem_loadFile_toolbar = Gtk3::MenuItem->new('Tool_bar file');
730 $menuItem_loadFile_toolbar->signal_connect('activate' => sub {
731  
732 $self->winObj->visibleSession->pseudoCmd('load -b', $mode);
733 });
734 $subMenu_loadFile->append($menuItem_loadFile_toolbar);
735  
736 my $menuItem_loadFile_userComm = Gtk3::MenuItem->new('_User commands file');
737 $menuItem_loadFile_userComm->signal_connect('activate' => sub {
738  
739 $self->winObj->visibleSession->pseudoCmd('load -u', $mode);
740 });
741 $subMenu_loadFile->append($menuItem_loadFile_userComm);
742  
743 my $menuItem_loadFile_zonemaps = Gtk3::MenuItem->new('_Zonemaps file');
744 $menuItem_loadFile_zonemaps->signal_connect('activate' => sub {
745  
746 $self->winObj->visibleSession->pseudoCmd('load -z', $mode);
747 });
748 $subMenu_loadFile->append($menuItem_loadFile_zonemaps);
749  
750 my $menuItem_loadFile_winmaps = Gtk3::MenuItem->new('Win_maps file');
751 $menuItem_loadFile_winmaps->signal_connect('activate' => sub {
752  
753 $self->winObj->visibleSession->pseudoCmd('load -p', $mode);
754 });
755 $subMenu_loadFile->append($menuItem_loadFile_winmaps);
756  
757 my $menuItem_loadFile_ttsObjs = Gtk3::MenuItem->new('T_ext-to-speech file');
758 $menuItem_loadFile_ttsObjs->signal_connect('activate' => sub {
759  
760 $self->winObj->visibleSession->pseudoCmd('load -x', $mode);
761 });
762 $subMenu_loadFile->append($menuItem_loadFile_ttsObjs);
763  
764 my $menuItem_loadFile = Gtk3::MenuItem->new('L_oad files');
765 $menuItem_loadFile->set_submenu($subMenu_loadFile);
766 $menuColumn_file->append($menuItem_loadFile);
767 # (Requires a visible session whose status is 'connected' or 'offline')
768 $self->ivAdd('menuItemHash', 'load_file', $menuItem_loadFile);
769  
770 $menuColumn_file->append(Gtk3::SeparatorMenuItem->new()); # Separator
771  
772 my $menuItem_saveAll = Gtk3::ImageMenuItem->new('_Save all');
773 my $menuImg_saveAll = Gtk3::Image->new_from_stock('gtk-save', 'menu');
774 $menuItem_saveAll->set_image($menuImg_saveAll);
775 $menuItem_saveAll->signal_connect('activate' => sub {
776  
777 $self->winObj->visibleSession->pseudoCmd(
778 'save ' . $forceSwitch . $allSessionSwitch,
779 $mode,
780 );
781 });
782 $menuColumn_file->append($menuItem_saveAll);
783 # (Requires a visible session whose status is 'connected' or 'offline')
784 $self->ivAdd('menuItemHash', 'save_all', $menuItem_saveAll);
785  
786 # 'Save files' submenu
787 my $subMenu_saveFile = Gtk3::Menu->new();
788  
789 my $menuItem_saveFile_config = Gtk3::MenuItem->new('_Config file');
790 $menuItem_saveFile_config->signal_connect('activate' => sub {
791  
792 $self->winObj->visibleSession->pseudoCmd('save -i' . $forceSwitch, $mode);
793 });
794 $subMenu_saveFile->append($menuItem_saveFile_config);
795  
796 $subMenu_saveFile->append(Gtk3::SeparatorMenuItem->new()); # Separator
797  
798 my $menuItem_saveFile_prof = Gtk3::MenuItem->new('_Profile files');
799 $menuItem_saveFile_prof->signal_connect('activate' => sub {
800  
801 $self->winObj->visibleSession->pseudoCmd('save -d' . $forceSwitch, $mode);
802 });
803 $subMenu_saveFile->append($menuItem_saveFile_prof);
804  
805 my $menuItem_saveFile_currentProf = Gtk3::MenuItem->new('C_urrent profile files');
806 $menuItem_saveFile_currentProf->signal_connect('activate' => sub {
807  
808 $self->winObj->visibleSession->pseudoCmd('save -c' . $forceSwitch, $mode);
809 });
810 $subMenu_saveFile->append($menuItem_saveFile_currentProf);
811  
812 my $menuItem_saveFile_worldProf = Gtk3::MenuItem->new('_World definition...');
813 $menuItem_saveFile_worldProf->signal_connect('activate' => sub {
814  
815 # Display a 'dialogue' window, so the user can choose a world profile
816 my (
817 $choice,
818 @worldList,
819 );
820  
821 # Get an ordered list of all world profiles
822 @worldList = $self->getWorldList();
823 if (@worldList) {
824  
825 # Display the dialogue
826 $choice = $self->winObj->showComboDialogue(
827 'Save file',
828 'Select a world profile to save',
829 \@worldList,
830 );
831  
832 if ($choice) {
833  
834 # Save the file
835 $self->winObj->visibleSession->pseudoCmd(
836 'save -o ' . $choice . $forceSwitch,
837 $mode,
838 );
839 }
840 }
841 });
842 $subMenu_saveFile->append($menuItem_saveFile_worldProf);
843  
844 my $menuItem_saveFile_currentWorld = Gtk3::MenuItem->new('Cu_rrent world files');
845 $menuItem_saveFile_currentWorld->signal_connect('activate' => sub {
846  
847 $self->winObj->visibleSession->pseudoCmd('save -w' . $forceSwitch, $mode);
848 });
849 $subMenu_saveFile->append($menuItem_saveFile_currentWorld);
850  
851 $subMenu_saveFile->append(Gtk3::SeparatorMenuItem->new()); # Separator
852  
853 my $menuItem_saveFile_worldModel = Gtk3::MenuItem->new('World _model file');
854 $menuItem_saveFile_worldModel->signal_connect('activate' => sub {
855  
856 $self->winObj->visibleSession->pseudoCmd('save -m' . $forceSwitch, $mode);
857 });
858 $subMenu_saveFile->append($menuItem_saveFile_worldModel);
859  
860 my $menuItem_saveFile_tasks = Gtk3::MenuItem->new('_Tasks file');
861 $menuItem_saveFile_tasks->signal_connect('activate' => sub {
862  
863 $self->winObj->visibleSession->pseudoCmd('save -t' . $forceSwitch, $mode);
864 });
865 $subMenu_saveFile->append($menuItem_saveFile_tasks);
866  
867 my $menuItem_saveFile_scripts = Gtk3::MenuItem->new('_Scripts file');
868 $menuItem_saveFile_scripts->signal_connect('activate' => sub {
869  
870 $self->winObj->visibleSession->pseudoCmd('save -s' . $forceSwitch, $mode);
871 });
872 $subMenu_saveFile->append($menuItem_saveFile_scripts);
873  
874 my $menuItem_saveFile_contacts = Gtk3::MenuItem->new('C_ontacts file');
875 $menuItem_saveFile_contacts->signal_connect('activate' => sub {
876  
877 $self->winObj->visibleSession->pseudoCmd('save -n' . $forceSwitch, $mode);
878 });
879 $subMenu_saveFile->append($menuItem_saveFile_contacts);
880  
881 my $menuItem_saveFile_dicts = Gtk3::MenuItem->new('_Dictionaries file');
882 $menuItem_saveFile_dicts->signal_connect('activate' => sub {
883  
884 $self->winObj->visibleSession->pseudoCmd('save -y' . $forceSwitch, $mode);
885 });
886 $subMenu_saveFile->append($menuItem_saveFile_dicts);
887  
888 my $menuItem_saveFile_toolbar = Gtk3::MenuItem->new('Tool_bar file');
889 $menuItem_saveFile_toolbar->signal_connect('activate' => sub {
890  
891 $self->winObj->visibleSession->pseudoCmd('save -b' . $forceSwitch, $mode);
892 });
893 $subMenu_saveFile->append($menuItem_saveFile_toolbar);
894  
895 my $menuItem_saveFile_userComm = Gtk3::MenuItem->new('Us_er commands file');
896 $menuItem_saveFile_userComm->signal_connect('activate' => sub {
897  
898 $self->winObj->visibleSession->pseudoCmd('save -u' . $forceSwitch, $mode);
899 });
900 $subMenu_saveFile->append($menuItem_saveFile_userComm);
901  
902 my $menuItem_saveFile_zonemaps = Gtk3::MenuItem->new('_Zonemaps file');
903 $menuItem_saveFile_zonemaps->signal_connect('activate' => sub {
904  
905 $self->winObj->visibleSession->pseudoCmd('save -z' . $forceSwitch, $mode);
906 });
907 $subMenu_saveFile->append($menuItem_saveFile_zonemaps);
908  
909 my $menuItem_saveFile_winmaps = Gtk3::MenuItem->new('W_inmaps file');
910 $menuItem_saveFile_winmaps->signal_connect('activate' => sub {
911  
912 $self->winObj->visibleSession->pseudoCmd('save -p' . $forceSwitch, $mode);
913 });
914 $subMenu_saveFile->append($menuItem_saveFile_winmaps);
915  
916 my $menuItem_saveFile_ttsObjs = Gtk3::MenuItem->new('Te_xt-to-speech file');
917 $menuItem_saveFile_ttsObjs->signal_connect('activate' => sub {
918  
919 $self->winObj->visibleSession->pseudoCmd('save -x' . $forceSwitch, $mode);
920 });
921 $subMenu_saveFile->append($menuItem_saveFile_ttsObjs);
922  
923 my $menuItem_saveFile = Gtk3::MenuItem->new('S_ave files');
924 $menuItem_saveFile->set_submenu($subMenu_saveFile);
925 $menuColumn_file->append($menuItem_saveFile);
926 # (Requires a visible session whose status is 'connected' or 'offline' and
927 # $self->saveAllSessionsFlag set to FALSE)
928 $self->ivAdd('menuItemHash', 'save_file', $menuItem_saveFile);
929  
930 # 'Save options' submenu
931 my $subMenu_saveOptions = Gtk3::Menu->new();
932  
933 my $menuColumn_forced_radio1 = Gtk3::RadioMenuItem->new_with_mnemonic(
934 undef,
935 'Forced saves o_ff',
936 );
937 $menuColumn_forced_radio1->signal_connect('toggled' => sub {
938  
939 if ($menuColumn_forced_radio1->get_active()) {
940 $forceSwitch = '';
941 } else {
942 $forceSwitch = ' -f';
943 }
944 });
945 $subMenu_saveOptions->append($menuColumn_forced_radio1);
946  
947 my $menuColumn_forced_radio2 = Gtk3::RadioMenuItem->new_with_mnemonic(
948 $menuColumn_forced_radio1->get_group(),
949 'Forced saves o_n',
950 );
951 $subMenu_saveOptions->append($menuColumn_forced_radio2);
952  
953 $subMenu_saveOptions->append(Gtk3::SeparatorMenuItem->new()); # Separator
954  
955 my $menuColumn_allSession_radio1 = Gtk3::RadioMenuItem->new_with_mnemonic(
956 undef,
957 'Save in _this session',
958 );
959 $menuColumn_allSession_radio1->signal_connect('toggled' => sub {
960  
961 if ($menuColumn_allSession_radio1->get_active()) {
962  
963 $allSessionSwitch = '';
964 $self->ivPoke('saveAllSessionsFlag', FALSE);
965  
966 } else {
967  
968 $allSessionSwitch = ' -a';
969 $self->ivPoke('saveAllSessionsFlag', TRUE);
970 }
971  
972 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
973 $axmud::CLIENT->desktopObj->restrictWidgets();
974 });
975 $subMenu_saveOptions->append($menuColumn_allSession_radio1);
976  
977 my $menuColumn_allSession_radio2 = Gtk3::RadioMenuItem->new_with_mnemonic(
978 $menuColumn_allSession_radio1->get_group(),
979 'Save in _all sessions',
980 );
981 $subMenu_saveOptions->append($menuColumn_allSession_radio2);
982  
983 $subMenu_saveOptions->append(Gtk3::SeparatorMenuItem->new()); # Separator
984  
985 my $menuItem_autoSaves_off = Gtk3::MenuItem->new('T_urn auto-saves off');
986 $menuItem_autoSaves_off->signal_connect('activate' => sub {
987  
988 $self->winObj->visibleSession->pseudoCmd('autosave off', $mode);
989 });
990 $subMenu_saveOptions->append($menuItem_autoSaves_off);
991  
992 my $menuItem_autoSaves_on = Gtk3::MenuItem->new('Tu_rn auto-saves on');
993 $menuItem_autoSaves_on->signal_connect('activate' => sub {
994  
995 $self->winObj->visibleSession->pseudoCmd('autosave on', $mode);
996 });
997 $subMenu_saveOptions->append($menuItem_autoSaves_on);
998  
999 $subMenu_saveOptions->append(Gtk3::SeparatorMenuItem->new()); # Separator
1000  
1001 my $menuItem_autoSaves_setTime = Gtk3::MenuItem->new('_Set auto-save time...');
1002 $menuItem_autoSaves_setTime->signal_connect('activate' => sub {
1003  
1004 my $number = $self->winObj->showEntryDialogue(
1005 'Set auto-save time',
1006 'Enter a time in seconds',
1007 );
1008  
1009 if ($number) {
1010  
1011 # Set the auto-save time
1012 $self->winObj->visibleSession->pseudoCmd('autosave ' . $number, $mode);
1013 }
1014 });
1015 $subMenu_saveOptions->append($menuItem_autoSaves_setTime);
1016  
1017 my $menuItem_saveOptions = Gtk3::MenuItem->new('Sa_ve options');
1018 $menuItem_saveOptions->set_submenu($subMenu_saveOptions);
1019 $menuColumn_file->append($menuItem_saveOptions);
1020 # (Requires a visible session whose status is 'connected' or 'offline')
1021 $self->ivAdd('menuItemHash', 'save_options', $menuItem_saveOptions);
1022  
1023 $menuColumn_file->append(Gtk3::SeparatorMenuItem->new()); # Separator
1024  
1025 my $menuItem_importFile = Gtk3::MenuItem->new('I_mport files...');
1026 $menuItem_importFile->signal_connect('activate' => sub {
1027  
1028 $self->winObj->visibleSession->pseudoCmd('importfiles', $mode);
1029 });
1030 $menuColumn_file->append($menuItem_importFile);
1031 # (Requires a visible session whose status is 'connected' or 'offline')
1032 $self->ivAdd('menuItemHash', 'import_files', $menuItem_importFile);
1033  
1034 # my $menuItem_exportAllFile = Gtk3::MenuItem->new('_Export all files...');
1035 # $menuItem_exportAllFile->signal_connect('activate' => sub {
1036 #
1037 # $self->winObj->visibleSession->pseudoCmd('exportfiles', $mode);
1038 # });
1039 # $menuColumn_file->append($menuItem_exportAllFile);
1040 # # (Requires a visible session whose status is 'connected' or 'offline')
1041 # $self->ivAdd('menuItemHash', 'export_all_files', $menuItem_exportAllFile);
1042  
1043 # 'Export files' submenu
1044 my $subMenu_exportFile = Gtk3::Menu->new();
1045  
1046 my $menuItem_exportFile_world = Gtk3::MenuItem->new('_World files...');
1047 $menuItem_exportFile_world->signal_connect('activate' => sub {
1048  
1049 # Display a 'dialogue' window, so the user can choose a world profile
1050 my (
1051 $choice,
1052 @worldList,
1053 );
1054  
1055 # Get an ordered list of all world profiles
1056 @worldList = $self->getWorldList();
1057 if (@worldList) {
1058  
1059 # Display the dialogue
1060 $choice = $self->winObj->showComboDialogue(
1061 'Export file',
1062 'Select a world profile to export',
1063 \@worldList,
1064 );
1065  
1066 if ($choice) {
1067  
1068 # Export the file
1069 $self->winObj->visibleSession->pseudoCmd(
1070 'exportfiles -w ' . $choice,
1071 $mode,
1072 );
1073 }
1074 }
1075 });
1076 $subMenu_exportFile->append($menuItem_exportFile_world);
1077  
1078 $subMenu_exportFile->append(Gtk3::SeparatorMenuItem->new()); # Separator
1079  
1080 my $menuItem_exportFile_model = Gtk3::MenuItem->new('World _model file...');
1081 $menuItem_exportFile_model->signal_connect('activate' => sub {
1082  
1083 # Display a 'dialogue' window, so the user can choose a world profile
1084 my (
1085 $choice,
1086 @worldList,
1087 );
1088  
1089 # Get an ordered list of all world profiles
1090 @worldList = $self->getWorldList();
1091 if (@worldList) {
1092  
1093 # Display the dialogue
1094 $choice = $self->winObj->showComboDialogue(
1095 'Export file',
1096 'Select a world model to export',
1097 \@worldList,
1098 );
1099  
1100 if ($choice) {
1101  
1102 # Export the file
1103 $self->winObj->visibleSession->pseudoCmd(
1104 'exportfiles -m ' . $choice,
1105 $mode,
1106 );
1107 }
1108 }
1109 });
1110 $subMenu_exportFile->append($menuItem_exportFile_model);
1111  
1112 my $menuItem_exportFile_tasks = Gtk3::MenuItem->new('_Tasks file');
1113 $menuItem_exportFile_tasks->signal_connect('activate' => sub {
1114  
1115 $self->winObj->visibleSession->pseudoCmd('exportfiles -t', $mode);
1116 });
1117 $subMenu_exportFile->append($menuItem_exportFile_tasks);
1118  
1119 my $menuItem_exportFile_scripts = Gtk3::MenuItem->new('_Scripts file');
1120 $menuItem_exportFile_scripts->signal_connect('activate' => sub {
1121  
1122 $self->winObj->visibleSession->pseudoCmd('exportfiles -s', $mode);
1123 });
1124 $subMenu_exportFile->append($menuItem_exportFile_scripts);
1125  
1126 my $menuItem_exportFile_contacts = Gtk3::MenuItem->new('_Contacts file');
1127 $menuItem_exportFile_contacts->signal_connect('activate' => sub {
1128  
1129 $self->winObj->visibleSession->pseudoCmd('exportfiles -n', $mode);
1130 });
1131 $subMenu_exportFile->append($menuItem_exportFile_contacts);
1132  
1133 my $menuItem_exportFile_dicts = Gtk3::MenuItem->new('_Dictionaries file');
1134 $menuItem_exportFile_dicts->signal_connect('activate' => sub {
1135  
1136 $self->winObj->visibleSession->pseudoCmd('exportfiles -y', $mode);
1137 });
1138 $subMenu_exportFile->append($menuItem_exportFile_dicts);
1139  
1140 my $menuItem_exportFile_toolbar = Gtk3::MenuItem->new('Tool_bar file');
1141 $menuItem_exportFile_toolbar->signal_connect('activate' => sub {
1142  
1143 $self->winObj->visibleSession->pseudoCmd('exportfiles -b', $mode);
1144 });
1145 $subMenu_exportFile->append($menuItem_exportFile_toolbar);
1146  
1147 my $menuItem_exportFile_userComm = Gtk3::MenuItem->new('_User commands file');
1148 $menuItem_exportFile_userComm->signal_connect('activate' => sub {
1149  
1150 $self->winObj->visibleSession->pseudoCmd('exportfiles -u', $mode);
1151 });
1152 $subMenu_exportFile->append($menuItem_exportFile_userComm);
1153  
1154 my $menuItem_exportFile_zonemaps = Gtk3::MenuItem->new('_Zonemaps file');
1155 $menuItem_exportFile_zonemaps->signal_connect('activate' => sub {
1156  
1157 $self->winObj->visibleSession->pseudoCmd('exportfiles -z', $mode);
1158 });
1159 $subMenu_exportFile->append($menuItem_exportFile_zonemaps);
1160  
1161 my $menuItem_exportFile_winmaps = Gtk3::MenuItem->new('W_inmaps file');
1162 $menuItem_exportFile_winmaps->signal_connect('activate' => sub {
1163  
1164 $self->winObj->visibleSession->pseudoCmd('exportfiles -p', $mode);
1165 });
1166 $subMenu_exportFile->append($menuItem_exportFile_winmaps);
1167  
1168 my $menuItem_exportFile_ttsObjs = Gtk3::MenuItem->new('Te_xt-to-speech file');
1169 $menuItem_exportFile_ttsObjs->signal_connect('activate' => sub {
1170  
1171 $self->winObj->visibleSession->pseudoCmd('exportfiles -x', $mode);
1172 });
1173 $subMenu_exportFile->append($menuItem_exportFile_ttsObjs);
1174  
1175 my $menuItem_exportFile = Gtk3::MenuItem->new('E_xport files');
1176 $menuItem_exportFile->set_submenu($subMenu_exportFile);
1177 $menuColumn_file->append($menuItem_exportFile);
1178 # (Requires a visible session whose status is 'connected' or 'offline')
1179 $self->ivAdd('menuItemHash', 'export_file', $menuItem_exportFile);
1180  
1181 $menuColumn_file->append(Gtk3::SeparatorMenuItem->new()); # Separator
1182  
1183 my $menuItem_importData = Gtk3::MenuItem->new('_Import data...');
1184 $menuItem_importData->signal_connect('activate' => sub {
1185  
1186 $self->winObj->visibleSession->pseudoCmd('importdata', $mode);
1187 });
1188 $menuColumn_file->append($menuItem_importData);
1189 # (Requires a visible session whose status is 'connected' or 'offline')
1190 $self->ivAdd('menuItemHash', 'import_data', $menuItem_importData);
1191  
1192 # 'Export data' submenu
1193 my $subMenu_exportData = Gtk3::Menu->new();
1194  
1195 my $menuItem_exportData_otherProf = Gtk3::MenuItem->new('_Non-world profiles...');
1196 $menuItem_exportData_otherProf->signal_connect('activate' => sub {
1197  
1198 # Display a 'dialogue' window, so the user can choose a non-world profile
1199 my (
1200 $choice,
1201 @otherProfList,
1202 );
1203  
1204 # Get an ordered list of all non-world profiles
1205 @otherProfList = $self->getOtherProfList();
1206 if (@otherProfList) {
1207  
1208 # Display the dialogue
1209 $choice = $self->winObj->showComboDialogue(
1210 'Export data',
1211 'Select a non-world profile to export',
1212 \@otherProfList,
1213 );
1214  
1215 if ($choice) {
1216  
1217 # Export the data
1218 $self->winObj->visibleSession->pseudoCmd('exportdata -d ' . $choice, $mode);
1219 }
1220 }
1221 });
1222 $subMenu_exportData->append($menuItem_exportData_otherProf);
1223  
1224 my $menuItem_exportData_singleCage = Gtk3::MenuItem->new('_Single cage...');
1225 $menuItem_exportData_singleCage->signal_connect('activate' => sub {
1226  
1227 # Display a 'dialogue' window, so the user can choose a cage
1228 my (
1229 $choice,
1230 @cageList,
1231 );
1232  
1233 # Get an ordered list of cages
1234 @cageList
1235 = sort {lc($a) cmp lc($b)} ($self->winObj->visibleSession->ivKeys('cageHash'));
1236 if (@cageList) {
1237  
1238 # Display the dialogue
1239 $choice = $self->winObj->showComboDialogue(
1240 'Export data',
1241 'Select a cage to export',
1242 \@cageList,
1243 );
1244  
1245 if ($choice) {
1246  
1247 # Export the data
1248 $self->winObj->visibleSession->pseudoCmd('exportdata -t ' . $choice, $mode);
1249 }
1250 }
1251 });
1252 $subMenu_exportData->append($menuItem_exportData_singleCage);
1253  
1254 my $menuItem_exportData_profCages = Gtk3::MenuItem->new('_All cages in profile...');
1255 $menuItem_exportData_profCages->signal_connect('activate' => sub {
1256  
1257 # Display a 'dialogue' window, so the user can choose a profile
1258 my (
1259 $choice,
1260 @profList,
1261 );
1262  
1263 # Get an ordered list of profiles
1264 @profList
1265 = sort {lc($a) cmp lc($b)} ($self->winObj->visibleSession->ivKeys('profHash'));
1266  
1267 if (@profList) {
1268  
1269 # Display the dialogue
1270 $choice = $self->winObj->showComboDialogue(
1271 'Export data',
1272 'Select a profile whose cages should be exported',
1273 \@profList,
1274 );
1275  
1276 if ($choice) {
1277  
1278 # Export the data
1279 $self->winObj->visibleSession->pseudoCmd('exportdata -p ' . $choice, $mode);
1280 }
1281 }
1282 });
1283 $subMenu_exportData->append($menuItem_exportData_profCages);
1284  
1285 my $menuItem_exportData_template = Gtk3::MenuItem->new('_Profile template...');
1286 $menuItem_exportData_template->signal_connect('activate' => sub {
1287  
1288 # Display a 'dialogue' window, so the user can choose a profile template
1289 my (
1290 $choice,
1291 @templList,
1292 );
1293  
1294 # Get an ordered list of all templates
1295 @templList = sort {lc($a) cmp lc($b)}
1296 ($self->winObj->visibleSession->ivKeys('templateHash'));
1297  
1298 if (@templList) {
1299  
1300 # Display the dialogue
1301 $choice = $self->winObj->showComboDialogue(
1302 'Export data',
1303 'Select a profile template to export',
1304 \@templList,
1305 );
1306  
1307 if ($choice) {
1308  
1309 # Export the data
1310 $self->winObj->visibleSession->pseudoCmd('exportdata -s ' . $choice, $mode);
1311 }
1312 }
1313 });
1314 $subMenu_exportData->append($menuItem_exportData_template);
1315  
1316 $subMenu_exportData->append(Gtk3::SeparatorMenuItem->new()); # Separator
1317  
1318 my $menuItem_exportData_initialTask = Gtk3::MenuItem->new('(_Global) initial task...');
1319 $menuItem_exportData_initialTask->signal_connect('activate' => sub {
1320  
1321 # Display a 'dialogue' window, so the user can choose a (global) initial task
1322 my (
1323 $choice,
1324 @taskList,
1325 );
1326  
1327 # Get an ordered list of all (global) initial tasks
1328 @taskList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('initTaskHash'));
1329 if (@taskList) {
1330  
1331 # Display the dialogue
1332 $choice = $self->winObj->showComboDialogue(
1333 'Export data',
1334 'Select a (global) initial task to export',
1335 \@taskList,
1336 );
1337  
1338 if ($choice) {
1339  
1340 # Export the data
1341 $self->winObj->visibleSession->pseudoCmd('exportdata -i ' . $choice, $mode);
1342 }
1343 }
1344 });
1345 $subMenu_exportData->append($menuItem_exportData_initialTask);
1346  
1347 my $menuItem_exportData_customTask = Gtk3::MenuItem->new('_Custom task...');
1348 $menuItem_exportData_customTask->signal_connect('activate' => sub {
1349  
1350 # Display a 'dialogue' window, so the user can choose a custom task
1351 my (
1352 $choice,
1353 @taskList,
1354 );
1355  
1356 # Get an ordered list of all custom task names
1357 @taskList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('customTaskHash'));
1358 if (@taskList) {
1359  
1360 # Display the dialogue
1361 $choice = $self->winObj->showComboDialogue(
1362 'Export data',
1363 'Select a custom task to export',
1364 \@taskList,
1365 );
1366  
1367 if ($choice) {
1368  
1369 # Export the data
1370 $self->winObj->visibleSession->pseudoCmd('exportdata -c ' . $choice, $mode);
1371 }
1372 }
1373 });
1374 $subMenu_exportData->append($menuItem_exportData_customTask);
1375  
1376 $subMenu_exportData->append(Gtk3::SeparatorMenuItem->new()); # Separator
1377  
1378 my $menuItem_exportData_dict = Gtk3::MenuItem->new('_Dictionary...');
1379 $menuItem_exportData_dict->signal_connect('activate' => sub {
1380  
1381 # Display a 'dialogue' window, so the user can choose a dictionary
1382 my (
1383 $choice,
1384 @dictList,
1385 );
1386  
1387 # Get an ordered list of all dictionaries, with the current dictionary at the top of
1388 # the list
1389 @dictList = $self->getDictList();
1390 if (@dictList) {
1391  
1392 # Display the dialogue
1393 $choice = $self->winObj->showComboDialogue(
1394 'Export data',
1395 'Select a dictionary to export',
1396 \@dictList,
1397 );
1398  
1399 if ($choice) {
1400  
1401 # Export the data
1402 $self->winObj->visibleSession->pseudoCmd('exportdata -y ' . $choice, $mode);
1403 }
1404 }
1405 });
1406 $subMenu_exportData->append($menuItem_exportData_dict);
1407  
1408 my $menuItem_exportData_zonemap = Gtk3::MenuItem->new('_Zonemap...');
1409 $menuItem_exportData_zonemap->signal_connect('activate' => sub {
1410  
1411 # Display a 'dialogue' window, so the user can choose a zonemap
1412 my (
1413 $choice,
1414 @zonemapList,
1415 );
1416  
1417 @zonemapList = (sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('zonemapHash')));
1418 if (@zonemapList) {
1419  
1420 # Display the dialogue
1421 $choice = $self->winObj->showComboDialogue(
1422 'Export data',
1423 'Select a zonemap to export',
1424 \@zonemapList,
1425 );
1426  
1427 if ($choice) {
1428  
1429 # Export the data
1430 $self->winObj->visibleSession->pseudoCmd('exportdata -z ' . $choice, $mode);
1431 }
1432 }
1433 });
1434 $subMenu_exportData->append($menuItem_exportData_zonemap);
1435  
1436 my $menuItem_exportData_winmap = Gtk3::MenuItem->new('_Winmap...');
1437 $menuItem_exportData_winmap->signal_connect('activate' => sub {
1438  
1439 # Display a 'dialogue' window, so the user can choose a winmap
1440 my (
1441 $choice,
1442 @winmapList,
1443 );
1444  
1445 @winmapList = (sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('winmapHash')));
1446 if (@winmapList) {
1447  
1448 # Display the dialogue
1449 $choice = $self->winObj->showComboDialogue(
1450 'Export data',
1451 'Select a winmap to export',
1452 \@winmapList,
1453 );
1454  
1455 if ($choice) {
1456  
1457 # Export the data
1458 $self->winObj->visibleSession->pseudoCmd('exportdata -p ' . $choice, $mode);
1459 }
1460 }
1461 });
1462 $subMenu_exportData->append($menuItem_exportData_winmap);
1463  
1464 my $menuItem_exportData_colScheme = Gtk3::MenuItem->new('C_olour scheme...');
1465 $menuItem_exportData_colScheme->signal_connect('activate' => sub {
1466  
1467 # Display a 'dialogue' window, so the user can choose a colour scheme
1468 my (
1469 $choice,
1470 @schemeList,
1471 );
1472  
1473 @schemeList = (
1474 sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('colourSchemeHash'))
1475 );
1476  
1477 if (@schemeList) {
1478  
1479 # Display the dialogue
1480 $choice = $self->winObj->showComboDialogue(
1481 'Export data',
1482 'Select a colour scheme to export',
1483 \@schemeList,
1484 );
1485  
1486 if ($choice) {
1487  
1488 # Export the data
1489 $self->winObj->visibleSession->pseudoCmd('exportdata -o ' . $choice, $mode);
1490 }
1491 }
1492 });
1493 $subMenu_exportData->append($menuItem_exportData_colScheme);
1494  
1495 my $menuItem_exportData_ttsObj = Gtk3::MenuItem->new('_TTS object...');
1496 $menuItem_exportData_ttsObj->signal_connect('activate' => sub {
1497  
1498 # Display a 'dialogue' window, so the user can choose a TTS object
1499 my (
1500 $choice,
1501 @objList,
1502 );
1503  
1504 @objList = (sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('ttsObjHash')));
1505 if (@objList) {
1506  
1507 # Display the dialogue
1508 $choice = $self->winObj->showComboDialogue(
1509 'Export data',
1510 'Select a text-to-speech object to export',
1511 \@objList,
1512 );
1513  
1514 if ($choice) {
1515  
1516 # Export the data
1517 $self->winObj->visibleSession->pseudoCmd('exportdata -x ' . $choice, $mode);
1518 }
1519 }
1520 });
1521 $subMenu_exportData->append($menuItem_exportData_ttsObj);
1522  
1523 my $menuItem_exportData = Gtk3::MenuItem->new('Export _data');
1524 $menuItem_exportData->set_submenu($subMenu_exportData);
1525 $menuColumn_file->append($menuItem_exportData);
1526 # (Requires a visible session whose status is 'connected' or 'offline')
1527 $self->ivAdd('menuItemHash', 'export_data', $menuItem_exportData);
1528  
1529 $menuColumn_file->append(Gtk3::SeparatorMenuItem->new()); # Separator
1530  
1531 # 'Backup data' submenu
1532 my $subMenu_backupRestore = Gtk3::Menu->new();
1533  
1534 my $menuItem_backupData = Gtk3::MenuItem->new('_Backup all data files');
1535 $menuItem_backupData->signal_connect('activate' => sub {
1536  
1537 $self->winObj->visibleSession->pseudoCmd('backupdata', $mode);
1538 });
1539 $subMenu_backupRestore->append($menuItem_backupData);
1540  
1541 my $menuItem_restoreData = Gtk3::MenuItem->new('_Restore from backup...');
1542 $menuItem_restoreData->signal_connect('activate' => sub {
1543  
1544 $self->winObj->visibleSession->pseudoCmd('restoredata', $mode);
1545 });
1546 $subMenu_backupRestore->append($menuItem_restoreData);
1547  
1548 my $menuItem_backupRestore = Gtk3::MenuItem->new('_Backup data');
1549 $menuItem_backupRestore->set_submenu($subMenu_backupRestore);
1550 $menuColumn_file->append($menuItem_backupRestore);
1551 # (Requires a visible session whose status is 'connected' or 'offline')
1552 $self->ivAdd('menuItemHash', 'backup_restore_data', $menuItem_backupRestore);
1553  
1554 $menuColumn_file->append(Gtk3::SeparatorMenuItem->new()); # Separator
1555  
1556 my $menuItem_showFiles = Gtk3::ImageMenuItem->new('S_how file objects');
1557 my $menuImg_showFiles = Gtk3::Image->new_from_stock('gtk-dialog-info', 'menu');
1558 $menuItem_showFiles->set_image($menuImg_showFiles);
1559 $menuItem_showFiles->signal_connect('activate' => sub {
1560  
1561 $self->winObj->visibleSession->pseudoCmd('showfile', $mode);
1562 });
1563 $menuColumn_file->append($menuItem_showFiles);
1564 # (Requires a visible session)
1565 $self->ivAdd('menuItemHash', 'show_files', $menuItem_showFiles);
1566  
1567 my $menuItem_disableSaveWorld = Gtk3::ImageMenuItem->new('Disable _world save');
1568 my $menuImg_disableSaveWorld = Gtk3::Image->new_from_stock('gtk-dialog-warning', 'menu');
1569 $menuItem_disableSaveWorld->set_image($menuImg_disableSaveWorld);
1570 $menuItem_disableSaveWorld->signal_connect('activate' => sub {
1571  
1572 $self->winObj->visibleSession->pseudoCmd('disablesaveworld', $mode);
1573 });
1574 $menuColumn_file->append($menuItem_disableSaveWorld);
1575 # (Requires a visible session whose status is 'connected' or 'offline')
1576 $self->ivAdd('menuItemHash', 'disable_world_save', $menuItem_disableSaveWorld);
1577  
1578 my $menuItem_disableSaveLoad = Gtk3::ImageMenuItem->new('Disabl_e all saves/loads');
1579 my $menuImg_disableSaveLoad = Gtk3::Image->new_from_stock('gtk-dialog-warning', 'menu');
1580 $menuItem_disableSaveLoad->set_image($menuImg_disableSaveLoad);
1581 $menuItem_disableSaveLoad->signal_connect('activate' => sub {
1582  
1583 $self->winObj->visibleSession->pseudoCmd('disablesaveload', $mode);
1584 });
1585 $menuColumn_file->append($menuItem_disableSaveLoad);
1586 # (Requires a visible session whose status is 'connected' or 'offline')
1587 $self->ivAdd('menuItemHash', 'disable_save_load', $menuItem_disableSaveLoad);
1588  
1589 # Setup complete
1590 return $menuColumn_file;
1591 }
1592  
1593 sub drawEditColumn {
1594  
1595 # Called by $self->enableMenu
1596 # Sets up the menu's 'Edit' column
1597 #
1598 # Expected arguments
1599 # (none besides $self)
1600 #
1601 # Return values
1602 # 'undef' on improper arguments, or if the menu can't be created
1603 # Otherwise returns the Gtk3::Menu created
1604  
1605 my ($self, $check) = @_;
1606  
1607 # Local variables
1608 my $mode;
1609  
1610 # Check for improper arguments
1611 if (defined $check) {
1612  
1613 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawEditColumn', @_);
1614 }
1615  
1616 # Import IVs (for convenience)
1617 $mode = $self->winObj->pseudoCmdMode;
1618  
1619 # Set up column
1620 my $menuColumn_edit = Gtk3::Menu->new();
1621 if (! $menuColumn_edit) {
1622  
1623 return undef;
1624 }
1625  
1626 my $menuItem_quickPrefs = Gtk3::ImageMenuItem->new(
1627 '_Quick preferences...',
1628 );
1629 my $menuImg_quickPrefs = Gtk3::Image->new_from_stock('gtk-preferences', 'menu');
1630 $menuItem_quickPrefs->set_image($menuImg_quickPrefs);
1631 $menuItem_quickPrefs->signal_connect('activate' => sub {
1632  
1633 $self->winObj->visibleSession->pseudoCmd('editquick', $mode);
1634 });
1635 $menuColumn_edit->append($menuItem_quickPrefs);
1636 # (Requires a visible session whose status is 'connected' or 'offline')
1637 $self->ivAdd('menuItemHash', 'edit_quick_prefs', $menuItem_quickPrefs);
1638  
1639 my $menuItem_clientPrefs = Gtk3::ImageMenuItem->new(
1640 $axmud::SCRIPT . ' _preferences...',
1641 );
1642 my $menuImg_clientPrefs = Gtk3::Image->new_from_stock('gtk-preferences', 'menu');
1643 $menuItem_clientPrefs->set_image($menuImg_clientPrefs);
1644 $menuItem_clientPrefs->signal_connect('activate' => sub {
1645  
1646 $self->winObj->visibleSession->pseudoCmd('editclient', $mode);
1647 });
1648 $menuColumn_edit->append($menuItem_clientPrefs);
1649 # (Requires a visible session whose status is 'connected' or 'offline')
1650 $self->ivAdd('menuItemHash', 'edit_client_prefs', $menuItem_clientPrefs);
1651  
1652 my $menuItem_sessionPrefs = Gtk3::ImageMenuItem->new('_Session preferences...');
1653 my $menuImg_sessionPrefs = Gtk3::Image->new_from_stock('gtk-preferences', 'menu');
1654 $menuItem_sessionPrefs->set_image($menuImg_sessionPrefs);
1655 $menuItem_sessionPrefs->signal_connect('activate' => sub {
1656  
1657 $self->winObj->visibleSession->pseudoCmd('editsession', $mode);
1658 });
1659 $menuColumn_edit->append($menuItem_sessionPrefs);
1660 # (Requires a visible session whose status is 'connected' or 'offline')
1661 $self->ivAdd('menuItemHash', 'edit_session_prefs', $menuItem_sessionPrefs);
1662  
1663 $menuColumn_edit->append(Gtk3::SeparatorMenuItem->new()); # Separator
1664  
1665 my $menuItem_editWorld = Gtk3::ImageMenuItem->new('Edit current _world...');
1666 my $menuImg_editWorld = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
1667 $menuItem_editWorld->set_image($menuImg_editWorld);
1668 $menuItem_editWorld->signal_connect('activate' => sub {
1669  
1670 $self->winObj->visibleSession->pseudoCmd('editworld', $mode);
1671 });
1672 $menuColumn_edit->append($menuItem_editWorld);
1673 # (Requires a visible session whose status is 'connected' or 'offline')
1674 $self->ivAdd('menuItemHash', 'edit_current_world', $menuItem_editWorld);
1675  
1676 my $menuItem_editGuild = Gtk3::ImageMenuItem->new('Edit current _guild...');
1677 my $menuImg_editGuild = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
1678 $menuItem_editGuild->set_image($menuImg_editGuild);
1679 $menuItem_editGuild->signal_connect('activate' => sub {
1680  
1681 $self->winObj->visibleSession->pseudoCmd('editguild', $mode);
1682 });
1683 $menuColumn_edit->append($menuItem_editGuild);
1684 # Requires a current session whose status is 'connected' or 'offline' and whose
1685 # ->currentGuild is defined
1686 $self->ivAdd('menuItemHash', 'edit_current_guild', $menuItem_editGuild);
1687  
1688 my $menuItem_editRace = Gtk3::ImageMenuItem->new('Edit current _race...');
1689 my $menuImg_editRace = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
1690 $menuItem_editRace->set_image($menuImg_editRace);
1691 $menuItem_editRace->signal_connect('activate' => sub {
1692  
1693 $self->winObj->visibleSession->pseudoCmd('editrace', $mode);
1694 });
1695 $menuColumn_edit->append($menuItem_editRace);
1696 # Requires a current session whose status is 'connected' or 'offline' and whose
1697 # ->currentRace is defined
1698 $self->ivAdd('menuItemHash', 'edit_current_race', $menuItem_editRace);
1699  
1700 my $menuItem_editChar = Gtk3::ImageMenuItem->new('Edit current _character...');
1701 my $menuImg_editChar = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
1702 $menuItem_editChar->set_image($menuImg_editChar);
1703 $menuItem_editChar->signal_connect('activate' => sub {
1704  
1705 $self->winObj->visibleSession->pseudoCmd('editchar', $mode);
1706 });
1707 $menuColumn_edit->append($menuItem_editChar);
1708 # Requires a current session whose status is 'connected' or 'offline' and whose
1709 # ->currentChar is defined
1710 $self->ivAdd('menuItemHash', 'edit_current_char', $menuItem_editChar);
1711  
1712 $menuColumn_edit->append(Gtk3::SeparatorMenuItem->new()); # Separator
1713  
1714 my $menuItem_locatorWiz = Gtk3::ImageMenuItem->new('Run Locator w_izard...');
1715 my $menuImg_locatorWiz = Gtk3::Image->new_from_stock('gtk-page-setup', 'menu');
1716 $menuItem_locatorWiz->set_image($menuImg_locatorWiz);
1717 $menuItem_locatorWiz->signal_connect('activate' => sub {
1718  
1719 $self->winObj->visibleSession->pseudoCmd('locatorwizard', $mode);
1720 });
1721 $menuColumn_edit->append($menuItem_locatorWiz);
1722 # (Requires a visible session whose status is 'connected' or 'offline'. A
1723 # corresponding menu item also appears in $self->drawTasksColumn)
1724 $self->ivAdd('menuItemHash', 'run_locator_wiz', $menuItem_locatorWiz);
1725  
1726 my $menuItem_editWorldModel = Gtk3::ImageMenuItem->new('Edit world _model...');
1727 my $menuImg_editWorldModel = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
1728 $menuItem_editWorldModel->set_image($menuImg_editWorldModel);
1729 $menuItem_editWorldModel->signal_connect('activate' => sub {
1730  
1731 $self->winObj->visibleSession->pseudoCmd('editmodel', $mode);
1732 });
1733 $menuColumn_edit->append($menuItem_editWorldModel);
1734 # (Requires a visible session whose status is 'connected' or 'offline')
1735 $self->ivAdd('menuItemHash', 'edit_world_model', $menuItem_editWorldModel);
1736  
1737 my $menuItem_editDict = Gtk3::ImageMenuItem->new('Edit _dictionary...');
1738 my $menuImg_editDict = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
1739 $menuItem_editDict->set_image($menuImg_editDict);
1740 $menuItem_editDict->signal_connect('activate' => sub {
1741  
1742 $self->winObj->visibleSession->pseudoCmd('editdictionary', $mode);
1743 });
1744 $menuColumn_edit->append($menuItem_editDict);
1745 # (Requires a visible session whose status is 'connected' or 'offline')
1746 $self->ivAdd('menuItemHash', 'edit_dictionary', $menuItem_editDict);
1747  
1748 $menuColumn_edit->append(Gtk3::SeparatorMenuItem->new()); # Separator
1749  
1750 # 'Simulate' submenu
1751 my $subMenu_simulate = Gtk3::Menu->new();
1752  
1753 my $menuItem_simWorld = Gtk3::MenuItem->new('Simulate _world...');
1754 $menuItem_simWorld->signal_connect('activate' => sub {
1755  
1756 # Open a simulate world 'dialogue' window. The text entered is used in a
1757 # ';simulateworld' command
1758 $self->winObj->visibleSession->pseudoCmd('simulateworld', $mode);
1759 });
1760 $subMenu_simulate->append($menuItem_simWorld);
1761  
1762 my $menuItem_simPrompt = Gtk3::MenuItem->new('Simulate _prompt...');
1763 $menuItem_simPrompt->signal_connect('activate' => sub {
1764  
1765 # Open a simulate prompt 'dialogue' window. The text entered is used in a
1766 # ';simulateprompt' command
1767 $self->winObj->visibleSession->pseudoCmd('simulateprompt', $mode);
1768 });
1769 $subMenu_simulate->append($menuItem_simPrompt);
1770  
1771 my $menuItem_simCmd = Gtk3::MenuItem->new('Simulate _command...');
1772 $menuItem_simCmd->signal_connect('activate' => sub {
1773  
1774 # Prompt the user for a world command
1775 my $cmd = $self->winObj->showEntryDialogue(
1776 'Simulate world command',
1777 'Enter a world command (not actually sent to the world)',
1778 );
1779  
1780 if ($cmd) {
1781  
1782 $self->winObj->visibleSession->pseudoCmd(
1783 'simulatecommand <' . $cmd . '>',
1784 $mode,
1785 );
1786 }
1787 });
1788 $subMenu_simulate->append($menuItem_simCmd);
1789  
1790 my $menuItem_simHook = Gtk3::MenuItem->new('Simulate _hook event...');
1791 $menuItem_simHook->signal_connect('activate' => sub {
1792  
1793 my (
1794 $interfaceModel, $choice, $number, $cancelFlag, $cmd,
1795 @eventList, @hookDataList,
1796 );
1797  
1798 # Get the hook interface model, and from there, a list of hook events
1799 $interfaceModel = $axmud::CLIENT->ivShow('interfaceModelHash', 'hook');
1800 @eventList = sort {$a cmp $b} ($interfaceModel->ivKeys('hookEventHash'));
1801  
1802 # Prompt the user for a hook event
1803 $choice = $self->winObj->showComboDialogue(
1804 'Simulate hook event',
1805 'Enter a hook event for ' . $axmud::SCRIPT . ' to simulate',
1806 \@eventList,
1807 );
1808  
1809 if ($choice) {
1810  
1811 # How many items of hook data are expected?
1812 $number = $interfaceModel->ivShow('hookEventHash', $choice);
1813 if ($number == 1) {
1814  
1815 my $result = $self->winObj->showEntryDialogue(
1816 'Simulate hook event',
1817 'Enter hook data #1 for the hook \'' . $choice . '\'',
1818 );
1819  
1820 if (! $result) {
1821  
1822 # Don't simulate the hook event
1823 $cancelFlag = TRUE;
1824  
1825 } else {
1826  
1827 push (@hookDataList, $result);
1828 }
1829  
1830 } elsif ($number == 2) {
1831  
1832 my @resultList = $self->winObj->showDoubleEntryDialogue(
1833 'Simulate hook event',
1834 'Enter hook data #1 for the hook \'' . $choice . '\'',
1835 'Enter hook data #2',
1836 );
1837  
1838 # Both hook data items must contain at least one character
1839 if (! @resultList || ! $resultList[0] || ! $resultList[1]) {
1840  
1841 # Don't simulate the hook event
1842 $cancelFlag = TRUE;
1843  
1844 } else {
1845  
1846 push (@hookDataList, @resultList);
1847 }
1848 }
1849  
1850 if (! $cancelFlag) {
1851  
1852 # Prepare the client command to execute...
1853 $cmd = 'simulatehook ' . $choice;
1854 foreach my $item (@hookDataList) {
1855  
1856 $cmd .= ' <' . $item . '>';
1857 }
1858  
1859 # ...and execute it
1860 $self->winObj->visibleSession->pseudoCmd($cmd, $mode);
1861 }
1862 }
1863 });
1864 $subMenu_simulate->append($menuItem_simHook);
1865  
1866 my $menuItem_simulate = Gtk3::MenuItem->new('Sim_ulate');
1867 $menuItem_simulate->set_submenu($subMenu_simulate);
1868 $menuColumn_edit->append($menuItem_simulate);
1869 # (Requires a visible session whose status is 'connected' or 'offline')
1870 $self->ivAdd('menuItemHash', 'simulate', $menuItem_simulate);
1871  
1872 my $menuItem_patternTest = Gtk3::MenuItem->new('_Test patterns...');
1873 $menuItem_patternTest->signal_connect('activate' => sub {
1874  
1875 $self->winObj->visibleSession->pseudoCmd('testpattern', $mode);
1876 });
1877 $menuColumn_edit->append($menuItem_patternTest);
1878 # (Desensitised only when the setup wizwin is open)
1879 $self->ivAdd('menuItemHash', 'test_pattern', $menuItem_patternTest);
1880  
1881 # Setup complete
1882 return $menuColumn_edit;
1883 }
1884  
1885 sub drawInterfacesColumn {
1886  
1887 # Called by $self->enableMenu
1888 # Sets up the menu's 'Interfaces' column
1889 #
1890 # Expected arguments
1891 # (none besides $self)
1892 #
1893 # Return values
1894 # 'undef' on improper arguments, or if the menu can't be created
1895 # Otherwise returns the Gtk3::Menu created
1896  
1897 my ($self, $check) = @_;
1898  
1899 # Local variables
1900 my $mode;
1901  
1902 # Check for improper arguments
1903 if (defined $check) {
1904  
1905 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawInterfacesColumn', @_);
1906 }
1907  
1908 # Import IVs (for convenience)
1909 $mode = $self->winObj->pseudoCmdMode;
1910  
1911 # Set up column
1912 my $menuColumn_interfaces = Gtk3::Menu->new();
1913 if (! $menuColumn_interfaces) {
1914  
1915 return undef;
1916 }
1917  
1918 my $menuItem_activeInterfaces = Gtk3::MenuItem->new('Acti_ve interfaces...');
1919 $menuItem_activeInterfaces->signal_connect('activate' => sub {
1920  
1921 # Open a session preference window on the notebook's second page, so the user can see
1922 # the list of active interfaces immediately
1923 $self->winObj->visibleSession->pseudoCmd('editactiveinterface', $mode);
1924 });
1925 $menuColumn_interfaces->append($menuItem_activeInterfaces);
1926 # (Requires a visible session whose status is 'connected' or 'offline')
1927 $self->ivAdd('menuItemHash', 'active_interfaces', $menuItem_activeInterfaces);
1928  
1929 $menuColumn_interfaces->append(Gtk3::SeparatorMenuItem->new()); # Separator
1930  
1931 # 'Triggers' submenu
1932 my $subMenu_showTriggers = Gtk3::Menu->new();
1933  
1934 my $menuItem_worldTriggers = Gtk3::MenuItem->new('_World triggers...');
1935 $menuItem_worldTriggers->signal_connect('activate' => sub {
1936  
1937 # Open the cage window on the notebook's second page, so the user can see the list
1938 # of triggers immediately
1939 $self->winObj->visibleSession->pseudoCmd('editcage -t', $mode);
1940 });
1941 $subMenu_showTriggers->append($menuItem_worldTriggers);
1942  
1943 my $menuItem_guildTriggers = Gtk3::MenuItem->new('_Guild triggers...');
1944 $menuItem_guildTriggers->signal_connect('activate' => sub {
1945  
1946 $self->winObj->visibleSession->pseudoCmd(
1947 'editcage trigger_guild_' . $self->winObj->visibleSession->currentGuild->name,
1948 $mode,
1949 );
1950 });
1951 $subMenu_showTriggers->append($menuItem_guildTriggers);
1952 # (Requires a visible session whose status is 'connected' or 'offline', and a current
1953 # guild)
1954 $self->ivAdd('menuItemHash', 'guild_triggers', $menuItem_guildTriggers);
1955  
1956 my $menuItem_raceTriggers = Gtk3::MenuItem->new('_Race triggers...');
1957 $menuItem_raceTriggers->signal_connect('activate' => sub {
1958  
1959 $self->winObj->visibleSession->pseudoCmd(
1960 'editcage trigger_race_' . $self->winObj->visibleSession->currentRace->name,
1961 $mode,
1962 );
1963 });
1964 $subMenu_showTriggers->append($menuItem_raceTriggers);
1965 # (Requires a visible session whose status is 'connected' or 'offline', and a current
1966 # race)
1967 $self->ivAdd('menuItemHash', 'race_triggers', $menuItem_raceTriggers);
1968  
1969 my $menuItem_charTriggers = Gtk3::MenuItem->new('_Character triggers...');
1970 $menuItem_charTriggers->signal_connect('activate' => sub {
1971  
1972 $self->winObj->visibleSession->pseudoCmd(
1973 'editcage trigger_char_' . $self->winObj->visibleSession->currentChar->name,
1974 $mode,
1975 );
1976 });
1977 $subMenu_showTriggers->append($menuItem_charTriggers);
1978 # (Requires a visible session whose status is 'connected' or 'offline', and a current
1979 # character)
1980 $self->ivAdd('menuItemHash', 'char_triggers', $menuItem_charTriggers);
1981  
1982 my $menuItem_showTriggers = Gtk3::MenuItem->new('_Triggers');
1983 $menuItem_showTriggers->set_submenu($subMenu_showTriggers);
1984 $menuColumn_interfaces->append($menuItem_showTriggers);
1985 # (Requires a visible session whose status is 'connected' or 'offline')
1986 $self->ivAdd('menuItemHash', 'show_triggers', $menuItem_showTriggers);
1987  
1988 # 'Aliases' submenu
1989 my $subMenu_showAliases = Gtk3::Menu->new();
1990  
1991 my $menuItem_worldAliases = Gtk3::MenuItem->new('World _aliases...');
1992 $menuItem_worldAliases->signal_connect('activate' => sub {
1993  
1994 # Open the cage window on the notebook's second page, so the user can see the list
1995 # of aliases immediately
1996 $self->winObj->visibleSession->pseudoCmd('editcage -a', $mode);
1997 });
1998 $subMenu_showAliases->append($menuItem_worldAliases);
1999  
2000 my $menuItem_guildAliases = Gtk3::MenuItem->new('_Guild aliases...');
2001 $menuItem_guildAliases->signal_connect('activate' => sub {
2002  
2003 $self->winObj->visibleSession->pseudoCmd(
2004 'editcage alias_guild_' . $self->winObj->visibleSession->currentGuild->name,
2005 $mode,
2006 );
2007 });
2008 $subMenu_showAliases->append($menuItem_guildAliases);
2009 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2010 # guild)
2011 $self->ivAdd('menuItemHash', 'guild_aliases', $menuItem_guildAliases);
2012  
2013 my $menuItem_raceAliases = Gtk3::MenuItem->new('_Race aliases...');
2014 $menuItem_raceAliases->signal_connect('activate' => sub {
2015  
2016 $self->winObj->visibleSession->pseudoCmd(
2017 'editcage alias_race_' . $self->winObj->visibleSession->currentRace->name,
2018 $mode,
2019 );
2020 });
2021 $subMenu_showAliases->append($menuItem_raceAliases);
2022 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2023 # race)
2024 $self->ivAdd('menuItemHash', 'race_aliases', $menuItem_raceAliases);
2025  
2026 my $menuItem_charAliases = Gtk3::MenuItem->new('_Character aliases...');
2027 $menuItem_charAliases->signal_connect('activate' => sub {
2028  
2029 $self->winObj->visibleSession->pseudoCmd(
2030 'editcage alias_char_' . $self->winObj->visibleSession->currentChar->name,
2031 $mode,
2032 );
2033 });
2034 $subMenu_showAliases->append($menuItem_charAliases);
2035 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2036 # character)
2037 $self->ivAdd('menuItemHash', 'char_aliases', $menuItem_charAliases);
2038  
2039 my $menuItem_showAliases = Gtk3::MenuItem->new('_Aliases');
2040 $menuItem_showAliases->set_submenu($subMenu_showAliases);
2041 $menuColumn_interfaces->append($menuItem_showAliases);
2042 # (Requires a visible session whose status is 'connected' or 'offline')
2043 $self->ivAdd('menuItemHash', 'show_aliases', $menuItem_showAliases);
2044  
2045 # 'Macros' submenu
2046 my $subMenu_showMacros = Gtk3::Menu->new();
2047  
2048 my $menuItem_worldMacros = Gtk3::MenuItem->new('_World macros...');
2049 $menuItem_worldMacros->signal_connect('activate' => sub {
2050  
2051 # Open the cage window on the notebook's second page, so the user can see the list
2052 # of macros immediately
2053 $self->winObj->visibleSession->pseudoCmd('editcage -m', $mode);
2054 });
2055 $subMenu_showMacros->append($menuItem_worldMacros);
2056  
2057 my $menuItem_guildMacros = Gtk3::MenuItem->new('_Guild macros...');
2058 $menuItem_guildMacros->signal_connect('activate' => sub {
2059  
2060 $self->winObj->visibleSession->pseudoCmd(
2061 'editcage macro_guild_' . $self->winObj->visibleSession->currentGuild->name,
2062 $mode,
2063 );
2064 });
2065 $subMenu_showMacros->append($menuItem_guildMacros);
2066 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2067 # guild)
2068 $self->ivAdd('menuItemHash', 'guild_macros', $menuItem_guildMacros);
2069  
2070 my $menuItem_raceMacros = Gtk3::MenuItem->new('_Race macros...');
2071 $menuItem_raceMacros->signal_connect('activate' => sub {
2072  
2073 $self->winObj->visibleSession->pseudoCmd(
2074 'editcage macro_race_' . $self->winObj->visibleSession->currentRace->name,
2075 $mode,
2076 );
2077 });
2078 $subMenu_showMacros->append($menuItem_raceMacros);
2079 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2080 # race)
2081 $self->ivAdd('menuItemHash', 'race_macros', $menuItem_raceMacros);
2082  
2083 my $menuItem_charMacros = Gtk3::MenuItem->new('_Character macros...');
2084 $menuItem_charMacros->signal_connect('activate' => sub {
2085  
2086 $self->winObj->visibleSession->pseudoCmd(
2087 'editcage macro_char_' . $self->winObj->visibleSession->currentChar->name,
2088 $mode,
2089 );
2090 });
2091 $subMenu_showMacros->append($menuItem_charMacros);
2092 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2093 # character)
2094 $self->ivAdd('menuItemHash', 'char_macros', $menuItem_charMacros);
2095  
2096 my $menuItem_showMacros = Gtk3::MenuItem->new('_Macros');
2097 $menuItem_showMacros->set_submenu($subMenu_showMacros);
2098 $menuColumn_interfaces->append($menuItem_showMacros);
2099 # (Requires a visible session whose status is 'connected' or 'offline')
2100 $self->ivAdd('menuItemHash', 'show_macros', $menuItem_showMacros);
2101  
2102 # 'Timers' submenu
2103 my $subMenu_showTimers = Gtk3::Menu->new();
2104  
2105 my $menuItem_worldTimers = Gtk3::MenuItem->new('_World timers...');
2106 $menuItem_worldTimers->signal_connect('activate' => sub {
2107  
2108 # Open the cage window on the notebook's second page, so the user can see the list
2109 # of timers immediately
2110 $self->winObj->visibleSession->pseudoCmd('editcage -i', $mode);
2111 });
2112 $subMenu_showTimers->append($menuItem_worldTimers);
2113  
2114 my $menuItem_guildTimers = Gtk3::MenuItem->new('_Guild timers...');
2115 $menuItem_guildTimers->signal_connect('activate' => sub {
2116  
2117 $self->winObj->visibleSession->pseudoCmd(
2118 'editcage timer_guild_' . $self->winObj->visibleSession->currentGuild->name,
2119 $mode,
2120 );
2121 });
2122 $subMenu_showTimers->append($menuItem_guildTimers);
2123 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2124 # guild)
2125 $self->ivAdd('menuItemHash', 'guild_timers', $menuItem_guildTimers);
2126  
2127 my $menuItem_raceTimers = Gtk3::MenuItem->new('_Race timers...');
2128 $menuItem_raceTimers->signal_connect('activate' => sub {
2129  
2130 $self->winObj->visibleSession->pseudoCmd(
2131 'editcage timer_race_' . $self->winObj->visibleSession->currentRace->name,
2132 $mode,
2133 );
2134 });
2135 $subMenu_showTimers->append($menuItem_raceTimers);
2136 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2137 # race)
2138 $self->ivAdd('menuItemHash', 'race_timers', $menuItem_raceTimers);
2139  
2140 my $menuItem_charTimers = Gtk3::MenuItem->new('_Character timers...');
2141 $menuItem_charTimers->signal_connect('activate' => sub {
2142  
2143 $self->winObj->visibleSession->pseudoCmd(
2144 'editcage timer_char_' . $self->winObj->visibleSession->currentChar->name,
2145 $mode,
2146 );
2147 });
2148 $subMenu_showTimers->append($menuItem_charTimers);
2149 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2150 # character)
2151 $self->ivAdd('menuItemHash', 'char_timers', $menuItem_charTimers);
2152  
2153 my $menuItem_showTimers = Gtk3::MenuItem->new('T_imers');
2154 $menuItem_showTimers->set_submenu($subMenu_showTimers);
2155 $menuColumn_interfaces->append($menuItem_showTimers);
2156 # (Requires a visible session whose status is 'connected' or 'offline')
2157 $self->ivAdd('menuItemHash', 'show_timers', $menuItem_showTimers);
2158  
2159 # 'Hooks' submenu
2160 my $subMenu_showHooks = Gtk3::Menu->new();
2161  
2162 my $menuItem_worldHooks = Gtk3::MenuItem->new('_World hooks...');
2163 $menuItem_worldHooks->signal_connect('activate' => sub {
2164  
2165 # Open the cage window on the notebook's second page, so the user can see the list
2166 # of hooks immediately
2167 $self->winObj->visibleSession->pseudoCmd('editcage -h', $mode);
2168 });
2169 $subMenu_showHooks->append($menuItem_worldHooks);
2170  
2171 my $menuItem_guildHooks = Gtk3::MenuItem->new('_Guild hooks...');
2172 $menuItem_guildHooks->signal_connect('activate' => sub {
2173  
2174 $self->winObj->visibleSession->pseudoCmd(
2175 'editcage hook_guild_' . $self->winObj->visibleSession->currentGuild->name,
2176 $mode,
2177 );
2178 });
2179 $subMenu_showHooks->append($menuItem_guildHooks);
2180 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2181 # guild)
2182 $self->ivAdd('menuItemHash', 'guild_hooks', $menuItem_guildHooks);
2183  
2184 my $menuItem_raceHooks = Gtk3::MenuItem->new('_Race hooks...');
2185 $menuItem_raceHooks->signal_connect('activate' => sub {
2186  
2187 $self->winObj->visibleSession->pseudoCmd(
2188 'editcage hook_race_' . $self->winObj->visibleSession->currentRace->name,
2189 $mode,
2190 );
2191 });
2192 $subMenu_showHooks->append($menuItem_raceHooks);
2193 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2194 # race)
2195 $self->ivAdd('menuItemHash', 'race_hooks', $menuItem_raceHooks);
2196  
2197 my $menuItem_charHooks = Gtk3::MenuItem->new('_Character hooks...');
2198 $menuItem_charHooks->signal_connect('activate' => sub {
2199  
2200 $self->winObj->visibleSession->pseudoCmd(
2201 'editcage hook_char_' . $self->winObj->visibleSession->currentChar->name,
2202 $mode,
2203 );
2204 });
2205 $subMenu_showHooks->append($menuItem_charHooks);
2206 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2207 # character)
2208 $self->ivAdd('menuItemHash', 'char_hooks', $menuItem_charHooks);
2209  
2210 my $menuItem_showHooks = Gtk3::MenuItem->new('_Hooks');
2211 $menuItem_showHooks->set_submenu($subMenu_showHooks);
2212 $menuColumn_interfaces->append($menuItem_showHooks);
2213 # (Requires a visible session whose status is 'connected' or 'offline')
2214 $self->ivAdd('menuItemHash', 'show_hooks', $menuItem_showHooks);
2215  
2216 $menuColumn_interfaces->append(Gtk3::SeparatorMenuItem->new()); # Separator
2217  
2218 # 'Commands' submenu
2219 my $subMenu_showCmds = Gtk3::Menu->new();
2220  
2221 my $menuItem_worldCmds = Gtk3::MenuItem->new('_World commands...');
2222 $menuItem_worldCmds->signal_connect('activate' => sub {
2223  
2224 # Open the cage window on the notebook's second page, so the user can see the list
2225 # OF commands immediately
2226 $self->winObj->visibleSession->pseudoCmd('editcage -c', $mode);
2227 });
2228 $subMenu_showCmds->append($menuItem_worldCmds);
2229  
2230 my $menuItem_guildCmds = Gtk3::MenuItem->new('_Guild commands...');
2231 $menuItem_guildCmds->signal_connect('activate' => sub {
2232  
2233 $self->winObj->visibleSession->pseudoCmd(
2234 'editcage cmd_guild_' . $self->winObj->visibleSession->currentGuild->name,
2235 $mode,
2236 );
2237 });
2238 $subMenu_showCmds->append($menuItem_guildCmds);
2239 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2240 # guild)
2241 $self->ivAdd('menuItemHash', 'guild_cmds', $menuItem_guildCmds);
2242  
2243 my $menuItem_raceCmds = Gtk3::MenuItem->new('_Race commands...');
2244 $menuItem_raceCmds->signal_connect('activate' => sub {
2245  
2246 $self->winObj->visibleSession->pseudoCmd(
2247 'editcage cmd_race_' . $self->winObj->visibleSession->currentRace->name,
2248 $mode,
2249 );
2250 });
2251 $subMenu_showCmds->append($menuItem_raceCmds);
2252 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2253 # race)
2254 $self->ivAdd('menuItemHash', 'race_cmds', $menuItem_raceCmds);
2255  
2256 my $menuItem_charCmds = Gtk3::MenuItem->new('_Character commands...');
2257 $menuItem_charCmds->signal_connect('activate' => sub {
2258  
2259 $self->winObj->visibleSession->pseudoCmd(
2260 'editcage cmd_char_' . $self->winObj->visibleSession->currentChar->name,
2261 $mode,
2262 );
2263 });
2264 $subMenu_showCmds->append($menuItem_charCmds);
2265 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2266 # character)
2267 $self->ivAdd('menuItemHash', 'char_cmds', $menuItem_charCmds);
2268  
2269 my $menuItem_showCmds = Gtk3::MenuItem->new('_Commands');
2270 $menuItem_showCmds->set_submenu($subMenu_showCmds);
2271 $menuColumn_interfaces->append($menuItem_showCmds);
2272 # (Requires a visible session whose status is 'connected' or 'offline')
2273 $self->ivAdd('menuItemHash', 'show_cmds', $menuItem_showCmds);
2274  
2275 # 'Routes' submenu
2276 my $subMenu_showRoutes = Gtk3::Menu->new();
2277  
2278 my $menuItem_worldRoutes = Gtk3::MenuItem->new('_World routes...');
2279 $menuItem_worldRoutes->signal_connect('activate' => sub {
2280  
2281 # Open the cage window on the notebook's second page, so the user can see the list
2282 # OF routes immediately
2283 $self->winObj->visibleSession->pseudoCmd('editcage -r', $mode);
2284 });
2285 $subMenu_showRoutes->append($menuItem_worldRoutes);
2286  
2287 my $menuItem_guildRoutes = Gtk3::MenuItem->new('_Guild routes...');
2288 $menuItem_guildRoutes->signal_connect('activate' => sub {
2289  
2290 $self->winObj->visibleSession->pseudoCmd(
2291 'editcage route_guild_' . $self->winObj->visibleSession->currentGuild->name,
2292 $mode,
2293 );
2294 });
2295 $subMenu_showRoutes->append($menuItem_guildRoutes);
2296 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2297 # guild)
2298 $self->ivAdd('menuItemHash', 'guild_routes', $menuItem_guildRoutes);
2299  
2300 my $menuItem_raceRoutes = Gtk3::MenuItem->new('_Race routes...');
2301 $menuItem_raceRoutes->signal_connect('activate' => sub {
2302  
2303 $self->winObj->visibleSession->pseudoCmd(
2304 'editcage route_race_' . $self->winObj->visibleSession->currentRace->name,
2305 $mode,
2306 );
2307 });
2308 $subMenu_showRoutes->append($menuItem_raceRoutes);
2309 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2310 # race)
2311 $self->ivAdd('menuItemHash', 'race_routes', $menuItem_raceRoutes);
2312  
2313 my $menuItem_charRoutes = Gtk3::MenuItem->new('_Character routes...');
2314 $menuItem_charRoutes->signal_connect('activate' => sub {
2315  
2316 $self->winObj->visibleSession->pseudoCmd(
2317 'editcage route_char_' . $self->winObj->visibleSession->currentChar->name,
2318 $mode,
2319 );
2320 });
2321 $subMenu_showRoutes->append($menuItem_charRoutes);
2322 # (Requires a visible session whose status is 'connected' or 'offline', and a current
2323 # character)
2324 $self->ivAdd('menuItemHash', 'char_routes', $menuItem_charRoutes);
2325  
2326 my $menuItem_showRoutes = Gtk3::MenuItem->new('_Routes');
2327 $menuItem_showRoutes->set_submenu($subMenu_showRoutes);
2328 $menuColumn_interfaces->append($menuItem_showRoutes);
2329 # (Requires a visible session whose status is 'connected' or 'offline')
2330 $self->ivAdd('menuItemHash', 'show_routes', $menuItem_showRoutes);
2331  
2332 # Setup complete
2333 return $menuColumn_interfaces;
2334 }
2335  
2336 sub drawTasksColumn {
2337  
2338 # Called by $self->enableMenu
2339 # Sets up the menu's 'Tasks' column
2340 #
2341 # Expected arguments
2342 # (none besides $self)
2343 #
2344 # Return values
2345 # 'undef' on improper arguments, or if the menu can't be created
2346 # Otherwise returns the Gtk3::Menu created
2347  
2348 my ($self, $check) = @_;
2349  
2350 # Local variables
2351 my $mode;
2352  
2353 # Check for improper arguments
2354 if (defined $check) {
2355  
2356 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawTasksColumn', @_);
2357 }
2358  
2359 # Import IVs (for convenience)
2360 $mode = $self->winObj->pseudoCmdMode;
2361  
2362 # Set up column
2363 my $menuColumn_tasks = Gtk3::Menu->new();
2364 if (! $menuColumn_tasks) {
2365  
2366 return undef;
2367 }
2368  
2369 my $menuItem_freezeTasks = Gtk3::CheckMenuItem->new('_Freeze all tasks');
2370 $menuItem_freezeTasks->signal_connect('toggled' => sub {
2371  
2372 $self->winObj->visibleSession->pseudoCmd('freezetask', $mode);
2373 });
2374 $menuColumn_tasks->append($menuItem_freezeTasks);
2375 # (Requires a visible session whose status is 'connected' or 'offline')
2376 $self->ivAdd('menuItemHash', 'freeze_tasks', $menuItem_freezeTasks);
2377  
2378 # 'Start new task' submenu
2379 my $subMenu_startNewTask = Gtk3::Menu->new();
2380  
2381 my @taskList = (
2382 'channels', 'chat', 'compass', 'condition', 'divert', 'inventory', 'locator',
2383 'status', 'watch',
2384 );
2385  
2386 my @mnemonicList = (
2387 '_Channels task', 'C_hat task', 'C_ompass task', 'Con_dition task', '_Divert task',
2388 '_Inventory task', '_Locator task', '_Status task', '_Watch task',
2389 );
2390  
2391 foreach my $task (@taskList) {
2392  
2393 my $menuItem_startNewTask_task = Gtk3::MenuItem->new(shift @mnemonicList);
2394 $menuItem_startNewTask_task->signal_connect('activate' => sub {
2395  
2396 $self->winObj->visibleSession->pseudoCmd(
2397 'starttask ' . $task,
2398 $mode,
2399 );
2400 });
2401 $subMenu_startNewTask->append($menuItem_startNewTask_task);
2402 # (Requires a visible session whose status is 'connected' or 'offline'; in addition,
2403 # some of these tasks must be unique)
2404 $self->ivAdd('menuItemHash', $task . '_task_start', $menuItem_startNewTask_task);
2405 }
2406  
2407 my $menuItem_startNewTask = Gtk3::MenuItem->new('Start _new task');
2408 $menuItem_startNewTask->set_submenu($subMenu_startNewTask);
2409 $menuColumn_tasks->append($menuItem_startNewTask);
2410 # (Requires a visible session whose status is 'connected' or 'offline')
2411 $self->ivAdd('menuItemHash', 'start_new_task', $menuItem_startNewTask);
2412  
2413 $menuColumn_tasks->append(Gtk3::SeparatorMenuItem->new()); # Separator
2414  
2415 # 'Channels task' submenu
2416 my $subMenu_channelsTask = Gtk3::Menu->new();
2417  
2418 my $menuItem_channelsTask_addPattern = Gtk3::MenuItem->new('Add _channel pattern...');
2419 $menuItem_channelsTask_addPattern->signal_connect('activate' => sub {
2420  
2421 my ($pattern, $channel);
2422  
2423 # Prompt the user for a pattern/channel
2424 ($pattern, $channel) = $self->winObj->showDoubleEntryDialogue(
2425 'Add channel pattern',
2426 'Enter a pattern (regex)',
2427 'Enter a channel (1-16 chars)',
2428 );
2429  
2430 if (defined $pattern && defined $channel) {
2431  
2432 $self->winObj->visibleSession->pseudoCmd(
2433 'addchannelpattern <' . $channel . '> <' . $pattern . '>',
2434 $mode,
2435 );
2436 }
2437 });
2438 $subMenu_channelsTask->append($menuItem_channelsTask_addPattern);
2439  
2440 my $menuItem_channelsTask_addException = Gtk3::MenuItem->new(
2441 'Add _exception pattern...',
2442 );
2443 $menuItem_channelsTask_addException->signal_connect('activate' => sub {
2444  
2445 # Prompt the user for a pattern
2446 my $pattern = $self->winObj->showEntryDialogue(
2447 'Add exception pattern',
2448 'Enter a pattern (regex)',
2449 );
2450  
2451 if (defined $pattern) {
2452  
2453 $self->winObj->visibleSession->pseudoCmd(
2454 'addchannelpattern -e <' . $pattern . '>',
2455 $mode,
2456 );
2457 }
2458 });
2459 $subMenu_channelsTask->append($menuItem_channelsTask_addException);
2460  
2461 my $menuItem_channelsTask_listPattern = Gtk3::MenuItem->new('_List patterns');
2462 $menuItem_channelsTask_listPattern->signal_connect('activate' => sub {
2463  
2464 $self->winObj->visibleSession->pseudoCmd('listchannelpattern', $mode);
2465 });
2466 $subMenu_channelsTask->append($menuItem_channelsTask_listPattern);
2467  
2468 $subMenu_channelsTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2469  
2470 my $menuItem_channelsTask_emptyWindow = Gtk3::MenuItem->new('Empty Channels _window');
2471 $menuItem_channelsTask_emptyWindow->signal_connect('activate' => sub {
2472  
2473 $self->winObj->visibleSession->pseudoCmd('emptychannelswindow', $mode);
2474 });
2475 $subMenu_channelsTask->append($menuItem_channelsTask_emptyWindow);
2476  
2477 $subMenu_channelsTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2478  
2479 my $menuItem_channelsTask_editTask = Gtk3::ImageMenuItem->new('Edit current _task...');
2480 my $menuImg_channelsTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
2481 $menuItem_channelsTask_editTask->set_image($menuImg_channelsTask_editTask);
2482 $menuItem_channelsTask_editTask->signal_connect('activate' => sub {
2483  
2484 my $session = $self->winObj->visibleSession;
2485  
2486 # Open up a task 'edit' window to edit the task, with the 'main' window as the
2487 # parent
2488 $self->winObj->createFreeWin(
2489 'Games::Axmud::EditWin::Task',
2490 $self->winObj,
2491 $session,
2492 'Edit ' . $session->channelsTask->prettyName . ' task',
2493 $session->channelsTask,
2494 FALSE, # Not temporary
2495 # Config
2496 'edit_flag' => FALSE, # Some IVs for current tasks not editable
2497 );
2498 });
2499 $subMenu_channelsTask->append($menuItem_channelsTask_editTask);
2500  
2501 my $menuItem_channelsTask = Gtk3::MenuItem->new('_Channels task');
2502 $menuItem_channelsTask->set_submenu($subMenu_channelsTask);
2503 $menuColumn_tasks->append($menuItem_channelsTask);
2504 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
2505 # Channels task)
2506 $self->ivAdd('menuItemHash', 'channels_task', $menuItem_channelsTask);
2507  
2508 # 'Chat task' submenu
2509 my $subMenu_chatTask = Gtk3::Menu->new();
2510  
2511 my $menuItem_chatTask_listen = Gtk3::MenuItem->new('_Listen for incoming calls');
2512 $menuItem_chatTask_listen->signal_connect('activate' => sub {
2513  
2514 $self->winObj->visibleSession->pseudoCmd('chatlisten', $mode);
2515 });
2516 $subMenu_chatTask->append($menuItem_chatTask_listen);
2517  
2518 my $menuItem_chatTask_ignore = Gtk3::MenuItem->new('_Ignore incoming calls');
2519 $menuItem_chatTask_ignore->signal_connect('activate' => sub {
2520  
2521 $self->winObj->visibleSession->pseudoCmd('chatignore', $mode);
2522 });
2523 $subMenu_chatTask->append($menuItem_chatTask_ignore);
2524  
2525 $subMenu_chatTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2526  
2527 my $menuItem_chatTask_chatContact = Gtk3::MenuItem->new('_Chat with...');
2528 $menuItem_chatTask_chatContact->signal_connect('activate' => sub {
2529  
2530 my (
2531 $choice,
2532 @comboList,
2533 );
2534  
2535 # Get a sorted list of chat contact names
2536 @comboList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('chatContactHash'));
2537 if (! @comboList) {
2538  
2539 $self->winObj->showMsgDialogue(
2540 'Chat with contact',
2541 'error',
2542 'There is no-one in your contacts list',
2543 'ok',
2544 );
2545  
2546 } else {
2547  
2548 # Prompt the user to choose a chat contact
2549 $choice = $self->winObj->showComboDialogue(
2550 'Select chat contact',
2551 'Select the chat contact to call',
2552 \@comboList,
2553 );
2554  
2555 if ($choice) {
2556  
2557 $self->session->pseudoCmd(
2558 'chatcall ' . $choice,
2559 $mode,
2560 );
2561 }
2562 }
2563 });
2564 $subMenu_chatTask->append($menuItem_chatTask_chatContact);
2565  
2566 my $menuItem_chatTask_chatMM = Gtk3::MenuItem->new('Chat using _MudMaster...');
2567 $menuItem_chatTask_chatMM->signal_connect('activate' => sub {
2568  
2569 my ($host, $port);
2570  
2571 # Prompt the user for a host and port
2572 ($host, $port) = $self->winObj->showDoubleEntryDialogue(
2573 'Chat using MudMaster',
2574 'Enter a DNS/IP address',
2575 '(Optional) enter the port',
2576 );
2577  
2578 if ($host) {
2579  
2580 if (! $port) {
2581  
2582 # (Don't use an empty string as the port)
2583 $self->winObj->visibleSession->pseudoCmd('chatmcall ' . $host, $mode);
2584  
2585 } else {
2586  
2587 $self->winObj->visibleSession->pseudoCmd(
2588 'chatmcall ' . $host . ' ' . $port,
2589 $mode,
2590 );
2591 }
2592 }
2593 });
2594 $subMenu_chatTask->append($menuItem_chatTask_chatMM);
2595  
2596 my $menuItem_chatTask_chatZChat = Gtk3::MenuItem->new('Chat using _zChat...');
2597 $menuItem_chatTask_chatZChat->signal_connect('activate' => sub {
2598  
2599 my ($host, $port);
2600  
2601 # Prompt the user for an address and port
2602 ($host, $port) = $self->winObj->showDoubleEntryDialogue(
2603 'Chat using zChat',
2604 'Enter a DNS/IP address',
2605 '(Optional) enter the port',
2606 );
2607  
2608 if ($host) {
2609  
2610 if (! $port) {
2611  
2612 # (Don't use an empty string as the port)
2613 $self->winObj->visibleSession->pseudoCmd('chatzcall ' . $host, $mode);
2614  
2615 } else {
2616  
2617 $self->winObj->visibleSession->pseudoCmd(
2618 'chatzcall ' . $host . ' ' . $port,
2619 $mode,
2620 );
2621 }
2622 }
2623 });
2624 $subMenu_chatTask->append($menuItem_chatTask_chatZChat);
2625  
2626 $subMenu_chatTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2627  
2628 my $menuItem_chatTask_allowSnoop = Gtk3::MenuItem->new('_Allow everyone to snoop');
2629 $menuItem_chatTask_allowSnoop->signal_connect('activate' => sub {
2630  
2631 $self->winObj->visibleSession->pseudoCmd('chatset -a', $mode);
2632 });
2633 $subMenu_chatTask->append($menuItem_chatTask_allowSnoop);
2634  
2635 my $menuItem_chatTask_forbidSnoop = Gtk3::MenuItem->new('_Forbid all snooping');
2636 $menuItem_chatTask_forbidSnoop->signal_connect('activate' => sub {
2637  
2638 $self->winObj->visibleSession->pseudoCmd('chatset -f', $mode);
2639 });
2640 $subMenu_chatTask->append($menuItem_chatTask_forbidSnoop);
2641  
2642 $subMenu_chatTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2643  
2644 my $menuItem_chatTask_hangUpAll = Gtk3::MenuItem->new('_Hang up on everyone');
2645 $menuItem_chatTask_hangUpAll->signal_connect('activate' => sub {
2646  
2647 $self->winObj->visibleSession->pseudoCmd('chathangup', $mode);
2648 });
2649 $subMenu_chatTask->append($menuItem_chatTask_hangUpAll);
2650  
2651 $subMenu_chatTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2652  
2653 my $menuItem_chatTask_editTask = Gtk3::ImageMenuItem->new('Edit lead chat _task...');
2654 my $menuImg_chatTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
2655 $menuItem_chatTask_editTask->set_image($menuImg_chatTask_editTask);
2656 $menuItem_chatTask_editTask->signal_connect('activate' => sub {
2657  
2658 my $session = $self->winObj->visibleSession;
2659  
2660 # Open up a task 'edit' window to edit the task, with the 'main' window as the
2661 # parent
2662 $self->winObj->createFreeWin(
2663 'Games::Axmud::EditWin::Task',
2664 $self->winObj,
2665 $session,
2666 'Edit ' . $session->chatTask->prettyName . ' task',
2667 $session->chatTask,
2668 FALSE, # Not temporary
2669 # Config
2670 'edit_flag' => FALSE, # Some IVs for current tasks not editable
2671 );
2672 });
2673 $subMenu_chatTask->append($menuItem_chatTask_editTask);
2674 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
2675 # Chat task)
2676 $self->ivAdd('menuItemHash', 'edit_chat_task', $menuItem_chatTask_editTask);
2677  
2678 my $menuItem_chatTask = Gtk3::MenuItem->new('C_hat task');
2679 $menuItem_chatTask->set_submenu($subMenu_chatTask);
2680 $menuColumn_tasks->append($menuItem_chatTask);
2681 # (Requires a visible session whose status is 'connected' or 'offline')
2682 $self->ivAdd('menuItemHash', 'chat_task', $menuItem_chatTask);
2683  
2684 # 'Compass' submenu
2685 my $subMenu_compassTask = Gtk3::Menu->new();
2686  
2687 my $menuItem_compassTask_enableKeypad
2688 = Gtk3::MenuItem->new('_Enable keypad world commands');
2689 $menuItem_compassTask_enableKeypad->signal_connect('activate' => sub {
2690  
2691 $self->winObj->visibleSession->pseudoCmd('compass on', $mode);
2692 });
2693 $subMenu_compassTask->append($menuItem_compassTask_enableKeypad);
2694  
2695 my $menuItem_compassTask_disableKeypad
2696 = Gtk3::MenuItem->new('_Disable keypad world commands');
2697 $menuItem_compassTask_disableKeypad->signal_connect('activate' => sub {
2698  
2699 $self->winObj->visibleSession->pseudoCmd('compass off', $mode);
2700 });
2701 $subMenu_compassTask->append($menuItem_compassTask_disableKeypad);
2702  
2703 $subMenu_compassTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2704  
2705 my $menuItem_compassTask_addPattern = Gtk3::MenuItem->new('_Customise key...');
2706 $menuItem_compassTask_addPattern->signal_connect('activate' => sub {
2707  
2708 my (
2709 $cmd, $keycode,
2710 @comboList,
2711 );
2712  
2713 @comboList = (
2714 'kp_0',
2715 'kp_5',
2716 'kp_divide',
2717 'kp_multiply',
2718 'kp_full_stop',
2719 'kp_enter',
2720 );
2721  
2722 # Prompt the user for a pattern
2723 ($cmd, $keycode) = $self->winObj->showEntryComboDialogue(
2724 'Customise keypad key',
2725 '(Optional) world command',
2726 'Keypad key',
2727 \@comboList,
2728 undef, # No max chars
2729 TRUE, # Put combo above entry box
2730 );
2731  
2732 if (defined $keycode) {
2733  
2734 if (defined $cmd) {
2735  
2736 $self->winObj->visibleSession->pseudoCmd(
2737 'compass ' . $keycode . ' ' . $cmd,
2738 $mode,
2739 );
2740  
2741 } else {
2742  
2743 $self->winObj->visibleSession->pseudoCmd('compass ' . $keycode, $mode);
2744 }
2745 }
2746 });
2747 $subMenu_compassTask->append($menuItem_compassTask_addPattern);
2748  
2749 $subMenu_compassTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2750  
2751 my $menuItem_compassTask_editTask = Gtk3::ImageMenuItem->new('Edit current _task...');
2752 my $menuImg_compassTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
2753 $menuItem_compassTask_editTask->set_image($menuImg_compassTask_editTask);
2754 $menuItem_compassTask_editTask->signal_connect('activate' => sub {
2755  
2756 my $session = $self->winObj->visibleSession;
2757  
2758 # Open up a task 'edit' window to edit the task, with the 'main' window as the
2759 # parent
2760 $self->winObj->createFreeWin(
2761 'Games::Axmud::EditWin::Task',
2762 $self->winObj,
2763 $session,
2764 'Edit ' . $session->compassTask->prettyName . ' task',
2765 $session->compassTask,
2766 FALSE, # Not temporary
2767 # Config
2768 'edit_flag' => FALSE, # Some IVs for current tasks not editable
2769 );
2770 });
2771 $subMenu_compassTask->append($menuItem_compassTask_editTask);
2772  
2773 my $menuItem_compassTask = Gtk3::MenuItem->new('C_ompass task');
2774 $menuItem_compassTask->set_submenu($subMenu_compassTask);
2775 $menuColumn_tasks->append($menuItem_compassTask);
2776 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
2777 # Compass task)
2778 $self->ivAdd('menuItemHash', 'compass_task', $menuItem_compassTask);
2779  
2780 # 'Divert task' submenu
2781 my $subMenu_divertTask = Gtk3::Menu->new();
2782  
2783 my $menuItem_divertTask_addPattern = Gtk3::MenuItem->new('Add _channel pattern...');
2784 $menuItem_divertTask_addPattern->signal_connect('activate' => sub {
2785  
2786 my ($pattern, $channel);
2787  
2788 # Prompt the user for a pattern/channel
2789 ($pattern, $channel) = $self->winObj->showDoubleEntryDialogue(
2790 'Add channel pattern',
2791 'Enter a pattern (regex)',
2792 'Enter a channel (1-16 chars)',
2793 );
2794  
2795 if (defined $pattern && defined $channel) {
2796  
2797 $self->winObj->visibleSession->pseudoCmd(
2798 'addchannelpattern <' . $channel . '> <' . $pattern . '>',
2799 $mode,
2800 );
2801 }
2802 });
2803 $subMenu_divertTask->append($menuItem_divertTask_addPattern);
2804  
2805 my $menuItem_divertTask_addException = Gtk3::MenuItem->new('Add _exception pattern...');
2806 $menuItem_divertTask_addException->signal_connect('activate' => sub {
2807  
2808 # Prompt the user for a pattern
2809 my $pattern = $self->winObj->showEntryDialogue(
2810 'Add exception pattern',
2811 'Enter a pattern (regex)',
2812 );
2813  
2814 if (defined $pattern) {
2815  
2816 $self->winObj->visibleSession->pseudoCmd(
2817 'addchannelpattern -e <' . $pattern . '>',
2818 $mode,
2819 );
2820 }
2821 });
2822 $subMenu_divertTask->append($menuItem_divertTask_addException);
2823  
2824 my $menuItem_divertTask_listPattern = Gtk3::MenuItem->new('_List patterns');
2825 $menuItem_divertTask_listPattern->signal_connect('activate' => sub {
2826  
2827 $self->winObj->visibleSession->pseudoCmd('listchannelpattern', $mode);
2828 });
2829 $subMenu_divertTask->append($menuItem_divertTask_listPattern);
2830  
2831 $subMenu_divertTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2832  
2833 my $menuItem_divertTask_emptyWindow = Gtk3::MenuItem->new('Empty divert _window');
2834 $menuItem_divertTask_emptyWindow->signal_connect('activate' => sub {
2835  
2836 $self->winObj->visibleSession->pseudoCmd('emptydivertwindow', $mode);
2837 });
2838 $subMenu_divertTask->append($menuItem_divertTask_emptyWindow);
2839  
2840 $subMenu_divertTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2841  
2842 my $menuItem_divertTask_editTask = Gtk3::ImageMenuItem->new('Edit current _task...');
2843 my $menuImg_divertTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
2844 $menuItem_divertTask_editTask->set_image($menuImg_divertTask_editTask);
2845 $menuItem_divertTask_editTask->signal_connect('activate' => sub {
2846  
2847 my $session = $self->winObj->visibleSession;
2848  
2849 # Open up a task 'edit' window to edit the task, with the 'main' window as the
2850 # parent
2851 $self->winObj->createFreeWin(
2852 'Games::Axmud::EditWin::Task',
2853 $self->winObj,
2854 $session,
2855 'Edit ' . $session->divertTask->prettyName . ' task',
2856 $session->divertTask,
2857 FALSE, # Not temporary
2858 # Config
2859 'edit_flag' => FALSE, # Some IVs for current tasks not editable
2860 );
2861 });
2862 $subMenu_divertTask->append($menuItem_divertTask_editTask);
2863  
2864 my $menuItem_divertTask = Gtk3::MenuItem->new('_Divert task');
2865 $menuItem_divertTask->set_submenu($subMenu_divertTask);
2866 $menuColumn_tasks->append($menuItem_divertTask);
2867 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
2868 # Divert task)
2869 $self->ivAdd('menuItemHash', 'divert_task', $menuItem_divertTask);
2870  
2871 # 'Inventory/Condition task' submenu
2872 my $subMenu_inventoryTask = Gtk3::Menu->new();
2873  
2874 my $menuItem_inventoryTask_activateTask = Gtk3::MenuItem->new('_Activate task');
2875 $menuItem_inventoryTask_activateTask->signal_connect('activate' => sub {
2876  
2877 $self->winObj->visibleSession->pseudoCmd('activateinventory', $mode);
2878 });
2879 $subMenu_inventoryTask->append($menuItem_inventoryTask_activateTask);
2880  
2881 my $menuItem_inventoryTask_disactivateTask = Gtk3::MenuItem->new('_Disactivate task');
2882 $menuItem_inventoryTask_disactivateTask->signal_connect('activate' => sub {
2883  
2884 $self->winObj->visibleSession->pseudoCmd('disactivateinventory', $mode);
2885 });
2886 $subMenu_inventoryTask->append($menuItem_inventoryTask_disactivateTask);
2887  
2888 $subMenu_inventoryTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2889  
2890 my $menuItem_inventoryTask_sellAll = Gtk3::MenuItem->new('_Sell all');
2891 $menuItem_inventoryTask_sellAll->signal_connect('activate' => sub {
2892  
2893 $self->winObj->visibleSession->pseudoCmd('sellall', $mode);
2894 });
2895 $subMenu_inventoryTask->append($menuItem_inventoryTask_sellAll);
2896  
2897 my $menuItem_inventoryTask_dropAll = Gtk3::MenuItem->new('D_rop all');
2898 $menuItem_inventoryTask_dropAll->signal_connect('activate' => sub {
2899  
2900 $self->winObj->visibleSession->pseudoCmd('dropall', $mode);
2901 });
2902 $subMenu_inventoryTask->append($menuItem_inventoryTask_dropAll);
2903  
2904 $subMenu_inventoryTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2905  
2906 my $menuItem_inventoryTask_editTask = Gtk3::ImageMenuItem->new(
2907 'Edit current _Inventory task...',
2908 );
2909 my $menuImg_inventoryTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
2910 $menuItem_inventoryTask_editTask->set_image($menuImg_inventoryTask_editTask);
2911 $menuItem_inventoryTask_editTask->signal_connect('activate' => sub {
2912  
2913 my $session = $self->winObj->visibleSession;
2914  
2915 # Open up a task 'edit' window to edit the task, with the 'main' window as the
2916 # parent
2917 $self->winObj->createFreeWin(
2918 'Games::Axmud::EditWin::Task',
2919 $self->winObj,
2920 $session,
2921 'Edit ' . $session->inventoryTask->prettyName . ' task',
2922 $session->inventoryTask,
2923 FALSE, # Not temporary
2924 # Config
2925 'edit_flag' => FALSE, # Some IVs for current tasks not editable
2926 );
2927 });
2928 $subMenu_inventoryTask->append($menuItem_inventoryTask_editTask);
2929  
2930 my $menuItem_conditionTask_editTask = Gtk3::ImageMenuItem->new(
2931 'Edit current _Condition task...',
2932 );
2933 my $menuImg_conditionTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
2934 $menuItem_conditionTask_editTask->set_image($menuImg_conditionTask_editTask);
2935 $menuItem_conditionTask_editTask->signal_connect('activate' => sub {
2936  
2937 my $session = $self->winObj->visibleSession;
2938  
2939 # Open up a task 'edit' window to edit the task, with the 'main' window as the
2940 # parent
2941 $self->winObj->createFreeWin(
2942 'Games::Axmud::EditWin::Task',
2943 $self->winObj,
2944 $session,
2945 'Edit ' . $session->conditionTask->prettyName . ' task',
2946 $session->conditionTask,
2947 FALSE, # Not temporary
2948 # Config
2949 'edit_flag' => FALSE, # Some IVs for current tasks not editable
2950 );
2951 });
2952 $subMenu_inventoryTask->append($menuItem_conditionTask_editTask);
2953  
2954 my $menuItem_inventoryTask = Gtk3::MenuItem->new('_Inventory/Condition tasks');
2955 $menuItem_inventoryTask->set_submenu($subMenu_inventoryTask);
2956 $menuColumn_tasks->append($menuItem_inventoryTask);
2957 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
2958 # Inventory task)
2959 $self->ivAdd('menuItemHash', 'inventory_task', $menuItem_inventoryTask);
2960  
2961 # 'Locator task' submenu
2962 my $subMenu_locatorTask = Gtk3::Menu->new();
2963  
2964 my $menuItem_locatorTask_resetTask = Gtk3::MenuItem->new('_Reset task');
2965 $menuItem_locatorTask_resetTask->signal_connect('activate' => sub {
2966  
2967 $self->winObj->visibleSession->pseudoCmd('resetlocatortask', $mode);
2968 });
2969 $subMenu_locatorTask->append($menuItem_locatorTask_resetTask);
2970  
2971 my $menuItem_locatorTask_toggleLocWin = Gtk3::MenuItem->new('Toggle task _window');
2972 $menuItem_locatorTask_toggleLocWin->signal_connect('activate' => sub {
2973  
2974 if ($self->winObj->visibleSession->locatorTask->winObj) {
2975  
2976 $self->winObj->visibleSession->pseudoCmd('closetaskwindow locator', $mode);
2977  
2978 } else {
2979  
2980 $self->winObj->visibleSession->pseudoCmd('opentaskwindow locator', $mode);
2981 }
2982 });
2983 $subMenu_locatorTask->append($menuItem_locatorTask_toggleLocWin);
2984  
2985 $subMenu_locatorTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
2986  
2987 my $menuItem_locatorTask_toggleUnknown
2988 = Gtk3::MenuItem->new('T_oggle unknown word collection');
2989 $menuItem_locatorTask_toggleUnknown->signal_connect('activate' => sub {
2990  
2991 $self->winObj->visibleSession->pseudoCmd('collectunknownwords', $mode);
2992 });
2993 $subMenu_locatorTask->append($menuItem_locatorTask_toggleUnknown);
2994  
2995 my $menuItem_locatorTask_emptyUnknown
2996 = Gtk3::MenuItem->new('_Empty unknown word list');
2997 $menuItem_locatorTask_emptyUnknown->signal_connect('activate' => sub {
2998  
2999 $self->winObj->visibleSession->pseudoCmd('emptyunknownwords', $mode);
3000 });
3001 $subMenu_locatorTask->append($menuItem_locatorTask_emptyUnknown);
3002  
3003 my $menuItem_locatorTask_displayUnknown
3004 = Gtk3::MenuItem->new('_Display unknown word list');
3005 $menuItem_locatorTask_displayUnknown->signal_connect('activate' => sub {
3006  
3007 $self->winObj->visibleSession->pseudoCmd('listunknownwords', $mode);
3008 });
3009 $subMenu_locatorTask->append($menuItem_locatorTask_displayUnknown);
3010  
3011 $subMenu_locatorTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
3012  
3013 my $menuItem_locatorWiz = Gtk3::ImageMenuItem->new('Run _Locator wizard...');
3014 my $menuImg_locatorWiz = Gtk3::Image->new_from_stock('gtk-page-setup', 'menu');
3015 $menuItem_locatorWiz->set_image($menuImg_locatorWiz);
3016 $menuItem_locatorWiz->signal_connect('activate' => sub {
3017  
3018 $self->winObj->visibleSession->pseudoCmd('locatorwizard', $mode);
3019 });
3020 $subMenu_locatorTask->append($menuItem_locatorWiz);
3021 # (Requires a visible session whose status is 'connected' or 'offline'. A
3022 # corresponding menu item also appears in $self->drawEditColumn)
3023 $self->ivAdd('menuItemHash', 'run_locator_wiz_2', $menuItem_locatorWiz);
3024  
3025 $subMenu_locatorTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
3026  
3027 my $menuItem_locatorTask_editTask = Gtk3::ImageMenuItem->new('Edit current _task...');
3028 my $menuImg_locatorTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
3029 $menuItem_locatorTask_editTask->set_image($menuImg_locatorTask_editTask);
3030 $menuItem_locatorTask_editTask->signal_connect('activate' => sub {
3031  
3032 my $session = $self->winObj->visibleSession;
3033  
3034 # Open up a task 'edit' window to edit the task, with the 'main' window as the
3035 # parent
3036 $self->winObj->createFreeWin(
3037 'Games::Axmud::EditWin::Task',
3038 $self->winObj,
3039 $session,
3040 'Edit ' . $session->locatorTask->prettyName . ' task',
3041 $session->locatorTask,
3042 FALSE, # Not temporary
3043 # Config
3044 'edit_flag' => FALSE, # Some IVs for current tasks not editable
3045 );
3046 });
3047 $subMenu_locatorTask->append($menuItem_locatorTask_editTask);
3048  
3049 my $menuItem_locatorTask = Gtk3::MenuItem->new('_Locator task');
3050 $menuItem_locatorTask->set_submenu($subMenu_locatorTask);
3051 $menuColumn_tasks->append($menuItem_locatorTask);
3052 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
3053 # Locator task)
3054 $self->ivAdd('menuItemHash', 'locator_task', $menuItem_locatorTask);
3055  
3056 # 'Status task' submenu
3057 my $subMenu_statusTask = Gtk3::Menu->new();
3058  
3059 my $menuItem_statusTask_activateTask = Gtk3::MenuItem->new('_Activate task');
3060 $menuItem_statusTask_activateTask->signal_connect('activate' => sub {
3061  
3062 $self->winObj->visibleSession->pseudoCmd('activatestatustask', $mode);
3063 });
3064 $subMenu_statusTask->append($menuItem_statusTask_activateTask);
3065  
3066 my $menuItem_statusTask_disactivateTask = Gtk3::MenuItem->new('_Disactivate task');
3067 $menuItem_statusTask_disactivateTask->signal_connect('activate' => sub {
3068  
3069 $self->winObj->visibleSession->pseudoCmd('disactivatestatustask', $mode);
3070 });
3071 $subMenu_statusTask->append($menuItem_statusTask_disactivateTask);
3072  
3073 my $menuItem_statusTask_resetCounters = Gtk3::MenuItem->new('_Reset all counters');
3074 $menuItem_statusTask_resetCounters->signal_connect('activate' => sub {
3075  
3076 $self->winObj->visibleSession->pseudoCmd('resetcounter', $mode);
3077 });
3078 $subMenu_statusTask->append($menuItem_statusTask_resetCounters);
3079  
3080 $subMenu_statusTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
3081  
3082 # 'Gauges' submenu
3083 my $subMenu_gauges = Gtk3::Menu->new();
3084  
3085 my $menuItem_statusTask_toggleStatWin = Gtk3::MenuItem->new('Toggle task _window');
3086 $menuItem_statusTask_toggleStatWin->signal_connect('activate' => sub {
3087  
3088 if ($self->winObj->visibleSession->statusTask->winObj) {
3089  
3090 $self->winObj->visibleSession->pseudoCmd('closetaskwindow status', $mode);
3091  
3092 } else {
3093  
3094 $self->winObj->visibleSession->pseudoCmd('opentaskwindow status', $mode);
3095 }
3096 });
3097 $subMenu_gauges->append($menuItem_statusTask_toggleStatWin);
3098  
3099 my $menuItem_statusTask_showGauge = Gtk3::MenuItem->new('Toggle _gauges');
3100 $menuItem_statusTask_showGauge->signal_connect('activate' => sub {
3101  
3102 $self->winObj->visibleSession->pseudoCmd('showstatusgauge', $mode);
3103 });
3104 $subMenu_gauges->append($menuItem_statusTask_showGauge);
3105  
3106 my $menuItem_statusTask_showGaugeLabel = Gtk3::MenuItem->new('Toggle gauge _labels');
3107 $menuItem_statusTask_showGaugeLabel->signal_connect('activate' => sub {
3108  
3109 $self->winObj->visibleSession->pseudoCmd('showstatusgauge -l', $mode);
3110 });
3111 $subMenu_gauges->append($menuItem_statusTask_showGaugeLabel);
3112  
3113 my $menuItem_gauges = Gtk3::MenuItem->new('D_isplay');
3114 $menuItem_gauges->set_submenu($subMenu_gauges);
3115 $subMenu_statusTask->append($menuItem_gauges);
3116  
3117 $subMenu_statusTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
3118  
3119 my $menuItem_statusTask_editTask = Gtk3::ImageMenuItem->new('Edit current _task...');
3120 my $menuImg_statusTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
3121 $menuItem_statusTask_editTask->set_image($menuImg_statusTask_editTask);
3122 $menuItem_statusTask_editTask->signal_connect('activate' => sub {
3123  
3124 my $session = $self->winObj->visibleSession;
3125  
3126 # Open up a task 'edit' window to edit the task, with the 'main' window as the
3127 # parent
3128 $self->winObj->createFreeWin(
3129 'Games::Axmud::EditWin::Task',
3130 $self->winObj,
3131 $session,
3132 'Edit ' . $session->statusTask->prettyName . ' task',
3133 $session->statusTask,
3134 FALSE, # Not temporary
3135 # Config
3136 'edit_flag' => FALSE, # Some IVs for current tasks not editable
3137 );
3138 });
3139 $subMenu_statusTask->append($menuItem_statusTask_editTask);
3140  
3141 my $menuItem_statusTask = Gtk3::MenuItem->new('_Status task');
3142 $menuItem_statusTask->set_submenu($subMenu_statusTask);
3143 $menuColumn_tasks->append($menuItem_statusTask);
3144 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
3145 # Status task)
3146 $self->ivAdd('menuItemHash', 'status_task', $menuItem_statusTask);
3147  
3148 # 'Watch' submenu
3149 my $subMenu_watchTask = Gtk3::Menu->new();
3150  
3151 my $menuItem_watchTask_emptyWindow = Gtk3::MenuItem->new('Empty watch _window');
3152 $menuItem_watchTask_emptyWindow->signal_connect('activate' => sub {
3153  
3154 $self->winObj->visibleSession->pseudoCmd('emptywatchwindow', $mode);
3155 });
3156 $subMenu_watchTask->append($menuItem_watchTask_emptyWindow);
3157  
3158 $subMenu_watchTask->append(Gtk3::SeparatorMenuItem->new()); # Separator
3159  
3160 my $menuItem_watchTask_editTask = Gtk3::ImageMenuItem->new('Edit current _task...');
3161 my $menuImg_watchTask_editTask = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
3162 $menuItem_watchTask_editTask->set_image($menuImg_watchTask_editTask);
3163 $menuItem_watchTask_editTask->signal_connect('activate' => sub {
3164  
3165 my $session = $self->winObj->visibleSession;
3166  
3167 # Open up a task 'edit' window to edit the task, with the 'main' window as the
3168 # parent
3169 $self->winObj->createFreeWin(
3170 'Games::Axmud::EditWin::Task',
3171 $self->winObj,
3172 $session,
3173 'Edit ' . $session->watchTask->prettyName . ' task',
3174 $session->watchTask,
3175 FALSE, # Not temporary
3176 # Config
3177 'edit_flag' => FALSE, # Some IVs for current tasks not editable
3178 );
3179 });
3180 $subMenu_watchTask->append($menuItem_watchTask_editTask);
3181  
3182 my $menuItem_watchTask = Gtk3::MenuItem->new('_Watch task');
3183 $menuItem_watchTask->set_submenu($subMenu_watchTask);
3184 $menuColumn_tasks->append($menuItem_watchTask);
3185 # (Requires a visible session whose status is 'connected' or 'offline' and is running a
3186 # Watch task)
3187 $self->ivAdd('menuItemHash', 'watch_task', $menuItem_watchTask);
3188  
3189 # Setup complete
3190 return $menuColumn_tasks;
3191 }
3192  
3193 sub drawDisplayColumn {
3194  
3195 # Called by $self->enableMenu
3196 # Sets up the menu's 'Display' column
3197 #
3198 # Expected arguments
3199 # (none besides $self)
3200 #
3201 # Return values
3202 # 'undef' on improper arguments, or if the menu can't be created
3203 # Otherwise returns the Gtk3::Menu created
3204  
3205 my ($self, $check) = @_;
3206  
3207 # Local variables
3208 my $mode;
3209  
3210 # Check for improper arguments
3211 if (defined $check) {
3212  
3213 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawDisplayColumn', @_);
3214 }
3215  
3216 # Import IVs (for convenience)
3217 $mode = $self->winObj->pseudoCmdMode;
3218  
3219 # Set up column
3220 my $menuColumn_display = Gtk3::Menu->new();
3221 if (! $menuColumn_display) {
3222  
3223 return undef;
3224 }
3225  
3226 my $menuItem_openAutomapper = Gtk3::ImageMenuItem->new('Open _automapper');
3227 my $menuImg_openAutomapper = Gtk3::Image->new_from_stock('gtk-jump-to', 'menu');
3228 $menuItem_openAutomapper->set_image($menuImg_openAutomapper);
3229 $menuItem_openAutomapper->signal_connect('activate' => sub {
3230  
3231 $self->winObj->visibleSession->pseudoCmd('openautomapper', $mode);
3232 });
3233 $menuColumn_display->append($menuItem_openAutomapper);
3234 # (Requires a visible session whose status is 'connected' or 'offline')
3235 $self->ivAdd('menuItemHash', 'open_automapper', $menuItem_openAutomapper);
3236  
3237 my $menuItem_openViewer = Gtk3::ImageMenuItem->new('Open object _viewer');
3238 my $menuImg_openViewer = Gtk3::Image->new_from_stock('gtk-jump-to', 'menu');
3239 $menuItem_openViewer->set_image($menuImg_openViewer);
3240 $menuItem_openViewer->signal_connect('activate' => sub {
3241  
3242 $self->winObj->visibleSession->pseudoCmd('opendataviewer', $mode);
3243 });
3244 $menuColumn_display->append($menuItem_openViewer);
3245 # (Requires a visible session whose status is 'connected' or 'offline')
3246 $self->ivAdd('menuItemHash', 'open_object_viewer', $menuItem_openViewer);
3247  
3248 $menuColumn_display->append(Gtk3::SeparatorMenuItem->new()); # Separator
3249  
3250 # 'Current layer' submenu
3251 my $subMenu_currentLayer = Gtk3::Menu->new();
3252  
3253 my $menuItem_currentLayer_moveUp = Gtk3::MenuItem->new('Move _up');
3254 $menuItem_currentLayer_moveUp->signal_connect('activate' => sub {
3255  
3256 $self->winObj->visibleSession->pseudoCmd('layerup', $mode);
3257 });
3258 $subMenu_currentLayer->append($menuItem_currentLayer_moveUp);
3259  
3260 my $menuItem_currentLayer_moveDown = Gtk3::MenuItem->new('Move _down');
3261 $menuItem_currentLayer_moveDown->signal_connect('activate' => sub {
3262  
3263 $self->winObj->visibleSession->pseudoCmd('layerdown', $mode);
3264 });
3265 $subMenu_currentLayer->append($menuItem_currentLayer_moveDown);
3266  
3267 $subMenu_currentLayer->append(Gtk3::SeparatorMenuItem->new()); # Separator
3268  
3269 my $menuItem_currentLayer_moveTop = Gtk3::MenuItem->new('Move to _top');
3270 $menuItem_currentLayer_moveTop->signal_connect('activate' => sub {
3271  
3272 # Get the workspace grid object used by the visible session; can't rely on
3273 # $self->workspaceGridObj because 'main' windows might appear on several
3274 # workspaces
3275 my $gridObj
3276 = $self->winObj->workspaceObj->findWorkspaceGrid($self->visibleSession);
3277  
3278 if ($gridObj) {
3279  
3280 $self->winObj->visibleSession->pseudoCmd(
3281 'setlayer ' . ($gridObj->maxLayers - 1),
3282 $mode,
3283 );
3284 }
3285 });
3286 $subMenu_currentLayer->append($menuItem_currentLayer_moveTop);
3287  
3288 my $menuItem_currentLayer_moveBottom = Gtk3::MenuItem->new('Move to _bottom');
3289 $menuItem_currentLayer_moveBottom->signal_connect('activate' => sub {
3290  
3291 $self->winObj->visibleSession->pseudoCmd('setlayer 0', $mode);
3292 });
3293 $subMenu_currentLayer->append($menuItem_currentLayer_moveBottom);
3294  
3295 $subMenu_currentLayer->append(Gtk3::SeparatorMenuItem->new()); # Separator
3296  
3297 my $menuItem_currentLayer_setLayer = Gtk3::MenuItem->new('_Set layer...');
3298 $menuItem_currentLayer_setLayer->signal_connect('activate' => sub {
3299  
3300 my ($gridObj, $result);
3301  
3302 $gridObj = $self->winObj->workspaceObj->findWorkspaceGrid($self->visibleSession);
3303  
3304 if ($gridObj) {
3305  
3306 # Display a dialogue to choose the new layer
3307 $result = $self->winObj->showEntryDialogue(
3308 'Set layer',
3309 'Enter the new layer (in the range 0-' . ($gridObj->maxLayers - 1) . ')',
3310 );
3311  
3312 if ($result) {
3313  
3314 # Set the layer
3315 $self->winObj->visibleSession->pseudoCmd('setlayer ' . $result, $mode);
3316 }
3317 }
3318 });
3319 $subMenu_currentLayer->append($menuItem_currentLayer_setLayer);
3320  
3321 my $menuItem_currentLayer = Gtk3::MenuItem->new('Current _layer');
3322 $menuItem_currentLayer->set_submenu($subMenu_currentLayer);
3323 $menuColumn_display->append($menuItem_currentLayer);
3324 # (Requires a visible session whose status is 'connected' or 'offline')
3325 $self->ivAdd('menuItemHash', 'current_layer', $menuItem_currentLayer);
3326  
3327 # 'Window storage' submenu
3328 my $subMenu_windowStorage = Gtk3::Menu->new();
3329  
3330 my $menuItem_autoStore
3331 = Gtk3::CheckMenuItem->new('_Automatically store sizes/positions');
3332 $menuItem_autoStore->signal_connect('toggled' => sub {
3333  
3334 $self->winObj->visibleSession->pseudoCmd('togglewindowstorage', $mode);
3335 });
3336 $subMenu_windowStorage->append($menuItem_autoStore);
3337  
3338 my $menuItem_storeCurrent = Gtk3::MenuItem->new('_Store current sizes/positions');
3339 $menuItem_storeCurrent->signal_connect('activate' => sub {
3340  
3341 $self->winObj->visibleSession->pseudoCmd('applywindowstorage', $mode);
3342 });
3343 $subMenu_windowStorage->append($menuItem_storeCurrent);
3344  
3345 $subMenu_windowStorage->append(Gtk3::SeparatorMenuItem->new()); # Separator
3346  
3347 my $menuItem_resetStorage = Gtk3::MenuItem->new('_Clear stored sizes/positions');
3348 $menuItem_resetStorage->signal_connect('activate' => sub {
3349  
3350 $self->winObj->visibleSession->pseudoCmd('clearwindowstorage', $mode);
3351 });
3352 $subMenu_windowStorage->append($menuItem_resetStorage);
3353  
3354 my $menuItem_windowStorage = Gtk3::MenuItem->new('\'Grid\' _window storage');
3355 $menuItem_windowStorage->set_submenu($subMenu_windowStorage);
3356 $menuColumn_display->append($menuItem_windowStorage);
3357 # (Requires a visible session whose status is 'connected' or 'offline')
3358 $self->ivAdd('menuItemHash', 'window_storage', $menuItem_windowStorage);
3359  
3360 $menuColumn_display->append(Gtk3::SeparatorMenuItem->new()); # Separator
3361  
3362 my $menuItem_testControls = Gtk3::MenuItem->new('_Test window controls');
3363 $menuItem_testControls->signal_connect('activate' => sub {
3364  
3365 $self->winObj->visibleSession->pseudoCmd('testwindowcontrols', $mode);
3366 });
3367 $menuColumn_display->append($menuItem_testControls);
3368 # (Requires a visible session whose status is 'connected' or 'offline')
3369 $self->ivAdd('menuItemHash', 'test_controls', $menuItem_testControls);
3370  
3371 my $menuItem_testPanels = Gtk3::MenuItem->new('T_est panels');
3372 $menuItem_testPanels->signal_connect('activate' => sub {
3373  
3374 $self->winObj->visibleSession->pseudoCmd('testpanel', $mode);
3375 });
3376 $menuColumn_display->append($menuItem_testPanels);
3377 # (Requires a visible session whose status is 'connected' or 'offline')
3378 $self->ivAdd('menuItemHash', 'test_panels', $menuItem_testPanels);
3379  
3380 # Setup complete
3381 return $menuColumn_display;
3382 }
3383  
3384 sub drawCommandsColumn {
3385  
3386 # Called by $self->enableMenu
3387 # Sets up the menu's 'Commands' column
3388 #
3389 # Expected arguments
3390 # (none besides $self)
3391 #
3392 # Return values
3393 # 'undef' on improper arguments, or if the menu can't be created
3394 # Otherwise returns the Gtk3::Menu created
3395  
3396 my ($self, $check) = @_;
3397  
3398 # Local variables
3399 my $mode;
3400  
3401 # Check for improper arguments
3402 if (defined $check) {
3403  
3404 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawCommandsColumn', @_);
3405 }
3406  
3407 # Import IVs (for convenience)
3408 $mode = $self->winObj->pseudoCmdMode;
3409  
3410 # Set up column
3411 my $menuColumn_commands = Gtk3::Menu->new();
3412 if (! $menuColumn_commands) {
3413  
3414 return undef;
3415 }
3416  
3417 my $menuItem_repeat = Gtk3::ImageMenuItem->new('_Repeat...');
3418 my $menuImg_repeat = Gtk3::Image->new_from_stock('gtk-redo', 'menu');
3419 $menuItem_repeat->set_image($menuImg_repeat);
3420 $menuItem_repeat->signal_connect('activate' => sub {
3421  
3422 # Display a 'dialogue' window so the user can choose the command to repeat, and how
3423 # often
3424 my ($cmd, $number);
3425  
3426 # Display the dialogue
3427 ($cmd, $number) = $self->winObj->showDoubleEntryDialogue(
3428 'Repeat command',
3429 'Enter a world command to repeat',
3430 'Enter how often to repeat it',
3431 );
3432  
3433 if ($cmd && $number) {
3434  
3435 # Issue the command
3436 $self->winObj->visibleSession->pseudoCmd('repeat ' . $number . ' ' . $cmd, $mode);
3437 }
3438 });
3439 $menuColumn_commands->append($menuItem_repeat);
3440 # (Requires a visible session whose status is 'connected' or 'offline')
3441 $self->ivAdd('menuItemHash', 'repeat_cmd', $menuItem_repeat);
3442  
3443 my $menuItem_repeatSecond = Gtk3::ImageMenuItem->new('Repeat each _second...');
3444 my $menuImg_repeatSecond = Gtk3::Image->new_from_stock('gtk-redo', 'menu');
3445 $menuItem_repeatSecond->set_image($menuImg_repeatSecond);
3446 $menuItem_repeatSecond->signal_connect('activate' => sub {
3447  
3448 # Display a 'dialogue' window so the user can choose the command to repeat, and how
3449 # often
3450 my ($cmd, $number);
3451  
3452 # Display the dialogue
3453 ($cmd, $number) = $self->winObj->showDoubleEntryDialogue(
3454 'Repeat command',
3455 'Enter a world command to repeat once a second',
3456 'Enter how often to repeat it',
3457 );
3458  
3459 if ($cmd && $number) {
3460  
3461 # Issue the command
3462 $self->winObj->visibleSession->pseudoCmd(
3463 'intervalrepeat ' . $number . ' 1 ' . $cmd,
3464 $mode,
3465 );
3466 }
3467 });
3468 $menuColumn_commands->append($menuItem_repeatSecond);
3469 # (Requires a visible session whose status is 'connected' or 'offline')
3470 $self->ivAdd('menuItemHash', 'repeat_second', $menuItem_repeatSecond);
3471  
3472 my $menuItem_repeatInterval = Gtk3::ImageMenuItem->new('Repeat at _intervals...');
3473 my $menuImg_repeatInterval = Gtk3::Image->new_from_stock('gtk-redo', 'menu');
3474 $menuItem_repeatInterval->set_image($menuImg_repeatInterval);
3475 $menuItem_repeatInterval->signal_connect('activate' => sub {
3476  
3477 # Display a 'dialogue' window so the user can choose the command to repeat, and how
3478 # often
3479 my ($cmd, $number, $interval);
3480  
3481 # Display the dialogue
3482 ($cmd, $number) = $self->winObj->showDoubleEntryDialogue(
3483 'Repeat command',
3484 'Enter a world command to repeat',
3485 'Enter how often to repeat it',
3486 );
3487  
3488 if ($cmd && $number) {
3489  
3490 # Display a second dialogue to get the interval
3491 $interval = $self->winObj->showEntryDialogue(
3492 'Repeat command',
3493 'Enter an interval (in seconds) between repetitions',
3494 );
3495  
3496 if ($interval) {
3497  
3498 # Issue the command
3499 $self->winObj->visibleSession->pseudoCmd(
3500 'intervalrepeat ' . $number . ' ' . $interval . ' ' . $cmd,
3501 $mode,
3502 );
3503 }
3504 }
3505 });
3506 $menuColumn_commands->append($menuItem_repeatInterval);
3507 # (Requires a visible session whose status is 'connected' or 'offline')
3508 $self->ivAdd('menuItemHash', 'repeat_interval', $menuItem_repeatInterval);
3509  
3510 $menuColumn_commands->append(Gtk3::SeparatorMenuItem->new()); # Separator
3511  
3512 my $menuItem_cancelRepeat = Gtk3::ImageMenuItem->new('_Cancel repeating commands');
3513 my $menuImg_cancelRepeat = Gtk3::Image->new_from_stock('gtk-cancel', 'menu');
3514 $menuItem_cancelRepeat->set_image($menuImg_cancelRepeat);
3515 $menuItem_cancelRepeat->signal_connect('activate' => sub {
3516  
3517 $self->winObj->visibleSession->pseudoCmd('stopcommand', $mode);
3518 });
3519 $menuColumn_commands->append($menuItem_cancelRepeat);
3520 # (Requires a visible session whose status is 'connected' or 'offline')
3521 $self->ivAdd('menuItemHash', 'cancel_repeat', $menuItem_cancelRepeat);
3522  
3523 # Setup complete
3524 return $menuColumn_commands;
3525 }
3526  
3527 sub drawRecordingsColumn {
3528  
3529 # Called by $self->enableMenu
3530 # Sets up the menu's 'Recordings' column
3531 #
3532 # Expected arguments
3533 # (none besides $self)
3534 #
3535 # Return values
3536 # 'undef' on improper arguments, or if the menu can't be created
3537 # Otherwise returns the Gtk3::Menu created
3538  
3539 my ($self, $check) = @_;
3540  
3541 # Local variables
3542 my $mode;
3543  
3544 # Check for improper arguments
3545 if (defined $check) {
3546  
3547 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawRecordingsColumn', @_);
3548 }
3549  
3550 # Import IVs (for convenience)
3551 $mode = $self->winObj->pseudoCmdMode;
3552  
3553 # Set up column
3554 my $menuColumn_recordings = Gtk3::Menu->new();
3555 if (! $menuColumn_recordings) {
3556  
3557 return undef;
3558 }
3559  
3560 my $menuItem_startStop = Gtk3::ImageMenuItem->new('_Start/stop recording');
3561 my $menuImg_startStop = Gtk3::Image->new_from_stock('gtk-media-record', 'menu');
3562 $menuItem_startStop->set_image($menuImg_startStop);
3563 $menuItem_startStop->signal_connect('activate' => sub {
3564  
3565 $self->winObj->visibleSession->pseudoCmd('record', $mode);
3566 });
3567 $menuColumn_recordings->append($menuItem_startStop);
3568 # (Requires a visible session whose status is 'connected' or 'offline', and
3569 # GA::Session->recordingPausedFlag set to FALSE)
3570 $self->ivAdd('menuItemHash', 'start_stop_recording', $menuItem_startStop);
3571  
3572 my $menuItem_pauseResume = Gtk3::ImageMenuItem->new('_Pause/resume recording');
3573 my $menuImg_pauseResume = Gtk3::Image->new_from_stock('gtk-media-pause', 'menu');
3574 $menuItem_pauseResume->set_image($menuImg_pauseResume);
3575 $menuItem_pauseResume->signal_connect('activate' => sub {
3576  
3577 $self->winObj->visibleSession->pseudoCmd('pauserecording', $mode);
3578 });
3579 $menuColumn_recordings->append($menuItem_pauseResume);
3580 # (Requires a visible session whose status is 'connected' or 'offline', and
3581 # GA::Session->recordingFlag set to TRUE)
3582 $self->ivAdd('menuItemHash', 'pause_recording', $menuItem_pauseResume);
3583  
3584 $menuColumn_recordings->append(Gtk3::SeparatorMenuItem->new()); # Separator
3585  
3586 # 'Add line' submenu
3587 my $subMenu_addLine = Gtk3::Menu->new();
3588  
3589 my $menuItem_addWorldCmd = Gtk3::MenuItem->new('Add _world command...');
3590 $menuItem_addWorldCmd->signal_connect('activate' => sub {
3591  
3592 # Display a 'dialogue' window, so the user can choose the command to add
3593 my $text = $self->winObj->showEntryDialogue(
3594 'Recording',
3595 'Enter a world command to add at this point in the recording',
3596 );
3597  
3598 if ($text) {
3599  
3600 # Add the world command
3601 $self->winObj->visibleSession->pseudoCmd(
3602 'worldcommand <' . $text . '>',
3603 $mode,
3604 );
3605 }
3606 });
3607 $subMenu_addLine->append($menuItem_addWorldCmd);
3608  
3609 my $menuItem_addClientCmd = Gtk3::MenuItem->new('Add _client command...');
3610 $menuItem_addClientCmd->signal_connect('activate' => sub {
3611  
3612 # Display a 'dialogue' window, so the user can choose the command to add
3613 my $text = $self->winObj->showEntryDialogue(
3614 'Recording',
3615 'Enter a client command to add at this point in the recording',
3616 );
3617  
3618 if ($text) {
3619  
3620 # Add the client command
3621 $self->winObj->visibleSession->pseudoCmd(
3622 'clientcommand <' . $text . '>',
3623 $mode,
3624 );
3625 }
3626 });
3627 $subMenu_addLine->append($menuItem_addClientCmd);
3628  
3629 my $menuItem_addComment = Gtk3::MenuItem->new('Add co_mment...');
3630 $menuItem_addComment->signal_connect('activate' => sub {
3631  
3632 # Display a 'dialogue' window, so the user can choose the comment to add
3633 my $text = $self->winObj->showEntryDialogue(
3634 'Recording',
3635 'Enter a comment to add at this point in the recording',
3636 );
3637  
3638 if ($text) {
3639  
3640 # Add the comment
3641 $self->winObj->visibleSession->pseudoCmd(
3642 'comment <' . $text . '>',
3643 $mode,
3644 );
3645 }
3646 });
3647 $subMenu_addLine->append($menuItem_addComment);
3648  
3649 my $menuItem_addLine = Gtk3::MenuItem->new('Add _line');
3650 $menuItem_addLine->set_submenu($subMenu_addLine);
3651 $menuColumn_recordings->append($menuItem_addLine);
3652 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3653 # whose ->recordingFlag set to TRUE)
3654 $self->ivAdd('menuItemHash', 'recording_add_line', $menuItem_addLine);
3655  
3656 # 'Add break' submenu
3657 my $subMenu_addBreak = Gtk3::Menu->new();
3658  
3659 my $menuItem_ordinaryBreak = Gtk3::MenuItem->new('Add _ordinary break');
3660 $menuItem_ordinaryBreak->signal_connect('activate' => sub {
3661  
3662 $self->winObj->visibleSession->pseudoCmd('break', $mode);
3663 });
3664 $subMenu_addBreak->append($menuItem_ordinaryBreak);
3665  
3666 my $menuItem_triggerBreak = Gtk3::MenuItem->new('Add _trigger break...');
3667 $menuItem_triggerBreak->signal_connect('activate' => sub {
3668  
3669 # Display a 'dialogue' window, so the user can choose the trigger pattern to add
3670 my $text = $self->winObj->showEntryDialogue(
3671 'Recording',
3672 'Enter a trigger pattern to add at this point in the recording',
3673 );
3674  
3675 if ($text) {
3676  
3677 # Add the trigger break
3678 $self->winObj->visibleSession->pseudoCmd('break -t ' . $text, $mode);
3679 }
3680 });
3681 $subMenu_addBreak->append($menuItem_triggerBreak);
3682  
3683 my $menuItem_pauseBreak = Gtk3::MenuItem->new('Add _pause break...');
3684 $menuItem_pauseBreak->signal_connect('activate' => sub {
3685  
3686 # Display a 'dialogue' window, so the user can choose the pause interval to add
3687 my $text = $self->winObj->showEntryDialogue(
3688 'Recording',
3689 'Enter the length of the pause break to add at this point in the recording',
3690 );
3691  
3692 if ($text) {
3693  
3694 # Add the pause break
3695 $self->winObj->visibleSession->pseudoCmd('break -p ' . $text, $mode);
3696 }
3697 });
3698 $subMenu_addBreak->append($menuItem_pauseBreak);
3699  
3700 my $menuItem_locatorBreak = Gtk3::MenuItem->new('Add _Locator task break');
3701 $menuItem_locatorBreak->signal_connect('activate' => sub {
3702  
3703 $self->winObj->visibleSession->pseudoCmd('break -l', $mode);
3704 });
3705 $subMenu_addBreak->append($menuItem_locatorBreak);
3706  
3707 my $menuItem_addBreak = Gtk3::MenuItem->new('Add _break');
3708 $menuItem_addBreak->set_submenu($subMenu_addBreak);
3709 $menuColumn_recordings->append($menuItem_addBreak);
3710 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3711 # whose ->recordingFlag set to TRUE)
3712 $self->ivAdd('menuItemHash', 'recording_add_break', $menuItem_addBreak);
3713  
3714 $menuColumn_recordings->append(Gtk3::SeparatorMenuItem->new()); # Separator
3715  
3716 my $menuItem_insertPoint = Gtk3::MenuItem->new('Set _insertion point...');
3717 $menuItem_insertPoint->signal_connect('activate' => sub {
3718  
3719 # Display a 'dialogue' window, so the user can choose the insertion point
3720 my $text = $self->winObj->showEntryDialogue(
3721 'Recording',
3722 'Enter the line number at which to continue the recording',
3723 );
3724  
3725 if ($text) {
3726  
3727 # Set the insertion point
3728 $self->winObj->visibleSession->pseudoCmd('insertrecording ' . $text, $mode);
3729 }
3730 });
3731 $menuColumn_recordings->append($menuItem_insertPoint);
3732 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3733 # whose ->recordingFlag set to TRUE)
3734 $self->ivAdd('menuItemHash', 'recording_set_insertion', $menuItem_insertPoint);
3735  
3736 my $menuItem_cancelInsert = Gtk3::MenuItem->new('_Cancel insertion point');
3737 $menuItem_cancelInsert->signal_connect('activate' => sub {
3738  
3739 $self->winObj->visibleSession->pseudoCmd('insertrecording', $mode);
3740 });
3741 $menuColumn_recordings->append($menuItem_cancelInsert);
3742 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3743 # whose ->recordingFlag set to TRUE)
3744 $self->ivAdd('menuItemHash', 'recording_cancel_insertion', $menuItem_cancelInsert);
3745  
3746 $menuColumn_recordings->append(Gtk3::SeparatorMenuItem->new()); # Separator
3747  
3748 my $menuItem_deleteLine = Gtk3::MenuItem->new('_Delete line...');
3749 $menuItem_deleteLine->signal_connect('activate' => sub {
3750  
3751 # Display a 'dialogue' window, so the user can choose the line to delete
3752 my $text = $self->winObj->showEntryDialogue(
3753 'Recording',
3754 'Enter the number of the line to delete',
3755 );
3756  
3757 if ($text) {
3758  
3759 # Delete the line
3760 $self->winObj->visibleSession->pseudoCmd('deleterecording ' . $text, $mode);
3761 }
3762 });
3763 $menuColumn_recordings->append($menuItem_deleteLine);
3764 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3765 # whose ->recordingFlag set to TRUE)
3766 $self->ivAdd('menuItemHash', 'recording_delete_line', $menuItem_deleteLine);
3767  
3768 my $menuItem_deleteMulti = Gtk3::MenuItem->new('D_elete lines...');
3769 $menuItem_deleteMulti->signal_connect('activate' => sub {
3770  
3771 # Display a 'dialogue' window, so the user can choose the lines to delete
3772 my ($start, $stop) = $self->winObj->showDoubleEntryDialogue(
3773 'Recording',
3774 'Enter the number of the first line to be deleted',
3775 'Enter the number of the last line to be deleted',
3776 );
3777  
3778 if (defined $start && defined $stop) {
3779  
3780 # Delete the line
3781 $self->winObj->visibleSession->pseudoCmd(
3782 'deleterecording ' . $start . ' ' . $stop,
3783 $mode,
3784 );
3785 }
3786 });
3787 $menuColumn_recordings->append($menuItem_deleteMulti);
3788 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3789 # whose ->recordingFlag set to TRUE)
3790 $self->ivAdd('menuItemHash', 'recording_delete_multi', $menuItem_deleteMulti);
3791  
3792 my $menuItem_deleteLast = Gtk3::MenuItem->new('Delete l_ast line');
3793 $menuItem_deleteLast->signal_connect('activate' => sub {
3794  
3795 $self->winObj->visibleSession->pseudoCmd('deleterecording', $mode);
3796  
3797 });
3798 $menuColumn_recordings->append($menuItem_deleteLast);
3799 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3800 # whose ->recordingFlag set to TRUE)
3801 $self->ivAdd('menuItemHash', 'recording_delete_last', $menuItem_deleteLast);
3802  
3803 $menuColumn_recordings->append(Gtk3::SeparatorMenuItem->new()); # Separator
3804  
3805 my $menuItem_showRecording = Gtk3::MenuItem->new('S_how recording');
3806 $menuItem_showRecording->signal_connect('activate' => sub {
3807  
3808 $self->winObj->visibleSession->pseudoCmd('listrecording', $mode);
3809 });
3810 $menuColumn_recordings->append($menuItem_showRecording);
3811 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3812 # whose ->recordingFlag set to TRUE or whose ->recordingList is not empty)
3813 $self->ivAdd('menuItemHash', 'show_recording', $menuItem_showRecording);
3814  
3815 my $menuItem_copyRecording = Gtk3::MenuItem->new('C_opy recording');
3816 $menuItem_copyRecording->signal_connect('activate' => sub {
3817  
3818 $self->winObj->visibleSession->pseudoCmd('copyrecording', $mode);
3819 });
3820 $menuColumn_recordings->append($menuItem_copyRecording);
3821 # (Requires a visible session whose status is 'connected' or 'offline' and a visible session
3822 # whose ->recordingFlag set to TRUE or whose ->recordingList is not empty)
3823 $self->ivAdd('menuItemHash', 'copy_recording', $menuItem_copyRecording);
3824  
3825 # Setup complete
3826 return $menuColumn_recordings;
3827 }
3828  
3829 sub drawAxbasicColumn {
3830  
3831 # Called by $self->enableMenu
3832 # Sets up the menu's 'Axbasic' column
3833 #
3834 # Expected arguments
3835 # (none besides $self)
3836 #
3837 # Return values
3838 # 'undef' on improper arguments, or if the menu can't be created
3839 # Otherwise returns the Gtk3::Menu created
3840  
3841 my ($self, $check) = @_;
3842  
3843 # Local variables
3844 my $mode;
3845  
3846 # Check for improper arguments
3847 if (defined $check) {
3848  
3849 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawAxbasicColumn', @_);
3850 }
3851  
3852 # Import IVs (for convenience)
3853 $mode = $self->winObj->pseudoCmdMode;
3854  
3855 # Set up column
3856 my $menuColumn_basic = Gtk3::Menu->new();
3857 if (! $menuColumn_basic) {
3858  
3859 return undef;
3860 }
3861  
3862 my $menuItem_runScript = Gtk3::ImageMenuItem->new('_Run script...');
3863 my $menuImg_runScript = Gtk3::Image->new_from_stock('gtk-execute', 'menu');
3864 $menuItem_runScript->set_image($menuImg_runScript);
3865 $menuItem_runScript->signal_connect('activate' => sub {
3866  
3867 # Display a 'dialogue' window, so the user can choose the script to run
3868 my $text = $self->winObj->showEntryDialogue(
3869 'Run ' . $axmud::BASIC_NAME . ' script',
3870 'Enter the script to run (e.g. \'wumpus\')',
3871 );
3872  
3873 if ($text) {
3874  
3875 # Run the script
3876 $self->winObj->visibleSession->pseudoCmd('runscript ' . $text, $mode);
3877 }
3878 });
3879 $menuColumn_basic->append($menuItem_runScript);
3880 # (Requires a visible session whose status is 'connected' or 'offline')
3881 $self->ivAdd('menuItemHash', 'run_script', $menuItem_runScript);
3882  
3883 my $menuItem_runScriptTask = Gtk3::ImageMenuItem->new('Run script as _task...');
3884 my $menuImg_runScriptTask = Gtk3::Image->new_from_stock('gtk-execute', 'menu');
3885 $menuItem_runScriptTask->set_image($menuImg_runScriptTask);
3886 $menuItem_runScriptTask->signal_connect('activate' => sub {
3887  
3888 # Display a 'dialogue' window, so the user can choose the script to run
3889 my $text = $self->winObj->showEntryDialogue(
3890 'Run ' . $axmud::BASIC_NAME . ' script',
3891 'Enter the script to run as a task (e.g. \'wumpus\')',
3892 );
3893  
3894 if ($text) {
3895  
3896 # Run the script as a task
3897 $self->winObj->visibleSession->pseudoCmd('runscripttask ' . $text, $mode);
3898 }
3899 });
3900 $menuColumn_basic->append($menuItem_runScriptTask);
3901 # (Requires a visible session whose status is 'connected' or 'offline')
3902 $self->ivAdd('menuItemHash', 'run_script_task', $menuItem_runScriptTask);
3903  
3904 $menuColumn_basic->append(Gtk3::SeparatorMenuItem->new()); # Separator
3905  
3906 my $menuItem_checkScript = Gtk3::MenuItem->new('_Check script...');
3907 $menuItem_checkScript->signal_connect('activate' => sub {
3908  
3909 # Display a 'dialogue' window, so the user can choose the script to check
3910 my $text = $self->winObj->showEntryDialogue(
3911 'Check ' . $axmud::BASIC_NAME . ' script',
3912 'Enter the script to check (e.g. \'wumpus\')',
3913 );
3914  
3915 if ($text) {
3916  
3917 # Check the script
3918 $self->winObj->visibleSession->pseudoCmd('checkscript ' . $text, $mode);
3919 }
3920 });
3921 $menuColumn_basic->append($menuItem_checkScript);
3922 # (Requires a visible session)
3923 $self->ivAdd('menuItemHash', 'check_script', $menuItem_checkScript);
3924  
3925 my $menuItem_editScript = Gtk3::ImageMenuItem->new('_Edit script...');
3926 my $menuImg_editScript = Gtk3::Image->new_from_stock('gtk-edit', 'menu');
3927 $menuItem_editScript->set_image($menuImg_editScript);
3928 $menuItem_editScript->signal_connect('activate' => sub {
3929  
3930 # Display a 'dialogue' window, so the user can choose the script to check
3931 my $text = $self->winObj->showEntryDialogue(
3932 'Edit ' . $axmud::BASIC_NAME . ' script',
3933 'Enter the script to edit (e.g. \'wumpus\')',
3934 );
3935  
3936 if ($text) {
3937  
3938 # Edit the script
3939 $self->winObj->visibleSession->pseudoCmd('editscript ' . $text, $mode);
3940 }
3941 });
3942 $menuColumn_basic->append($menuItem_editScript);
3943 # (Requires a visible session)
3944 $self->ivAdd('menuItemHash', 'edit_script', $menuItem_editScript);
3945  
3946 # Setup complete
3947 return $menuColumn_basic;
3948 }
3949  
3950 sub drawPluginsColumn {
3951  
3952 # Called by $self->enableMenu
3953 # Sets up the menu's 'Plugins' column
3954 #
3955 # Expected arguments
3956 # (none besides $self)
3957 #
3958 # Return values
3959 # 'undef' on improper arguments, or if the menu can't be created
3960 # Otherwise returns the Gtk3::Menu created
3961  
3962 my ($self, $check) = @_;
3963  
3964 # Local variables
3965 my $mode;
3966  
3967 # Check for improper arguments
3968 if (defined $check) {
3969  
3970 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawPluginsColumn', @_);
3971 }
3972  
3973 # Import IVs (for convenience)
3974 $mode = $self->winObj->pseudoCmdMode;
3975  
3976 # Set up column
3977 my $menuColumn_plugins = Gtk3::Menu->new();
3978 if (! $menuColumn_plugins) {
3979  
3980 return undef;
3981 }
3982  
3983 my $menuItem_loadPlugin = Gtk3::ImageMenuItem->new('_Load plugin...');
3984 my $menuImg_loadPlugin = Gtk3::Image->new_from_stock('gtk-open', 'menu');
3985 $menuItem_loadPlugin->set_image($menuImg_loadPlugin);
3986 $menuItem_loadPlugin->signal_connect('activate' => sub {
3987  
3988 # Load the plugin
3989 $self->winObj->visibleSession->pseudoCmd('loadplugin', $mode);
3990 });
3991 $menuColumn_plugins->append($menuItem_loadPlugin);
3992 # (Requires a visible session)
3993 $self->ivAdd('menuItemHash', 'load_plugin', $menuItem_loadPlugin);
3994  
3995 my $menuItem_showPlugins = Gtk3::MenuItem->new('_Show plugins...');
3996 $menuItem_showPlugins->signal_connect('activate' => sub {
3997  
3998 # Open the client preference window at the right page
3999 my $prefWin = $self->winObj->createFreeWin(
4000 'Games::Axmud::PrefWin::Client',
4001 $self->winObj,
4002 $self->winObj->visibleSession,
4003 'Client preferences',
4004 );
4005  
4006 if ($prefWin) {
4007  
4008 $prefWin->notebook->set_current_page(2);
4009 }
4010 });
4011 $menuColumn_plugins->append($menuItem_showPlugins);
4012 # (Requires a visible session)
4013 $self->ivAdd('menuItemHash', 'show_plugin', $menuItem_showPlugins);
4014  
4015 # Setup complete
4016 return $menuColumn_plugins;
4017 }
4018  
4019 sub drawHelpColumn {
4020  
4021 # Called by $self->enableMenu
4022 # Sets up the menu's 'Help' column
4023 #
4024 # Expected arguments
4025 # (none besides $self)
4026 #
4027 # Return values
4028 # 'undef' on improper arguments, or if the menu can't be created
4029 # Otherwise returns the Gtk3::Menu created
4030  
4031 my ($self, $check) = @_;
4032  
4033 # Local variables
4034 my $mode;
4035  
4036 # Check for improper arguments
4037 if (defined $check) {
4038  
4039 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawHelpColumn', @_);
4040 }
4041  
4042 # Import IVs (for convenience)
4043 $mode = $self->winObj->pseudoCmdMode;
4044  
4045 # Set up column
4046 my $menuColumn_help = Gtk3::Menu->new();
4047 if (! $menuColumn_help) {
4048  
4049 return undef;
4050 }
4051  
4052 my $menuItem_help = Gtk3::ImageMenuItem->new('_Help...');
4053 my $menuImg_help = Gtk3::Image->new_from_stock('gtk-help', 'menu');
4054 $menuItem_help->set_image($menuImg_help);
4055 $menuItem_help->signal_connect('activate' => sub {
4056  
4057 # Check that the About window isn't already open
4058 if ($axmud::CLIENT->aboutWin) {
4059  
4060 # Only one About window can be open at a time
4061 $axmud::CLIENT->aboutWin->restoreFocus();
4062 # Open it at the right page
4063 $axmud::CLIENT->aboutWin->notebook->set_current_page(2);
4064  
4065 } else {
4066  
4067 # Open the About window
4068 my $winObj = $self->winObj->quickFreeWin(
4069 'Games::Axmud::OtherWin::About',
4070 $self->winObj->visibleSession,
4071 # Config
4072 'first_tab' => 'help',
4073 );
4074  
4075 if ($winObj) {
4076  
4077 $axmud::CLIENT->set_aboutWin($winObj);
4078 }
4079 }
4080 });
4081 $menuColumn_help->append($menuItem_help);
4082 # (Desensitised only when the setup wizwin is open)
4083 $self->ivAdd('menuItemHash', 'help', $menuItem_help);
4084  
4085 $menuColumn_help->append(Gtk3::SeparatorMenuItem->new()); # Separator
4086  
4087 my $menuItem_about = Gtk3::ImageMenuItem->new('_About...');
4088 my $menuImg_about = Gtk3::Image->new_from_stock('gtk-about', 'menu');
4089 $menuItem_about->set_image($menuImg_about);
4090 $menuItem_about->signal_connect('activate' => sub {
4091  
4092 # Check that the About window isn't already open
4093 if ($axmud::CLIENT->aboutWin) {
4094  
4095 # Window already open; draw attention to the fact by 'present'ing it
4096 $axmud::CLIENT->aboutWin->restoreFocus();
4097 # Open it at the right page
4098 $axmud::CLIENT->aboutWin->notebook->set_current_page(0);
4099  
4100 } else {
4101  
4102 # Open the About window
4103 my $winObj = $self->winObj->quickFreeWin(
4104 'Games::Axmud::OtherWin::About',
4105 $self->winObj->visibleSession,
4106 # Config
4107 'first_tab' => 'about',
4108 );
4109  
4110 if ($winObj) {
4111  
4112 # Only one About window can be open at a time
4113 $axmud::CLIENT->set_aboutWin($winObj);
4114 }
4115 }
4116 });
4117 $menuColumn_help->append($menuItem_about);
4118 # (Desensitised only when the setup wizwin is open)
4119 $self->ivAdd('menuItemHash', 'about', $menuItem_about);
4120  
4121 my $menuItem_credits = Gtk3::MenuItem->new('_Credits...');
4122 $menuItem_credits->signal_connect('activate' => sub {
4123  
4124 # Check that the About window isn't already open
4125 if ($axmud::CLIENT->aboutWin) {
4126  
4127 # Window already open; draw attention to the fact by 'present'ing it
4128 $axmud::CLIENT->aboutWin->restoreFocus();
4129 # Open it at the right page
4130 $axmud::CLIENT->aboutWin->notebook->set_current_page(1);
4131  
4132 } else {
4133  
4134 # Open the About window
4135 my $winObj = $self->winObj->quickFreeWin(
4136 'Games::Axmud::OtherWin::About',
4137 $self->winObj->visibleSession,
4138 # Config
4139 'first_tab' => 'credits',
4140 );
4141  
4142 if ($winObj) {
4143  
4144 # Only one About window can be open at a time
4145 $axmud::CLIENT->set_aboutWin($winObj);
4146 }
4147 }
4148 });
4149 $menuColumn_help->append($menuItem_credits);
4150 # (Desensitised only when the setup wizwin is open)
4151 $self->ivAdd('menuItemHash', 'credits', $menuItem_credits);
4152  
4153 my $menuItem_license = Gtk3::MenuItem->new('_Licenses...');
4154 $menuItem_license->signal_connect('activate' => sub {
4155  
4156 # Check that the About window isn't already open
4157 if ($axmud::CLIENT->aboutWin) {
4158  
4159 # Window already open; draw attention to the fact by 'present'ing it
4160 $axmud::CLIENT->aboutWin->restoreFocus();
4161 # Open it at the right page
4162 $axmud::CLIENT->aboutWin->notebook->set_current_page(3);
4163  
4164 } else {
4165  
4166 # Open the About window
4167 my $winObj = $self->winObj->quickFreeWin(
4168 'Games::Axmud::OtherWin::About',
4169 $self->winObj->visibleSession,
4170 # Config
4171 'first_tab' => 'license',
4172 );
4173  
4174 if ($winObj) {
4175  
4176 # Only one About window can be open at a time
4177 $axmud::CLIENT->set_aboutWin($winObj);
4178 }
4179 }
4180 });
4181 $menuColumn_help->append($menuItem_license);
4182 # (Desensitised only when the setup wizwin is open)
4183 $self->ivAdd('menuItemHash', 'license', $menuItem_license);
4184  
4185 $menuColumn_help->append(Gtk3::SeparatorMenuItem->new()); # Separator
4186  
4187 my $menuItem_website = Gtk3::MenuItem->new($axmud::SCRIPT . ' _website...');
4188 $menuItem_website->signal_connect('activate' => sub {
4189  
4190 $axmud::CLIENT->openURL($axmud::URL);
4191 });
4192 $menuColumn_help->append($menuItem_website);
4193 # (Requires GA::Client->browserCmd)
4194 $self->ivAdd('menuItemHash', 'go_website', $menuItem_website);
4195  
4196 # Setup complete
4197 return $menuColumn_help;
4198 }
4199  
4200 sub addPluginWidgets {
4201  
4202 # Called by GA::Client->addPluginMenus to add a sub-menu in the 'plugins' column, for the
4203 # benefit of a loaded plugin
4204 # Also called by $self->objEnable to add plugin sub-menus for 'internal' windows that are
4205 # created after the plugins are loaded
4206 #
4207 # Expected arguments
4208 # $plugin - The plugin name
4209 #
4210 # Return values
4211 # 'undef' on improper arguments
4212 # Otherwise, returns the sub-menu to which the plugin's code can add new menu items
4213  
4214 my ($self, $plugin, $check) = @_;
4215  
4216 # Check for improper arguments
4217 if (! defined $plugin || defined $check) {
4218  
4219 return $axmud::CLIENT->writeImproper($self->_objClass . '->addPluginWidgets', @_);
4220 }
4221  
4222 # Create a sub-menu for this plugin. If this is the first plugin to add menu items, add a
4223 # separator
4224 if (! $self->pluginHash) {
4225  
4226 $self->pluginMenu->append(Gtk3::SeparatorMenuItem->new());
4227 }
4228  
4229 # Add a sub-menu
4230 my $subMenu = Gtk3::Menu->new();
4231  
4232 my $menuItem = Gtk3::MenuItem->new('_' . $plugin . ' plugin');
4233 $menuItem->set_submenu($subMenu);
4234 $self->pluginMenu->append($menuItem);
4235  
4236 # Update IVs
4237 $self->ivAdd('pluginHash', $plugin, $subMenu);
4238 $self->ivAdd('pluginMenuItemHash', $plugin, $menuItem);
4239  
4240 return $subMenu;
4241 }
4242  
4243 sub sensitiseWidgets {
4244  
4245 # Can be called by anything, but usually called by GA::Win::Internal->restrictMenuBars
4246 # Given a list of Gtk3 widgets (all of them menu bar items), sets them as sensitive
4247 #
4248 # Expected arguments
4249 # (none besides $self)
4250 #
4251 # Optional arguments
4252 # @widgetList - A list of widget names, matching keys in $self->menuItemHash
4253 # (e.g. 'move_up_level')
4254 #
4255 # Return values
4256 # 1
4257  
4258 my ($self, @widgetList) = @_;
4259  
4260 # (No improper arguments to check)
4261  
4262 foreach my $widgetName (@widgetList) {
4263  
4264 my $widget = $self->ivShow('menuItemHash', $widgetName);
4265 if ($widget) {
4266  
4267 $widget->set_sensitive(TRUE);
4268 }
4269 }
4270  
4271 return 1;
4272 }
4273  
4274 sub desensitiseWidgets {
4275  
4276 # Can be called by anything, but usually called by GA::Win::Internal->restrictMenuBars
4277 # Given a list of Gtk3 widgets (all of them menu bar items), sets them as insensitive
4278 #
4279 # Expected arguments
4280 # (none besides $self)
4281 #
4282 # Optional arguments
4283 # @widgetList - A list of widget names, matching keys in $self->menuItemHash
4284 # (e.g. 'move_up_level')
4285 #
4286 # Return values
4287 # 1
4288  
4289 my ($self, @widgetList) = @_;
4290  
4291 # (No improper arguments to check)
4292  
4293 foreach my $widgetName (@widgetList) {
4294  
4295 my $widget = $self->ivShow('menuItemHash', $widgetName);
4296 if ($widget) {
4297  
4298 $widget->set_sensitive(FALSE);
4299 }
4300 }
4301  
4302 return 1;
4303 }
4304  
4305 # Menu bar support functions
4306  
4307 sub promptUser {
4308  
4309 # Called by most menu items in $self->drawWorldColumn
4310 # Before doing an action that will lead to the current connection being closed (e.g. 'Stop
4311 # client', which runs the ';stopclient' command), prompt the user for confirmation
4312 # We don't want the user to lose their connection after accidentally clicking on a menu
4313 # item; at the same time, we usually don't ask for confirmation when the user types the
4314 # equivalent client command, because they are much less likely to make a mistake while
4315 # typing, than while clicking
4316 #
4317 # Expected arguments
4318 # $title - The 'dialogue' window title
4319 # $msg - A message to display in the 'dialogue' window
4320 #
4321 # Return values
4322 # 'undef' on improper arguments or if the user clicks 'No' in the 'dialogue' window (or
4323 # closes it without clicking 'Yes'
4324 # 1 if the user clicks on 'Yes' in the 'dialogue' window
4325  
4326 my ($self, $title, $msg, $check) = @_;
4327  
4328 # Local variables
4329 my $choice;
4330  
4331 # Check for improper arguments
4332 if (! defined $title || ! defined $msg || defined $check) {
4333  
4334 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptUser', @_);
4335 }
4336  
4337 # Prompt the user
4338 $choice = $self->winObj->showMsgDialogue(
4339 $title,
4340 'question',
4341 $msg,
4342 'yes-no',
4343 );
4344  
4345 if ($choice eq 'yes') {
4346 return 1;
4347 } else {
4348 return undef;
4349 }
4350 }
4351  
4352 sub getWorldList {
4353  
4354 # Called by $self->drawFileColumn
4355 # Compiles an ordered list of world profile names, with the visible session's current world
4356 # as the first item in the list
4357 #
4358 # Expected arguments
4359 # (none besides $self)
4360 #
4361 # Return values
4362 # An empty list on improper arguments
4363 # Otherwise, the sorted list of world profile names
4364  
4365 my ($self, $check) = @_;
4366  
4367 # Local variables
4368 my (@emptyList, @worldList);
4369  
4370 # Check for improper arguments
4371 if (defined $check) {
4372  
4373 $axmud::CLIENT->writeImproper($self->_objClass . '->getWorldList', @_);
4374 return @emptyList;
4375 }
4376  
4377 foreach my $profObj ($axmud::CLIENT->ivValues('worldProfHash')) {
4378  
4379 if ($profObj ne $self->winObj->visibleSession->currentWorld) {
4380  
4381 push (@worldList, $profObj->name);
4382 }
4383 }
4384  
4385 # Now sort the list alphabetically, but put the current world (if any) at the top
4386 @worldList = sort {lc($a) cmp lc($b)} (@worldList);
4387 unshift (@worldList, $self->winObj->visibleSession->currentWorld->name);
4388  
4389 # Operation complete
4390 return @worldList;
4391 }
4392  
4393 sub getOtherProfList {
4394  
4395 # Called by $self->drawFileColumn
4396 # Compiles an ordered list of non-world profile names
4397 #
4398 # Expected arguments
4399 # (none besides $self)
4400 #
4401 # Return values
4402 # An empty list on improper arguments
4403 # Otherwise, the sorted list of non-world profile names
4404  
4405 my ($self, $check) = @_;
4406  
4407 # Local variables
4408 my (@emptyList, @profList);
4409  
4410 # Check for improper arguments
4411 if (defined $check) {
4412  
4413 $axmud::CLIENT->writeImproper($self->_objClass . '->getOtherProfList', @_);
4414 return @emptyList;
4415 }
4416  
4417 foreach my $profObj ($self->winObj->visibleSession->ivValues('profHash')) {
4418  
4419 if ($profObj->category ne 'world') {
4420  
4421 push (@profList, $profObj->name);
4422 }
4423 }
4424  
4425 # Now sort the list alphabetically
4426 @profList = sort {lc($a) cmp lc($b)} (@profList);
4427  
4428 # Operation complete
4429 return @profList;
4430 }
4431  
4432 sub getDictList {
4433  
4434 # Called by $self->drawFileColumn
4435 # Compiles an ordered list of dictionary names, with the current dictionary the first item
4436 # on the list
4437 #
4438 # Expected arguments
4439 # (none besides $self)
4440 #
4441 # Return values
4442 # An empty list on improper arguments
4443 # Otherwise, the sorted list of dictionary names
4444  
4445 my ($self, $check) = @_;
4446  
4447 # Local variables
4448 my (@emptyList, @dictList);
4449  
4450 # Check for improper arguments
4451 if (defined $check) {
4452  
4453 $axmud::CLIENT->writeImproper($self->_objClass . '->getDictList', @_);
4454 return @emptyList;
4455 }
4456  
4457 foreach my $dictName ($axmud::CLIENT->ivKeys('dictHash')) {
4458  
4459 if ($dictName ne $self->winObj->visibleSession->currentDict->name) {
4460  
4461 push (@dictList, $dictName);
4462 }
4463 }
4464  
4465 # Now sort the list alphabetically, and insert the current dictionary at the top of the list
4466 @dictList = sort {lc($a) cmp lc($b)} (@dictList);
4467 unshift (@dictList, $self->winObj->visibleSession->currentDict->name);
4468  
4469 # Operation complete
4470 return @dictList;
4471 }
4472  
4473 sub getFileObjList {
4474  
4475 # Called by $self->drawFileColumn
4476 # Compiles an ordered list of file object names
4477 #
4478 # Expected arguments
4479 # (none besides $self)
4480 #
4481 # Return values
4482 # An empty list on improper arguments
4483 # Otherwise, returns a list in the form (list_reference, hash_reference):
4484 # 'list_reference' - list of items to display in a combo box, e.g.
4485 # 'deathmud (worldprof)'
4486 # 'hash_reference' - hash in which each key is an item in 'list_reference', and
4487 # the corresponding value is the name of the file object
4488 # Otherwise, the sorted list of file object names
4489  
4490 my ($self, $check) = @_;
4491  
4492 # Local variables
4493 my (
4494 @emptyList, @list, @sortedList,
4495 %regHash, %checkHash, %returnHash,
4496 );
4497  
4498 # Check for improper arguments
4499 if (defined $check) {
4500  
4501 $axmud::CLIENT->writeImproper($self->_objClass . '->getDictList', @_);
4502 return @emptyList;
4503 }
4504  
4505 # Get a list of client file objects, and sort them alphabetically
4506 %regHash = $axmud::CLIENT->fileObjHash;
4507 @list = sort {
4508 if ($a->fileType ne $b->fileType) {
4509 $a->fileType cmp $b->fileType
4510 } else {
4511 lc($a->name) cmp lc($b->name)
4512 }
4513 } (values %regHash);
4514  
4515 foreach my $obj (@list) {
4516  
4517 my $string;
4518  
4519 if ($obj->fileType eq 'worldprof') {
4520 $string = $obj->name . ' (type: worldprof)';
4521 } else {
4522 $string = $obj->name;
4523 }
4524  
4525 # Don't add the same file object more than once
4526 if (! exists $checkHash{$obj}) {
4527  
4528 push (@sortedList, $string);
4529 $returnHash{$string} = $obj;
4530 $checkHash{$obj} = undef;
4531 }
4532 }
4533  
4534 # Get a list of session file objects, and sort them alphabetically
4535 %regHash = $self->winObj->visibleSession->sessionFileObjHash;
4536 @list = sort {lc($a->name) cmp lc($b->name)} (values %regHash);
4537  
4538 foreach my $obj (@list) {
4539  
4540 my $string = $obj->name . ' (parent: ' . $obj->assocWorldProf . ')';
4541  
4542 # Don't add the same file object more than once
4543 if (! exists $checkHash{$obj}) {
4544  
4545 push (@sortedList, $string);
4546 $returnHash{$string} = $obj->name;
4547 $checkHash{$obj} = undef;
4548 }
4549 }
4550  
4551 # Operation complete
4552 return (\@sortedList, \%returnHash);
4553 }
4554  
4555 ##################
4556 # Accessors - set
4557  
4558 ##################
4559 # Accessors - get
4560  
4561 sub menuBar
4562 { $_[0]->{menuBar} }
4563  
4564 sub menuItemHash
4565 { my $self = shift; return %{$self->{menuItemHash}}; }
4566  
4567 sub pluginMenu
4568 { $_[0]->{pluginMenu} }
4569 sub pluginHash
4570 { my $self = shift; return %{$self->{pluginHash}}; }
4571 sub pluginMenuItemHash
4572 { my $self = shift; return %{$self->{pluginMenuItemHash}}; }
4573  
4574 sub saveAllSessionsFlag
4575 { $_[0]->{saveAllSessionsFlag} }
4576 }
4577  
4578 { package Games::Axmud::Strip::Toolbar;
4579  
4580 use strict;
4581 use warnings;
4582 # use diagnostics;
4583  
4584 use Glib qw(TRUE FALSE);
4585  
4586 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
4587  
4588 ##################
4589 # Constructors
4590  
4591 sub new {
4592  
4593 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
4594 # Creates the GA::Strip::Toolbar - a non-compulsory strip object containing a Gtk3::Toolbar
4595 #
4596 # Expected arguments
4597 # $number - The strip object's number within the parent window (matches
4598 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
4599 # created to access its default IVs)
4600 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
4601 # objects
4602 #
4603 # Optional arguments
4604 # %initHash - A hash containing arbitrary data to use as the strip object's
4605 # initialisation settings. The strip object should use default
4606 # initialisation settings unless it can succesfully interpret one or more
4607 # of the key-value pairs in the hash, if there are any
4608 # - (This type of strip object requires no initialisation settings)
4609 #
4610 # Return values
4611 # 'undef' on improper arguments
4612 # Blessed reference to the newly-created object on success
4613  
4614 my ($class, $number, $winObj, %initHash) = @_;
4615  
4616 # Local variables
4617 my %modHash;
4618  
4619 # Check for improper arguments
4620 if (! defined $class || ! defined $number || ! defined $winObj) {
4621  
4622 return $axmud::CLIENT->writeImproper($class . '->new', @_);
4623 }
4624  
4625 # Setup
4626 my $self = {
4627 _objName => 'strip_' . $number,
4628 _objClass => $class,
4629 _parentFile => undef, # No parent file object
4630 _parentWorld => undef, # No parent file object
4631 _privFlag => TRUE, # All IVs are private
4632  
4633 # Standard strip object IVs
4634 # -------------------------
4635  
4636 # The strip object's number within the parent window (matches
4637 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
4638 # its default IVs)
4639 number => $number,
4640 # The type of strip object (custom strip objects should use a ->type starting with
4641 # 'custom_' to avoid clashing with future built-in strip objects)
4642 type => 'toolbar',
4643 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
4644 winObj => $winObj,
4645  
4646 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
4647 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
4648 # still exists in GA::Win::Internal->stripHash, etc)
4649 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
4650 # have gauges to draw, or not, depending on current conditions. (Most strip objects
4651 # have this flag set to TRUE all the time)
4652 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
4653 # called by this object's functions
4654 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
4655 # the flag's value shouldn't be modified by anything other than
4656 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
4657 # $self->set_visibleFlag)
4658 visibleFlag => TRUE,
4659 # Flag set to TRUE is the strip object should be given its share of any extra space
4660 # within the packing box (the extra space is divided equally between all children of
4661 # the box whose ->expandFlag is TRUE)
4662 expandFlag => FALSE,
4663 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
4664 # actually allocated within the strip object, FALSE if it is used as padding outside
4665 # it (on both sides)
4666 fillFlag => FALSE,
4667 # Flag set to TRUE if the strip object should be packed into its window with a small
4668 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
4669 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
4670 # for example in the toolbar strip object)
4671 spacingFlag => FALSE,
4672 # Flag set to TRUE if only one instance of this strip object should be added to the
4673 # parent window, set to FALSE if any number of instances can be added
4674 jealousyFlag => TRUE,
4675 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
4676 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
4677 # users)
4678 blindFlag => FALSE,
4679 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
4680 # allowed to accept the focus, FALSE if not. The restriction is applied during the
4681 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
4682 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
4683 # GA::Strip::MenuBar)
4684 allowFocusFlag => FALSE,
4685  
4686 # Initialisation settings stored as a hash (see the comments above)
4687 initHash => \%modHash,
4688 # Reference to a function to call when some widget is used. This IV is set only when
4689 # required by this type of strip object. It can be set by a call to
4690 # $self->set_func() or by some setting in $self->initHash, which is applied in the
4691 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
4692 # generic object function Games::Axmud->getMethodRef()
4693 funcRef => undef,
4694 # A value passed to ->funcRef when it is called which identifies this strip object and
4695 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
4696 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
4697 # to $self->objEnable()
4698 funcID => undef,
4699  
4700 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
4701 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
4702 packingBox => undef, # Gtk3::VBox
4703  
4704 # Other IVs
4705 # ---------
4706  
4707 # Widgets
4708 toolbar => undef, # Gtk3::Toolbar
4709 toolbarWidgetList => [], # Various
4710  
4711 # Toolbar buttons which will be sensitised or desensitised, depending on whether the
4712 # session is connected to a world (or if it's in 'offline' mode). Hash in the form
4713 # $requireConnectHash{'button_name'} = Gtk3_widget
4714 requireConnectHash => {},
4715 # Toolbar buttons which will be sensitised or desensitised, depending on whether there
4716 # is a visible session for this window. Hash in the form
4717 # $requireSessionHash{'button_name'} = Gtk3_widget
4718 requireSessionHash => {},
4719 };
4720  
4721 # Bless the object into existence
4722 bless $self, $class;
4723  
4724 return $self;
4725 }
4726  
4727 ##################
4728 # Methods
4729  
4730 # Standard strip object functions
4731  
4732 sub objEnable {
4733  
4734 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
4735 # Sets up the strip object's widgets
4736 #
4737 # Expected arguments
4738 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
4739 # parent window
4740 #
4741 # Return values
4742 # 'undef' on improper arguments
4743 # 1 on success
4744  
4745 my ($self, $winmapObj, $check) = @_;
4746  
4747 # Check for improper arguments
4748 if (! defined $winmapObj || defined $check) {
4749  
4750 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
4751 }
4752  
4753 # Create a packing box
4754 my $vBox = Gtk3::VBox->new(FALSE, 0);
4755 $vBox->set_border_width(0);
4756  
4757 # Create a Gtk3::Toolbar
4758 my $toolbar = Gtk3::Toolbar->new();
4759 $vBox->pack_start($toolbar, TRUE, TRUE, 0);
4760  
4761 # Update IVs
4762 $self->ivPoke('packingBox', $vBox);
4763 $self->ivPoke('toolbar', $toolbar);
4764  
4765 # Draw a set of buttons and separators
4766 $self->fillToolbar();
4767  
4768 return 1;
4769 }
4770  
4771 sub objDestroy {
4772  
4773 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
4774 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
4775 # to do any necessary tidying up
4776 #
4777 # Expected arguments
4778 # (none besides $self)
4779 #
4780 # Return values
4781 # 'undef' on improper arguments
4782 # 1 otherwise
4783  
4784 my ($self, $check) = @_;
4785  
4786 # Check for improper arguments
4787 if (defined $check) {
4788  
4789 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
4790 }
4791  
4792 # (No tidying up required for this type of strip object)
4793 # ...
4794  
4795 return 1;
4796 }
4797  
4798 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Strip
4799  
4800 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Strip
4801  
4802 # ->signal_connects are stored in $self->fillToolbar
4803  
4804 # Other functions
4805  
4806 sub fillToolbar {
4807  
4808 # Called by $self->objEnable and ->resetToolbar
4809 # Draws a set of toolbar buttons and separators, and adds them to the existing toolbar
4810 #
4811 # Expected arguments
4812 # (none besides $self)
4813 #
4814 # Return values
4815 # 'undef' on improper arguments
4816 # 1 otherwise
4817  
4818 my ($self, $check) = @_;
4819  
4820 # Local variables
4821 my (
4822 $winObj,
4823 @widgetList,
4824 );
4825  
4826 # Check for improper arguments
4827 if (defined $check) {
4828  
4829 return $axmud::CLIENT->writeImproper($self->_objClass . '->fillToolbar', @_);
4830 }
4831  
4832 # Each toolbar button is a GA::Obj::Toolbar object
4833 foreach my $buttonName ($axmud::CLIENT->toolbarList) {
4834  
4835 my ($separator, $buttonObj, $path, $label, $iconName, $choice);
4836  
4837 if ($buttonName eq 'separator') {
4838  
4839 # Add a separator to the toolbar
4840 my $separator = Gtk3::SeparatorToolItem->new();
4841  
4842 $self->toolbar->insert($separator, -1);
4843 push (@widgetList, $separator);
4844  
4845 } else {
4846  
4847 $buttonObj = $axmud::CLIENT->ivShow('toolbarHash', $buttonName);
4848  
4849 # Set the path of the icon file. If it doesn't exist, use an emergency fallback icon
4850 if ($buttonObj->customFlag) {
4851 $path = $buttonObj->iconPath;
4852 } else {
4853 $path = $axmud::SHARE_DIR . '/icons/main/' . $buttonObj->iconPath;
4854 }
4855  
4856 if (! (-e $path)) {
4857  
4858 # Spare icon
4859 $path = $axmud::SHARE_DIR . '/icons/main/drop.png';
4860 }
4861  
4862 if ($axmud::CLIENT->toolbarLabelFlag) {
4863  
4864 # Otherwise, $label remains as 'undef', which is what Gtk3::ToolButton is
4865 # expecting
4866 $label = $buttonObj->descrip;
4867 }
4868  
4869 # Create the toolbar button itself
4870 my $toolButton_item = Gtk3::ToolButton->new(
4871 Gtk3::Image->new_from_file($path),
4872 $label,
4873 );
4874 $toolButton_item->set_tooltip_text($buttonObj->descrip);
4875 $toolButton_item->signal_connect('clicked' => sub {
4876  
4877 # The icons for ';connect', ';openaboutwindow -h', ';stopsession' and
4878 # ';stopclient' are sensitised even when there is no current session. Since we
4879 # can't call ->doInstruct, process those commands directly
4880  
4881 # Special case: prompt the user before stopping an active session (if the flag
4882 # is set)
4883 if ($buttonObj->instruct eq ';stopsession') {
4884  
4885 if ($self->winObj->visibleSession) {
4886  
4887 if (
4888 $self->winObj->visibleSession->status eq 'connected'
4889 && $axmud::CLIENT->confirmCloseToolButtonFlag
4890 ) {
4891 $choice = $self->winObj->showMsgDialogue(
4892 'Close tab',
4893 'question',
4894 'This session is connected to a world. Are you sure you want'
4895 . ' to close it?',
4896 'yes-no',
4897 );
4898  
4899 if ($choice eq 'yes') {
4900  
4901 $self->winObj->visibleSession->pseudoCmd(
4902 'stopsession',
4903 $self->winObj->pseudoCmdMode,
4904 );
4905 }
4906  
4907 } else {
4908  
4909 $self->winObj->visibleSession->pseudoCmd(
4910 'stopsession',
4911 $self->winObj->pseudoCmdMode,
4912 );
4913 }
4914  
4915 } else {
4916  
4917 # No sessions open, so terminate the client
4918 $axmud::CLIENT->stop();
4919 }
4920  
4921 } elsif ($buttonObj->instruct eq ';stopclient') {
4922  
4923 if ($self->winObj->visibleSession) {
4924  
4925 $self->winObj->visibleSession->pseudoCmd(
4926 'stopclient',
4927 $self->winObj->pseudoCmdMode,
4928 );
4929  
4930 } else {
4931  
4932 # No sessions open, so terminate the client
4933 $axmud::CLIENT->stop();
4934 }
4935  
4936 # If a session is open, then we can call ->doInstruct, as normal
4937 } elsif ($self->winObj->visibleSession) {
4938  
4939 $self->winObj->visibleSession->doInstruct($buttonObj->instruct);
4940  
4941 # Process commands directly
4942 } elsif ($buttonObj->instruct eq ';connect') {
4943  
4944 # Check that the Connections window isn't already open
4945 if ($axmud::CLIENT->connectWin) {
4946  
4947 # Window already open; draw attention to the fact by 'present'ing it
4948 $axmud::CLIENT->connectWin->restoreFocus();
4949  
4950 } else {
4951  
4952 # Open the Connections window
4953 $winObj = $self->winObj->quickFreeWin(
4954 'Games::Axmud::OtherWin::Connect',
4955 $self->winObj->visibleSession,
4956 );
4957  
4958 if ($winObj) {
4959  
4960 # Only one Connections window can be open at a time
4961 $axmud::CLIENT->set_connectWin($winObj);
4962 }
4963 }
4964  
4965 } elsif ($buttonObj->instruct eq ';openaboutwindow -h') {
4966  
4967 # Check that the About window isn't already open
4968 if ($axmud::CLIENT->aboutWin) {
4969  
4970 # Window already open; draw attention to the fact by 'present'ing it
4971 $axmud::CLIENT->aboutWin->restoreFocus();
4972  
4973 } else {
4974  
4975 # Open the About window
4976 $winObj = $self->winObj->quickFreeWin(
4977 'Games::Axmud::OtherWin::About',
4978 $self->winObj->visibleSession,
4979 # Config
4980 'first_tab' => 'help',
4981 );
4982  
4983 if ($winObj) {
4984  
4985 # Only one About window can be open at a time
4986 $axmud::CLIENT->set_aboutWin($winObj);
4987 }
4988 }
4989 }
4990  
4991 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
4992 $axmud::CLIENT->desktopObj->restrictWidgets();
4993 });
4994  
4995 $iconName = 'icon_' . $buttonObj->name;
4996 if ($buttonObj->requireConnectFlag) {
4997  
4998 # (Button requires a connection to a world, even if it's in 'offline' mode)
4999 $self->ivAdd('requireConnectHash', $iconName, $toolButton_item);
5000  
5001 } elsif ($buttonObj->requireSessionFlag) {
5002  
5003 # (Button requires a current session)
5004 $self->ivAdd('requireSessionHash', $iconName, $toolButton_item);
5005  
5006 } else {
5007  
5008 # (Button always sensitised)
5009 $self->ivDelete('requireConnectHash', $iconName);
5010 $self->ivDelete('requireSessionHash', $iconName);
5011 }
5012  
5013 # Add the toolbar button to the toolbar
5014 $self->toolbar->insert($toolButton_item, -1);
5015 push (@widgetList, $toolButton_item);
5016 }
5017 }
5018  
5019 $self->toolbar->show_all();
5020  
5021 # Store the list of buttons and separators
5022 $self->ivPoke('toolbarWidgetList', @widgetList);
5023  
5024 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
5025 $axmud::CLIENT->desktopObj->restrictWidgets();
5026  
5027 # Setup complete
5028 return 1;
5029 }
5030  
5031 sub resetToolbar {
5032  
5033 # Called by GA::PrefWin::Client->toolbarTab to re-draw the list of toolbar buttons, after
5034 # the GA::Client->toolbarHash and ->toolbarList have been modified
5035 #
5036 # Expected arguments
5037 # (none besides $self)
5038 #
5039 # Return values
5040 # 'undef' on improper arguments
5041 # 1 otherwise
5042  
5043 my ($self, $check) = @_;
5044  
5045 # Check for improper arguments
5046 if (defined $check) {
5047  
5048 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetToolbar', @_);
5049 }
5050  
5051 # Remove the existing buttons and separators
5052 foreach my $widget ($self->toolbarWidgetList) {
5053  
5054 $axmud::CLIENT->desktopObj->removeWidget($self->toolbar, $widget);
5055 }
5056  
5057 # Draw a new set of buttons and separators
5058 $self->fillToolbar();
5059  
5060 return 1;
5061 }
5062  
5063 sub sensitiseWidgets {
5064  
5065 # Can be called by anything, but usually called by GA::Win::Internal->restrictToolbars
5066 # Given a list of Gtk3 widgets (all of them toolbar items), sets them as sensitive
5067 #
5068 # Expected arguments
5069 # (none besides $self)
5070 #
5071 # Optional arguments
5072 # @widgetList - A list of widget names from $self->toolbarWidgetList (e.g. 'connect_me')
5073 #
5074 # Return values
5075 # 1
5076  
5077 my ($self, @widgetList) = @_;
5078  
5079 # (No improper arguments to check)
5080  
5081 foreach my $widgetName (@widgetList) {
5082  
5083 my $widget;
5084  
5085 $widget = $self->ivShow('requireConnectHash', $widgetName);
5086 if (! $widget) {
5087  
5088 $widget = $self->ivShow('requireSessionHash', $widgetName);
5089 }
5090  
5091 if ($widget) {
5092  
5093 $widget->set_sensitive(TRUE);
5094 }
5095 }
5096  
5097 return 1;
5098 }
5099  
5100 sub desensitiseWidgets {
5101  
5102 # Can be called by anything, but usually called by GA::Win::Internal->restrictToolbars
5103 # Given a list of Gtk3 widgets (all of them toolbar items), sets them as insensitive
5104 #
5105 # Expected arguments
5106 # (none besides $self)
5107 #
5108 # Optional arguments
5109 # @widgetList - A list of widget names from $self->toolbarWidgetList (e.g. 'connect_me')
5110 #
5111 # Return values
5112 # 1
5113  
5114 my ($self, @widgetList) = @_;
5115  
5116 # (No improper arguments to check)
5117  
5118 foreach my $widgetName (@widgetList) {
5119  
5120 my $widget;
5121  
5122 $widget = $self->ivShow('requireConnectHash', $widgetName);
5123 if (! $widget) {
5124  
5125 $widget = $self->ivShow('requireSessionHash', $widgetName);
5126 }
5127  
5128 if ($widget) {
5129  
5130 $widget->set_sensitive(FALSE);
5131 }
5132 }
5133  
5134 return 1;
5135 }
5136  
5137 ##################
5138 # Accessors - set
5139  
5140 ##################
5141 # Accessors - get
5142  
5143 sub toolbar
5144 { $_[0]->{toolbar} }
5145 sub toolbarWidgetList
5146 { my $self = shift; return @{$self->{toolbarWidgetList}}; }
5147  
5148 sub requireConnectHash
5149 { my $self = shift; return %{$self->{requireConnectHash}}; }
5150 sub requireSessionHash
5151 { my $self = shift; return %{$self->{requireSessionHash}}; }
5152 }
5153  
5154 { package Games::Axmud::Strip::Table;
5155  
5156 use strict;
5157 use warnings;
5158 # use diagnostics;
5159  
5160 use Glib qw(TRUE FALSE);
5161  
5162 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
5163  
5164 ##################
5165 # Constructors
5166  
5167 sub new {
5168  
5169 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
5170 # Creates the GA::Strip::Table - a compulsory strip object containing a Gtk3::Grid, onto
5171 # which widgets can be drawn
5172 #
5173 # Expected arguments
5174 # $number - The strip object's number within the parent window (matches
5175 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
5176 # created to access its default IVs)
5177 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
5178 # objects
5179 #
5180 # Optional arguments
5181 # %initHash - A hash containing arbitrary data to use as the strip object's
5182 # initialisation settings. The strip object should use default
5183 # initialisation settings unless it can succesfully interpret one or more
5184 # of the key-value pairs in the hash, if there are any
5185 #
5186 # 'spacing' - The number of pixels between table objects. If
5187 # specified, can be any integer value in the range 0-10. If not
5188 # specified, an invalid value or 'undef',
5189 # GA::Client->constMainSpacingPixels or ->constGridSpacingPixels
5190 # is used
5191 # 'border' - The number of pixels between table objects and the edge
5192 # of the table. If specified, can be any integer value in the
5193 # range 0-10. If not specified, an invalid value or 'undef', 0 is
5194 # used
5195 #
5196 # Return values
5197 # 'undef' on improper arguments
5198 # Blessed reference to the newly-created object on success
5199  
5200 my ($class, $number, $winObj, %initHash) = @_;
5201  
5202 # Local variables
5203 my (
5204 $spacing,
5205 %modHash,
5206 );
5207  
5208 # Check for improper arguments
5209 if (! defined $class || ! defined $number || ! defined $winObj) {
5210  
5211 return $axmud::CLIENT->writeImproper($class . '->new', @_);
5212 }
5213  
5214 # Default initialisation settings
5215 if ($winObj ne 'temp' && $winObj->winType eq 'main') {
5216 $spacing = $axmud::CLIENT->constMainSpacingPixels;
5217 } else {
5218 $spacing = $axmud::CLIENT->constGridSpacingPixels;
5219 }
5220  
5221 %modHash = (
5222 'spacing' => $spacing,
5223 'border' => 0,
5224 );
5225  
5226 # Interpret the initialisation settings in %initHash, if any
5227 foreach my $key (keys %modHash) {
5228  
5229 if (exists $initHash{$key}) {
5230  
5231 $modHash{$key} = $initHash{$key};
5232 }
5233 }
5234  
5235 # Setup
5236 my $self = {
5237 _objName => 'strip_' . $number,
5238 _objClass => $class,
5239 _parentFile => undef, # No parent file object
5240 _parentWorld => undef, # No parent file object
5241 _privFlag => TRUE, # All IVs are private
5242  
5243 # Standard strip object IVs
5244 # -------------------------
5245  
5246 # The strip object's number within the parent window (matches
5247 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
5248 # its default IVs)
5249 number => $number,
5250 # The type of strip object (custom strip objects should use a ->type starting with
5251 # 'custom_' to avoid clashing with future built-in strip objects)
5252 type => 'table',
5253 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
5254 winObj => $winObj,
5255  
5256 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
5257 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
5258 # still exists in GA::Win::Internal->stripHash, etc)
5259 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
5260 # have gauges to draw, or not, depending on current conditions. (Most strip objects
5261 # have this flag set to TRUE all the time)
5262 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
5263 # called by this object's functions
5264 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
5265 # the flag's value shouldn't be modified by anything other than
5266 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
5267 # $self->set_visibleFlag)
5268 visibleFlag => TRUE,
5269 # Flag set to TRUE is the strip object should be given its share of any extra space
5270 # within the packing box (the extra space is divided equally between all children of
5271 # the box whose ->expandFlag is TRUE)
5272 expandFlag => TRUE,
5273 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
5274 # actually allocated within the strip object, FALSE if it is used as padding outside
5275 # it (on both sides)
5276 fillFlag => TRUE,
5277 # Flag set to TRUE if the strip object should be packed into its window with a small
5278 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
5279 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
5280 # for example in the toolbar strip object)
5281 spacingFlag => TRUE,
5282 # Flag set to TRUE if only one instance of this strip object should be added to the
5283 # parent window, set to FALSE if any number of instances can be added
5284 jealousyFlag => TRUE,
5285 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
5286 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
5287 # users)
5288 blindFlag => TRUE,
5289 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
5290 # allowed to accept the focus, FALSE if not. The restriction is applied during the
5291 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
5292 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
5293 # GA::Strip::MenuBar)
5294 allowFocusFlag => FALSE,
5295  
5296 # Initialisation settings stored as a hash (see the comments above)
5297 initHash => \%modHash,
5298 # Reference to a function to call when some widget is used. This IV is set only when
5299 # required by this type of strip object. It can be set by a call to
5300 # $self->set_func() or by some setting in $self->initHash, which is applied in the
5301 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
5302 # generic object function Games::Axmud->getMethodRef()
5303 funcRef => undef,
5304 # A value passed to ->funcRef when it is called which identifies this strip object and
5305 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
5306 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
5307 # to $self->objEnable()
5308 funcID => undef,
5309  
5310 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
5311 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
5312 packingBox => undef, # Gtk3::ScrolledWindow
5313  
5314 # Other IVs
5315 # ---------
5316  
5317 # Gtk3 widgets to draw the table
5318 table => undef, # Gtk3::Grid
5319  
5320 # The table size actually used
5321 tableSize => undef,
5322  
5323 # Hash of tablezone objects (GA::Obj::Tablezone), each of which marks out an area of
5324 # Gtk3::Grid for a single table object. Hash in the form
5325 # $zoneHash{number} = blessed_reference_to_tablezone_object
5326 tablezoneHash => {},
5327 # Number of tablezones ever created for this Gtk3::Grid (used to give every tablezone
5328 # object a number unique to the Gtk3::Grid)
5329 tablezoneCount => 0,
5330 # Hash of table objects (inheriting from GA::Generic::Table) which occupy the space
5331 # marked out by a single tablezone. Hash in the form
5332 # $tableObjHash{number} = blessed_reference_to_table_object
5333 tableObjHash => {},
5334 # Number of table objects ever created for this Gtk3::Grid (used to give every table
5335 # object a number unique to the Gtk3::Grid)
5336 tableObjCount => 0,
5337  
5338 # The current value for spacing between table objects (actually applied as a border
5339 # around each table object; set from $self->initHash by $self->objEnable)
5340 currentSpacing => 0,
5341 # The current value for the border at the edge of the table (set from $self->initHash by
5342 # $self->objEnable)
5343 currentBorder => 0,
5344 };
5345  
5346 # Bless the object into existence
5347 bless $self, $class;
5348  
5349 return $self;
5350 }
5351  
5352 ##################
5353 # Methods
5354  
5355 # Standard strip object functions
5356  
5357 sub objEnable {
5358  
5359 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
5360 # Sets up the strip object's widgets
5361 #
5362 # Expected arguments
5363 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
5364 # parent window
5365 #
5366 # Return values
5367 # 'undef' on improper arguments
5368 # 1 on success
5369  
5370 my ($self, $winmapObj, $check) = @_;
5371  
5372 # Local variables
5373 my ($spacing, $border);
5374  
5375 # Check for improper arguments
5376 if (! defined $winmapObj || defined $check) {
5377  
5378 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
5379 }
5380  
5381 # Interpret $self->initHash, replacing any invalid values
5382 $spacing = $self->ivShow('initHash', 'spacing');
5383 if (defined $spacing && $axmud::CLIENT->intCheck($spacing, 0, 10)) {
5384  
5385 $self->ivPoke('currentSpacing', $spacing);
5386 }
5387  
5388 $border = $self->ivShow('initHash', 'border');
5389 if (defined $border && $axmud::CLIENT->intCheck($border, 0, 10)) {
5390  
5391 $self->ivPoke('currentBorder', $border);
5392 }
5393  
5394 # Create a packing box (a scroller rather than a VBox/HBox, in this case)
5395 my $scroller = Gtk3::ScrolledWindow->new();
5396 $scroller->set_policy('automatic', 'automatic');
5397  
5398 # Create a Gtk3::Grid
5399 my $grid = Gtk3::Grid->new();
5400 $scroller->add_with_viewport($grid);
5401 $grid->set_border_width($border);
5402 $grid->set_column_spacing(0);
5403 $grid->set_row_spacing(0);
5404  
5405 # Update IVs
5406 $self->ivPoke('packingBox', $scroller);
5407 $self->ivPoke('table', $grid);
5408 $self->ivPoke('tableSize', $winmapObj->tableSize);
5409  
5410 return 1;
5411 }
5412  
5413 sub objDestroy {
5414  
5415 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
5416 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
5417 # to do any necessary tidying up
5418 #
5419 # Expected arguments
5420 # (none besides $self)
5421 #
5422 # Return values
5423 # 'undef' on improper arguments
5424 # 1 otherwise
5425  
5426 my ($self, $check) = @_;
5427  
5428 # Check for improper arguments
5429 if (defined $check) {
5430  
5431 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
5432 }
5433  
5434 # No tidying up required for this type of strip object, but we do call the same function for
5435 # any table objects
5436 foreach my $tableObj ($self->ivValues('tableObjHash')) {
5437  
5438 $tableObj->objDestroy();
5439 }
5440  
5441 return 1;
5442 }
5443  
5444 sub setWidgetsIfSession {
5445  
5446 # Called by GA::Win::Internal->setWidgetsIfSession
5447 # Allows this strip object to sensitise or desensitise its widgets, depending on whether
5448 # the parent window has a ->visibleSession at the moment
5449 # (NB Only 'main' windows have a ->visibleSession; for other 'grid' windows, the flag
5450 # argument will be FALSE)
5451 #
5452 # Expected arguments
5453 # $flag - TRUE if the parent window has a visible session, FALSE if not
5454 #
5455 # Return values
5456 # 'undef' on improper arguments
5457 # 1 otherwise
5458  
5459 my ($self, $flag, $check) = @_;
5460  
5461 # Check for improper arguments
5462 if (! defined $flag || defined $check) {
5463  
5464 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
5465 }
5466  
5467 # Pass on the message to every table object
5468 foreach my $tableObj ($self->ivValues('tableObjHash')) {
5469  
5470 $tableObj->setWidgetsIfSession($flag);
5471 }
5472  
5473 return 1;
5474 }
5475  
5476 sub setWidgetsChangeSession {
5477  
5478 # Called by GA::Win::Internal->setWidgetsChangeSession
5479 # Allows this strip object to update its widgets whenever the visible session in any 'main'
5480 # window changes
5481 #
5482 # Expected arguments
5483 # (none besides $self)
5484 #
5485 # Return values
5486 # 'undef' on improper arguments
5487 # 1 otherwise
5488  
5489 my ($self, $check) = @_;
5490  
5491 # Check for improper arguments
5492 if (defined $check) {
5493  
5494 return $axmud::CLIENT->writeImproper(
5495 $self->_objClass . '->setWidgetsChangeSession',
5496 @_,
5497 );
5498 }
5499  
5500 # Pass on the message to every table object
5501 foreach my $tableObj ($self->ivValues('tableObjHash')) {
5502  
5503 $tableObj->setWidgetsChangeSession();
5504 }
5505  
5506 return 1;
5507 }
5508  
5509 # ->signal_connects
5510  
5511 # Other functions
5512  
5513 sub addTableObj {
5514  
5515 # Called by GA::Win::Internal->drawWidgets or any other code
5516 # Adds a table object (inheriting GA::Generic::Table) to this strip object's Gtk3::Grid
5517 #
5518 # Expected arguments
5519 # $packageName
5520 # - The package name of the table object to add, e.g. 'Games::Axmud::Table::Pane'
5521 # $left, $right, $top, $bottom
5522 # - The coordinates of the top-left ($left, $top) and bottom-right ($right, $bottom)
5523 # corners of the table object on the table
5524 #
5525 # Optional arguments
5526 # $objName
5527 # - An optional name to give to the table object, when it is created. If not
5528 # specified, the table object's ->objName is given the same value as its ->number.
5529 # If specified, $objName can be any string (avoid using short strings or numbers.
5530 # No part of the code checks that table object names are unique; if two or more
5531 # table objects share the same ->objName, usually the one with the lowest ->number
5532 # 'wins')
5533 # %initHash
5534 # - A hash containing arbitrary data to use as the table object's initialisation
5535 # settings. The table object should use default initialisation settings unless it
5536 # can succesfully interpret one or more of the key-value pairs in the hash, if
5537 # there are any
5538 #
5539 # Return values
5540 # 'undef' on improper arguments, if the specified space on the table is invalid or already
5541 # occupied by a tablezone, or if the table object can't be created
5542 # Otherwise returns the blessed reference to the new table object
5543  
5544 my ($self, $packageName, $left, $right, $top, $bottom, $objName, %initHash) = @_;
5545  
5546 # Local variables
5547 my ($string, $zoneObj, $tableObj);
5548  
5549 # Check for improper arguments
5550 if (
5551 ! defined $packageName || ! defined $left || ! defined $right || ! defined $top
5552 || ! defined $bottom
5553 ) {
5554 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTableObj', @_);
5555 }
5556  
5557 # Table objects must inherit from GA::Generic::Table and must exist (in the case of table
5558 # objects loaded from a plugin)
5559 if (
5560 ! $packageName =~ m/^Games\:\:Axmud\:\:Table\:\:/
5561 || ! $axmud::CLIENT->ivExists('customTableHash', $packageName)
5562 ) {
5563 if ($axmud::CLIENT->debugTableFitFlag) {
5564  
5565 $self->writeError(
5566 'Unrecognised table object package \'' . $packageName . '\'',
5567 $self->_objClass . '->addTableObj',
5568 )
5569 }
5570  
5571 return undef;
5572 }
5573  
5574 # Check that the specified area is not outside the bounds of the table
5575 $string = '(X ' . $left . '-' . $right . ', Y ' . $top . '-' . $bottom . ')';
5576 if (
5577 $left < 0 || $right <= $left || $right >= $self->tableSize
5578 || $top < 0 || $bottom <= $top || $bottom >= $self->tableSize
5579 ) {
5580 if ($axmud::CLIENT->debugTableFitFlag) {
5581  
5582 $self->writeError(
5583 'Specified area ' . $string . ' is outside the bounds of the table',
5584 $self->_objClass . '->addTableObj',
5585 )
5586 }
5587  
5588 return undef;
5589 }
5590  
5591 # Check that the specified area on the table is not already occupied by a tablezone
5592 foreach my $otherZoneObj ($self->ivValues('tablezoneHash')) {
5593  
5594 if (
5595 (
5596 ($left >= $otherZoneObj->left && $left <= $otherZoneObj->right)
5597 || ($right >= $otherZoneObj->left && $right <= $otherZoneObj->right)
5598 ) && (
5599 ($top >= $otherZoneObj->top && $top <= $otherZoneObj->bottom)
5600 || ($bottom >= $otherZoneObj->top && $bottom <= $otherZoneObj->bottom)
5601 )
5602 ) {
5603 if ($axmud::CLIENT->debugTableFitFlag) {
5604  
5605 $self->writeError(
5606 'Specified area ' . $string . ' is occupied by an existing table object',
5607 $self->_objClass . '->addTableObj',
5608 )
5609 }
5610  
5611 return undef;
5612 }
5613 }
5614  
5615 # Create a tablezone, which marks out an area on the Gtk3::Grid as being in use by a single
5616 # table object
5617 $zoneObj = Games::Axmud::Obj::Tablezone->new(
5618 $self->tablezoneCount,
5619 $packageName,
5620 $left,
5621 $top,
5622 $right,
5623 $bottom,
5624 );
5625  
5626 if (! $zoneObj) {
5627  
5628 if ($axmud::CLIENT->debugTableFitFlag) {
5629  
5630 $self->writeError(
5631 'Could not allocate space for the table object at the specified position '
5632 . $string,
5633 $self->_objClass . '->addTableObj',
5634 )
5635 }
5636  
5637 return undef;
5638 }
5639  
5640 # If no $objName was specified, the table object's ->objName IV is the same as its ->number
5641 # IV
5642 if (! defined $objName || $objName eq '') {
5643  
5644 $objName = $self->tableObjCount;
5645 }
5646  
5647 # Create table object
5648 $tableObj = $packageName->new($self->tableObjCount, $objName, $self, $zoneObj, %initHash);
5649 if (! $tableObj) {
5650  
5651 if ($axmud::CLIENT->debugTableFitFlag) {
5652  
5653 $self->writeError(
5654 'Failed to create table object',
5655 $self->_objClass . '->addTableObj',
5656 )
5657 }
5658  
5659 return undef;
5660 }
5661  
5662 # Set up the table object's widgets
5663 if (! $tableObj->objEnable()) {
5664  
5665 if ($axmud::CLIENT->debugTableFitFlag) {
5666  
5667 $self->writeError(
5668 'Failed to set up the table object\'s widgets',
5669 $self->_objClass . '->addTableObj',
5670 )
5671 }
5672  
5673 return undef;
5674 }
5675  
5676 $self->table->attach(
5677 $tableObj->packingBox,
5678 $zoneObj->left,
5679 $zoneObj->top,
5680 # Axmud uses 59,59, but Gtk expects 60,60
5681 ($zoneObj->right - $zoneObj->left + 1),
5682 ($zoneObj->bottom - $zoneObj->top + 1),
5683 );
5684  
5685 # Update IVs
5686 $self->ivAdd('tablezoneHash', $zoneObj->number, $zoneObj);
5687 $self->ivIncrement('tablezoneCount');
5688 $self->ivAdd('tableObjHash', $tableObj->number, $tableObj);
5689 $self->ivIncrement('tableObjCount');
5690  
5691 # Cannot call $self->table->set_column_spacing(), etc, as that would add spacing to all
5692 # 60 columns (etc). Instead, add a border area around the table widget
5693 # In certain circumstances, approve the aesthetics by not using a border at all
5694 if (
5695 $self->ivPairs('tableObjHash') < 2
5696 && (
5697 $self->winObj->winType eq 'main'
5698 || $self->winObj->ivPairs('stripHash') < 2
5699 )
5700 ) {
5701 $tableObj->packingBox->set_border_width(0);
5702 } else {
5703 $tableObj->packingBox->set_border_width($self->currentSpacing);
5704 }
5705  
5706 # Notify all of this window's strip objects of the new table object's birth
5707 foreach my $stripObj (
5708 sort {$a->number <=> $b->number} ($self->winObj->ivValues('stripHash'))
5709 ) {
5710 $stripObj->notify_addTableObj($tableObj);
5711 }
5712  
5713 # Notify all of this strip's table objects of the new table object's birth
5714 foreach my $otherTableObj (
5715 sort {$a->number <=> $b->number} ($self->ivValues('tableObjHash'))
5716 ) {
5717 if ($otherTableObj ne $tableObj) {
5718  
5719 $otherTableObj->notify_addTableObj($tableObj);
5720 }
5721 }
5722  
5723 return $tableObj;
5724 }
5725  
5726 sub removeTableObj {
5727  
5728 # Can be called by anything
5729 # Removes a table object (inheriting GA::Generic::Table) from this strip object's Gtk3::Grid
5730 #
5731 # Expected arguments
5732 # $tableObj - The table object to remove
5733 #
5734 # Return values
5735 # 'undef' on improper arguments, if the table object is protected from removal or if the
5736 # table object no longer exists on this strip
5737 # 1 otherwise
5738  
5739 my ($self, $tableObj, $check) = @_;
5740  
5741 # Local variables
5742 my ($existFlag, $matchFlag, $count);
5743  
5744 # Check for improper arguments
5745 if (! defined $tableObj || defined $check) {
5746  
5747 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeTableObj', @_);
5748 }
5749  
5750 # Don't remove the table object if it's protected
5751 if (! $tableObj->allowRemoveFlag) {
5752  
5753 if ($axmud::CLIENT->debugTableFitFlag) {
5754  
5755 $self->writeError(
5756 'Can\'t remove table object \'' . $tableObj->type . '\' as it is protected',
5757 $self->_objClass . '->removeTableObj',
5758 )
5759 }
5760  
5761 return undef;
5762 }
5763  
5764 # Check the table object still exists on this strip
5765 OUTER: foreach my $obj ($self->ivValues('tableObjHash')) {
5766  
5767 if ($obj eq $tableObj) {
5768  
5769 $existFlag = TRUE;
5770 last OUTER;
5771 }
5772 }
5773  
5774 if (! $existFlag) {
5775  
5776 if ($axmud::CLIENT->debugTableFitFlag) {
5777  
5778 $self->writeError(
5779 'Specified table object doesn\'t exist (or no longer exists)',
5780 $self->_objClass . '->removeTableObj',
5781 )
5782 }
5783  
5784 return undef;
5785 }
5786  
5787  
5788 # Remove the table object
5789 $axmud::CLIENT->desktopObj->removeWidget($self->table, $tableObj->packingBox);
5790  
5791 # Update IVs
5792 $self->ivDelete('tableObjHash', $tableObj->number);
5793 $self->ivDelete('tablezoneHash', $tableObj->zoneObj->number);
5794  
5795 # Notify all of this window's strip objects of the table object's demise
5796 foreach my $stripObj (
5797 sort {$a->number <=> $b->number} ($self->winObj->ivValues('stripHash'))
5798 ) {
5799 $stripObj->notify_removeTableObj($tableObj);
5800 }
5801  
5802 # Notify all of this strip's table objects of the table object's demise
5803 foreach my $otherTableObj (
5804 sort {$a->number <=> $b->number} ($self->ivValues('tableObjHash'))
5805 ) {
5806 if ($otherTableObj ne $tableObj) {
5807  
5808 $otherTableObj->notify_removeTableObj($tableObj);
5809 }
5810 }
5811  
5812 return 1;
5813 }
5814  
5815 sub removeAllTableObjs {
5816  
5817 # Can be called by anything
5818 # Removes all table objects (inheriting GA::Generic::Table) from this strip object's
5819 # Gtk3::Grid
5820 #
5821 # Expected arguments
5822 # (none besides $self)
5823 #
5824 # Return values
5825 # 'undef' on improper arguments or if any of the removal operations fail
5826 # Otherwise returns the number of objects removed (may be zero)
5827  
5828 my ($self, $check) = @_;
5829  
5830 # Local variables
5831 my ($count, $failFlag);
5832  
5833 # Check for improper arguments
5834 if (defined $check) {
5835  
5836 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeAllTableObjs', @_);
5837 }
5838  
5839 # Remove all table objects
5840 $count = 0;
5841 foreach my $tableObj (
5842 sort {$a->number <=> $b->number} ($self->ivValues('tableObjHash'))
5843 ) {
5844 if (! $self->removeTableObj($tableObj)) {
5845 $failFlag = TRUE;
5846 } else {
5847 $count++;
5848 }
5849 }
5850  
5851 if ($failFlag) {
5852 return undef;
5853 } else {
5854 return $count;
5855 }
5856 }
5857  
5858 sub resizeTableObj {
5859  
5860 # Can be called by anything
5861 # Resizes a table object (inheriting GA::Generic::Table) on this strip object's Gtk3::Grid
5862 #
5863 # Expected arguments
5864 # $tableObj - The table object to resize
5865 # $left, $right, $top, $bottom
5866 # - The coordinates of the top-left ($left, $top) and bottom-right ($right, $bottom)
5867 # corners of the table object on the table
5868 #
5869 # Return values
5870 # 'undef' on improper arguments, if the table object is protected from resizing, if the
5871 # table object no longer exists on this strip, if the specified space on the table is
5872 # invalid or already occupied by a tablezone, or if the resize operation fails
5873 # 1 otherwise
5874  
5875 my ($self, $tableObj, $left, $right, $top, $bottom, $check) = @_;
5876  
5877 # Local variables
5878 my ($flag, $string, $zoneObj);
5879  
5880 # Check for improper arguments
5881 if (
5882 ! defined $tableObj || ! defined $left || ! defined $right || ! defined $top
5883 || ! defined $bottom || defined $check
5884 ) {
5885 return $axmud::CLIENT->writeImproper($self->_objClass . '->resizeTableObj', @_);
5886 }
5887  
5888 # Don't resize the table object if it's protected
5889 if (! $tableObj->allowResizeFlag) {
5890  
5891 if ($axmud::CLIENT->debugTableFitFlag) {
5892  
5893 $self->writeError(
5894 'Can\'t resize table object \'' . $tableObj->type . '\' as it is protected',
5895 $self->_objClass . '->resizeTableObj',
5896 )
5897 }
5898  
5899 return undef;
5900 }
5901  
5902 # Check the table object still exists on this strip
5903 OUTER: foreach my $obj ($self->ivValues('tableObjHash')) {
5904  
5905 if ($obj eq $tableObj) {
5906  
5907 $flag = TRUE;
5908 last OUTER;
5909 }
5910 }
5911  
5912 if (! $flag) {
5913  
5914 if ($axmud::CLIENT->debugTableFitFlag) {
5915  
5916 $self->writeError(
5917 'Specified table object doesn\'t exist (or no longer exists)',
5918 $self->_objClass . '->resizeTableObj',
5919 )
5920 }
5921  
5922 return undef;
5923 }
5924  
5925 # Check that the specified area is not outside the bounds of the table
5926 $string = '(X ' . $left . '-' . $right . ', Y ' . $top . '-' . $bottom . ')';
5927 if (
5928 $left < 0 || $right <= $left || $right >= $self->tableSize
5929 || $top < 0 || $bottom <= $top || $bottom >= $self->tableSize
5930 ) {
5931 if ($axmud::CLIENT->debugTableFitFlag) {
5932  
5933 $self->writeError(
5934 'Specified area ' . $string . ' is outside the bounds of the table',
5935 $self->_objClass . '->resizeTableObj',
5936 )
5937 }
5938  
5939 return undef;
5940 }
5941  
5942 # Check that the specified space on the table is not already occupied by a tablezone
5943 foreach my $otherZoneObj ($self->ivValues('tablezoneHash')) {
5944  
5945 if (
5946 $tableObj->zoneObj ne $otherZoneObj
5947 && (
5948 ($left >= $otherZoneObj->left && $left <= $otherZoneObj->right)
5949 || ($right >= $otherZoneObj->left && $right <= $otherZoneObj->right)
5950 ) && (
5951 ($top >= $otherZoneObj->top && $top <= $otherZoneObj->bottom)
5952 || ($bottom >= $otherZoneObj->top && $bottom <= $otherZoneObj->bottom)
5953 )
5954 ) {
5955 if ($axmud::CLIENT->debugTableFitFlag) {
5956  
5957 $self->writeError(
5958 'Specified area ' . $string . ' is occupied by an existing table object',
5959 $self->_objClass . '->resizeTableObj',
5960 )
5961 }
5962  
5963 return undef;
5964 }
5965 }
5966  
5967 # Remove the old tablezone...
5968 $self->ivDelete('tablezoneHash', $tableObj->zoneObj->number);
5969  
5970 # ...and create a new one, assigning it to the table object
5971 $zoneObj = Games::Axmud::Obj::Tablezone->new(
5972 $self->tablezoneCount,
5973 $tableObj->_objClass,
5974 $left,
5975 $top,
5976 $right,
5977 $bottom,
5978 );
5979  
5980 if (! $zoneObj) {
5981  
5982 if ($axmud::CLIENT->debugTableFitFlag) {
5983  
5984 $self->writeError(
5985 'Could not allocate space for the table object at the specified position '
5986 . $string,
5987 $self->_objClass . '->resizeTableObj',
5988 )
5989 }
5990  
5991 return undef;
5992  
5993 } else {
5994  
5995 $self->ivAdd('tablezoneHash', $zoneObj->number, $zoneObj);
5996 $self->ivIncrement('tablezoneCount');
5997  
5998 $tableObj->set_zoneObj($zoneObj);
5999 }
6000  
6001 # Resize the table object
6002 $axmud::CLIENT->desktopObj->removeWidget($self->table, $tableObj->packingBox);
6003  
6004 $self->table->attach(
6005 $tableObj->packingBox,
6006 $zoneObj->left,
6007 $zoneObj->top,
6008 # Axmud uses 59,59, but Gtk expects 60,60
6009 ($zoneObj->right - $zoneObj->left + 1),
6010 ($zoneObj->bottom - $zoneObj->top + 1),
6011 );
6012  
6013 # Inform the table object that it's been resized
6014 $tableObj->setWidgetsOnResize(
6015 $zoneObj->left,
6016 $zoneObj->right,
6017 $zoneObj->top,
6018 $zoneObj->bottom,
6019 );
6020  
6021 return 1;
6022 }
6023  
6024 sub replaceHolder {
6025  
6026 # Called by any code
6027 # Looks for a holder table object (GA::Table::Holder) with a specified ->id. If one is
6028 # found, removes it and adds a different table object using the same size/position. If
6029 # one is not found, returns 'undef'
6030 # (The calling code can call this function as often as it needs to, looking for various
6031 # holders, and if none are found, can then call $self->addTableObj directly)
6032 #
6033 # Expected arguments
6034 # $id - The holder ID; can be any non-empty string. If any holders have an ->id with this
6035 # value, that is replaced. Values might include types of 'grid' window such as
6036 # 'map', or 'task' for task windows in general, or 'status_task' for the Status
6037 # task in particular. If not specified, 'undef' or an empty string, 'task' is
6038 # used as a default value
6039 # $packageName
6040 # - The package name of the replacement table object, e.g. GA::Table::Pane
6041 #
6042 # Optional arguments
6043 # $objName
6044 # - An optional name to give to the replacement table object, when it is created. If
6045 # not specified, the table object's ->objName is given the same value as its
6046 # ->number. If specified, $objName can be any string (avoid using short strings or
6047 # numbers. No part of the code checks that table object names are unique; if two
6048 # or more table objects share the same ->objName, usually the one with the lowest
6049 # ->number 'wins')
6050 # %initHash
6051 # - A hash containing arbitrary data to use as the table object's initialisation
6052 # settings. The table object should use default initialisation settings unless it
6053 # can succesfully interpret one or more of the key-value pairs in the hash, if
6054 # there are any
6055 #
6056 # Return values
6057 # 'undef' on improper arguments, if no holders with a matching ->id are found or if the
6058 # replacement table object can't be created
6059 # Otherwise returns the blessed reference to the replacement table object
6060  
6061 my ($self, $id, $packageName, $objName, %initHash) = @_;
6062  
6063 # Check for improper arguments
6064 if (! defined $id || ! defined $packageName) {
6065  
6066 return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceHolder', @_);
6067 }
6068  
6069 foreach my $tableObj (sort {$a->number <=> $b->number} ($self->ivValues('tableObjHash'))) {
6070  
6071 if (
6072 $tableObj->type eq 'holder'
6073 && $tableObj->id
6074 && $tableObj->id eq $id
6075 ) {
6076 # Matching holder found. Remove it from the table
6077 if (! $self->removeTableObj($tableObj)) {
6078  
6079 if ($axmud::CLIENT->debugTableFitFlag) {
6080  
6081 $self->writeError(
6082 'Could not replace holder table object due to internal error',
6083 $self->_objClass . '->replaceHolder',
6084 )
6085 }
6086  
6087 return undef;
6088 }
6089  
6090 # Add the replacement table object
6091 return $self->addTableObj(
6092 $packageName,
6093 $tableObj->zoneObj->left,
6094 $tableObj->zoneObj->right,
6095 $tableObj->zoneObj->top,
6096 $tableObj->zoneObj->bottom,
6097 $objName,
6098 %initHash,
6099 );
6100 }
6101 }
6102  
6103 # No matching holder found
6104 if ($axmud::CLIENT->debugTableFitFlag) {
6105  
6106 $self->writeError(
6107 'Could not replace holder table object - no matching holder found',
6108 $self->_objClass . '->replaceHolder',
6109 )
6110 }
6111  
6112 return undef;
6113 }
6114  
6115 sub findPosn {
6116  
6117 # The parent window's winmap (GA::Obj::Winmap) specified a default size for new table
6118 # objects, added to this strip object after its creation
6119 # This function checks the table, looking for an unoccupied space of the right size. If a
6120 # space is found, the calling function can then call $self->addTableObj to create a
6121 # table object in that space
6122 #
6123 # Expected arguments
6124 # (none besides $self)
6125 #
6126 # Return values
6127 # An empty list on improper arguments
6128 # Otherwise, returns a list in the form
6129 # (left, right, top, bottom)
6130 # ...matching the table coordinates that can be used in the subsequent call to
6131 # $self->addTableObj
6132  
6133 my ($self, $check) = @_;
6134  
6135 # Local variables
6136 my (
6137 $winmapObj, $width, $height,
6138 @emptyList,
6139 );
6140  
6141 # Check for improper arguments
6142 if (defined $check) {
6143  
6144 $axmud::CLIENT->writeImproper($self->_objClass . '->findPosn', @_);
6145 return @emptyList;
6146 }
6147  
6148 # Get the parent window's winmap and, from that, get the default size
6149 if ($self->winObj->winmap) {
6150  
6151 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $self->winObj->winmap);
6152 if ($winmapObj) {
6153  
6154 $width = $winmapObj->zoneWidth;
6155 $height = $winmapObj->zoneHeight;
6156 }
6157 }
6158  
6159 if (! defined $width) {
6160  
6161 # (Most standard winmaps use 30x30)
6162 $width = 30;
6163 $height = 30;
6164 }
6165  
6166 # Search left-to-right, then top-to-bottom
6167 OUTER: for (my $top = 0; $top < $self->tableSize; $top += $height) {
6168  
6169 INNER: for (my $left = 0; $left < $self->tableSize; $left += $width) {
6170  
6171 my ($right, $bottom);
6172  
6173 $right = $left + $width - 1;
6174 $bottom = $top + $height - 1;
6175  
6176 # Check that the specified position on the table is not already occupied by a
6177 # tablezone
6178 foreach my $zoneObj ($self->ivValues('tablezoneHash')) {
6179  
6180 if (
6181 (
6182 ($left >= $zoneObj->left && $left <= $zoneObj->right)
6183 || ($right >= $zoneObj->left && $right <= $zoneObj->right)
6184 ) && (
6185 ($top >= $zoneObj->top && $top <= $zoneObj->bottom)
6186 || ($bottom >= $zoneObj->top && $bottom <= $zoneObj->bottom)
6187 )
6188 ) {
6189 # This position is occupied
6190 next INNER;
6191 }
6192 }
6193  
6194 # This position is free
6195 return ($left, $right, $top, $bottom);
6196 }
6197 }
6198  
6199 # All positions are occupied
6200 return @emptyList;
6201 }
6202  
6203 sub getPosn {
6204  
6205 # Can be called by anything
6206 # Returns the size and position of an existing table object
6207 #
6208 # Expected arguments
6209 # $tableObj - An existing table object
6210 #
6211 # Return values
6212 # An empty list on improper arguments or if the table object doesn't exist in this strip
6213 # object's table
6214 # Otherwise, returns a list in the form
6215 # (left, right, top, bottom)
6216  
6217 my ($self, $tableObj, $check) = @_;
6218  
6219 # Local variables
6220 my (
6221 $zoneObj,
6222 @emptyList,
6223 );
6224  
6225 # Check for improper arguments
6226 if (! defined $tableObj || defined $check) {
6227  
6228 $axmud::CLIENT->writeImproper($self->_objClass . '->getPosn', @_);
6229 return @emptyList;
6230 }
6231  
6232 # Check the table object exists on this strip object's table, and get the corresponding
6233 # tablezone object (GA::Obj::Tablezone)
6234 if (
6235 ! $self->ivExists('tableObjHash', $tableObj->number)
6236 || $self->ivShow('tableObjHash', $tableObj->number) ne $tableObj
6237 ) {
6238 return @emptyList;
6239  
6240 } else {
6241  
6242 $zoneObj = $self->ivShow('tablezoneHash', $tableObj->number);
6243  
6244 return ($zoneObj->left, $zoneObj->right, $zoneObj->top, $zoneObj->bottom);
6245 }
6246 }
6247  
6248 sub changeSpacing {
6249  
6250 # Can be called by anything to update the spacing around table objects. The same spacing is
6251 # added around future table objects, as they added
6252 #
6253 # Expected arguments
6254 # $spacing - The new spacing (should be an integer, 0 or above)
6255 #
6256 # Return values
6257 # 'undef' on improper arguments
6258 # 1 otherwise
6259  
6260 my ($self, $spacing, $check) = @_;
6261  
6262 # Check for improper arguments
6263 if (! defined $spacing || defined $check) {
6264  
6265 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeSpacing', @_);
6266 }
6267  
6268 if (! ($spacing =~ m/\D/) && $spacing >= 0) {
6269  
6270 $self->ivPoke('currentSpacing', $spacing);
6271 foreach my $tableObj ($self->ivValues('tableObjHash')) {
6272  
6273 $tableObj->packingBox->set_border_width($spacing);
6274 }
6275 }
6276  
6277 return 1;
6278 }
6279  
6280 sub changeBorder {
6281  
6282 # Can be called by anything to update the border around the edge of the table
6283 #
6284 # Expected arguments
6285 # $border - The new border (should be an integer, 0-10)
6286 #
6287 # Return values
6288 # 'undef' on improper arguments
6289 # 1 otherwise
6290  
6291 my ($self, $border, $check) = @_;
6292  
6293 # Check for improper arguments
6294 if (! defined $border || defined $check) {
6295  
6296 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeBorder', @_);
6297 }
6298  
6299 if (! ($border =~ m/\D/) && $border >= 0 && $border <= 10) {
6300  
6301 $self->ivPoke('currentBorder', $border);
6302 $self->table->set_border_width($border);
6303 }
6304  
6305 return 1;
6306 }
6307  
6308 ##################
6309 # Accessors - set
6310  
6311 ##################
6312 # Accessors - get
6313  
6314 sub table
6315 { $_[0]->{table} }
6316  
6317 sub tableSize
6318 { $_[0]->{tableSize} }
6319  
6320 sub tablezoneHash
6321 { my $self = shift; return %{$self->{tablezoneHash}}; }
6322 sub tablezoneCount
6323 { $_[0]->{tablezoneCount} }
6324 sub tableObjHash
6325 { my $self = shift; return %{$self->{tableObjHash}}; }
6326 sub tableObjCount
6327 { $_[0]->{tableObjCount} }
6328  
6329 sub currentSpacing
6330 { $_[0]->{currentSpacing} }
6331 sub currentBorder
6332 { $_[0]->{currentBorder} }
6333 }
6334  
6335 { package Games::Axmud::Strip::GaugeBox;
6336  
6337 use strict;
6338 use warnings;
6339 # use diagnostics;
6340  
6341 use Glib qw(TRUE FALSE);
6342  
6343 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
6344  
6345 ##################
6346 # Constructors
6347  
6348 sub new {
6349  
6350 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
6351 # Creates the GA::Strip::GaugeBox - a non-compulsory strip object optionally containing one
6352 # or more gauge levels (or none, when this strip object is marked not visible)
6353 #
6354 # Expected arguments
6355 # $number - The strip object's number within the parent window (matches
6356 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
6357 # created to access its default IVs)
6358 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
6359 # objects
6360 #
6361 # Optional arguments
6362 # %initHash - A hash containing arbitrary data to use as the strip object's
6363 # initialisation settings. The strip object should use default
6364 # initialisation settings unless it can succesfully interpret one or more
6365 # of the key-value pairs in the hash, if there are any
6366 # - (This type of strip object requires no initialisation settings)
6367 #
6368 # Return values
6369 # 'undef' on improper arguments
6370 # Blessed reference to the newly-created object on success
6371  
6372 my ($class, $number, $winObj, %initHash) = @_;
6373  
6374 # Local variables
6375 my %modHash;
6376  
6377 # Check for improper arguments
6378 if (! defined $class || ! defined $number || ! defined $winObj) {
6379  
6380 return $axmud::CLIENT->writeImproper($class . '->new', @_);
6381 }
6382  
6383 # Setup
6384 my $self = {
6385 _objName => 'strip_' . $number,
6386 _objClass => $class,
6387 _parentFile => undef, # No parent file object
6388 _parentWorld => undef, # No parent file object
6389 _privFlag => TRUE, # All IVs are private
6390  
6391 # Standard strip object IVs
6392 # -------------------------
6393  
6394 # The strip object's number within the parent window (matches
6395 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
6396 # its default IVs)
6397 number => $number,
6398 # The type of strip object (custom strip objects should use a ->type starting with
6399 # 'custom_' to avoid clashing with future built-in strip objects)
6400 type => 'gauge_box',
6401 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
6402 winObj => $winObj,
6403  
6404 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
6405 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
6406 # still exists in GA::Win::Internal->stripHash, etc)
6407 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
6408 # have gauges to draw, or not, depending on current conditions. (Most strip objects
6409 # have this flag set to TRUE all the time)
6410 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
6411 # called by this object's functions
6412 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
6413 # the flag's value shouldn't be modified by anything other than
6414 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
6415 # $self->set_visibleFlag)
6416 visibleFlag => FALSE, # Wait until the first gauge is drawn
6417 # Flag set to TRUE is the strip object should be given its share of any extra space
6418 # within the packing box (the extra space is divided equally between all children of
6419 # the box whose ->expandFlag is TRUE)
6420 expandFlag => FALSE,
6421 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
6422 # actually allocated within the strip object, FALSE if it is used as padding outside
6423 # it (on both sides)
6424 fillFlag => TRUE, # Force canvas to use available width
6425 # Flag set to TRUE if the strip object should be packed into its window with a small
6426 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
6427 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
6428 # for example in the toolbar strip object)
6429 spacingFlag => TRUE,
6430 # Flag set to TRUE if only one instance of this strip object should be added to the
6431 # parent window, set to FALSE if any number of instances can be added
6432 jealousyFlag => TRUE,
6433 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
6434 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
6435 # users)
6436 blindFlag => FALSE,
6437 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
6438 # allowed to accept the focus, FALSE if not. The restriction is applied during the
6439 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
6440 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
6441 # GA::Strip::MenuBar)
6442 allowFocusFlag => FALSE,
6443  
6444 # Initialisation settings stored as a hash (see the comments above)
6445 initHash => \%modHash,
6446 # Reference to a function to call when some widget is used. This IV is set only when
6447 # required by this type of strip object. It can be set by a call to
6448 # $self->set_func() or by some setting in $self->initHash, which is applied in the
6449 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
6450 # generic object function Games::Axmud->getMethodRef()
6451 funcRef => undef,
6452 # A value passed to ->funcRef when it is called which identifies this strip object and
6453 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
6454 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
6455 # to $self->objEnable()
6456 funcID => undef,
6457  
6458 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
6459 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
6460 packingBox => undef, # Gtk3::VBox
6461  
6462 # Other IVs
6463 # ---------
6464  
6465 # Widgets
6466 frame => undef, # Gtk3::Frame
6467 canvas => undef, # GooCanvas2::Canvas
6468 # A list of GooCanvas2::CanvasRect and GooCanvas2::CanvasText objects drawn in the gauge
6469 # box, which are destroyed every time $self->drawGauges is called
6470 gaugeCanvasList => [], # GooCanvas2::CanvasRect/::CanvasText
6471  
6472 # The size of the available area inside the frame containing the canvas, set whenever
6473 # the frame's size-allocate signal is emitted (this is the only way to guarantee that
6474 # that the correct size is available to $self->drawGauges)
6475 canvasFrameWidth => 1,
6476 canvasFrameHeight => 1,
6477  
6478 # The size of the GooCanvas2::Canvas used to display gauges (width is the same as the
6479 # available space, so only height specified here)
6480 # The height (in pixels) of gauges. The total height of the gauge will be this value,
6481 # plus the spacing above and below it. (Width is the same as the available space, so
6482 # only height specified here)
6483 gaugeHeight => 16,
6484 # The size of the rounded corner (in pixels)
6485 gaugeCorner => 5,
6486 # Spacing (padding) used between the gauges, and between the edges of the gauge box
6487 gaugeSpacingX => 8,
6488 gaugeSpacingY => 4,
6489 # The font and size to use for gauge labels. These default values produce a font that's
6490 # about the right the size for a gauge of height $self->gaugeHeight
6491 gaugeLabelFont => 'Monospace',
6492 gaugeLabelFontSize => 10,
6493 # Registry hash of GA::Obj::GaugeLevel objects, one for each gauge level drawn in the
6494 # gauge box for a single session
6495 # Hash in the form
6496 # $gaugeLevelHash{unique_number} = gauge_level_object
6497 # ...where 'unique_number' is unique across all sessions
6498 gaugeLevelHash => {},
6499 # The number of gauge levels ever created (used to provide the unique number)
6500 gaugeLevelCount => 0,
6501 # Maximum number of gauge levels (sanity check)
6502 gaugeLevelMax => 8,
6503 # Number of GA::Obj::Gauge objects ever created (used to give each object a unique
6504 # number)
6505 gaugeCount => 0,
6506 # Maximum number of gauges per level (sanity check)
6507 gaugeMax => 10,
6508 # A list of GA::Obj::Gauge objects that were drawn, the last time $self->updateGauges
6509 # was called (may be an empty list)
6510 gaugeDrawnList => [],
6511 # Calls to $self->updateGauges should be allowed to finish, before another call to
6512 # the same function is allowed. This flag is set to TRUE at the beginning of a call,
6513 # and FALSE at the end of it
6514 gaugeUpdateFlag => FALSE,
6515 # Colour used to draw blank gauges
6516 gaugeBlankColour => '#CDCDBA',
6517 # Default colour for the empty portion of gauges
6518 gaugeEmptyColour => '#000000',
6519 # Default colour used for the full portion of gauges
6520 gaugeFullColour => '#FFFFFF',
6521 # Default colour used for gauge labels
6522 gaugeLabelColour => '#FF0000',
6523 # Colour (always) used to draw the borders of gauges
6524 gaugeBorderColour => '#000000',
6525 # When the last gauge is removed, we should wait a few seconds before removing the
6526 # gauge box entirely. For example, if the Status task resets, its gauges are
6527 # removed for a moment, and re-drawn as soon as the task is ready
6528 # If defined, the time (matches GA::Client->clientTime) at which the gauge box should
6529 # be removed, if no new gauges have been drawn in the mean time
6530 gaugeCheckTime => undef,
6531 # The time to wait (in seconds)
6532 gaugeWaitTime => 1,
6533 # When $self->addGaugeLevel is called with the no-redraw flag set to TRUE, this flag is
6534 # set to TRUE. Then, the next time $self->updateGauges is called, that function knows
6535 # that it needs to call $self->replaceStripObj to redraw the gauge box. (This flag is
6536 # then set back to FALSE)
6537 gaugeNoDrawFlag => FALSE,
6538 };
6539  
6540 # Bless the object into existence
6541 bless $self, $class;
6542  
6543 return $self;
6544 }
6545  
6546 ##################
6547 # Methods
6548  
6549 # Standard strip object functions
6550  
6551 sub objEnable {
6552  
6553 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
6554 # Sets up the strip object's widgets
6555 #
6556 # Expected arguments
6557 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
6558 # parent window
6559 #
6560 # Return values
6561 # 'undef' on improper arguments
6562 # 1 on success
6563  
6564 my ($self, $winmapObj, $check) = @_;
6565  
6566 # Check for improper arguments
6567 if (! defined $winmapObj || defined $check) {
6568  
6569 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
6570 }
6571  
6572 # (IVs normally updated here are updated by $self->drawGaugeBox, when it is called)
6573  
6574 return 1;
6575 }
6576  
6577 sub objDestroy {
6578  
6579 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
6580 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
6581 # to do any necessary tidying up
6582 #
6583 # Expected arguments
6584 # (none besides $self)
6585 #
6586 # Return values
6587 # 'undef' on improper arguments
6588 # 1 otherwise
6589  
6590 my ($self, $check) = @_;
6591  
6592 # Check for improper arguments
6593 if (defined $check) {
6594  
6595 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
6596 }
6597  
6598 if ($self->visibleFlag) {
6599  
6600 # Only polite to destroy GooCanvas2 canvas objects when they're no longer needed
6601 foreach my $canvasObj ($self->gaugeCanvasList) {
6602  
6603 $canvasObj->remove();
6604 }
6605 }
6606  
6607 return 1;
6608 }
6609  
6610 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Strip
6611  
6612 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Strip
6613  
6614 # ->signal_connects
6615  
6616 # Other functions
6617  
6618 sub drawGaugeBox {
6619  
6620 # Called by $self->objEnable and ->addGaugeLevel
6621 # Draws a Gtk3::HBox to contain gauge levels
6622 #
6623 # Expected arguments
6624 # (none besides $self)
6625 #
6626 # Return values
6627 # 'undef' on improper arguments
6628 # 1 otherwise
6629  
6630 my ($self, $check) = @_;
6631  
6632 # Local variables
6633 my (
6634 $levelCount,
6635 %sessionHash,
6636 );
6637  
6638 # Check for improper arguments
6639 if (defined $check) {
6640  
6641 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawGaugeBox', @_);
6642 }
6643  
6644 # Create a packing box, if one doesn't exist already
6645 my $packingBox;
6646 if (! $self->packingBox) {
6647  
6648 # This function is being called for the first time
6649 $packingBox = Gtk3::VBox->new(FALSE, 0);
6650 $packingBox->set_border_width(0);
6651  
6652 } else {
6653  
6654 # This function is being called for a subsequent time. Remove its current contents, so
6655 # new widgets can be created
6656 $packingBox = $self->packingBox;
6657 $axmud::CLIENT->desktopObj->removeWidget($packingBox, $self->frame);
6658 }
6659  
6660 # Different sessions might be using different numbers of gauge levels. Find the highest
6661 # number of gauge levels used by the greediest session (might be 0, if there are no gauge
6662 # levels at the moment)
6663 $levelCount = 0;
6664 foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {
6665  
6666 my $num = $gaugeLevelObj->session->number;
6667  
6668 if (! exists $sessionHash{$num}) {
6669 $sessionHash{$num} = 1;
6670 } else {
6671 $sessionHash{$num} = $sessionHash{$num} + 1;
6672 }
6673  
6674 if ($levelCount < $sessionHash{$num}) {
6675  
6676 $levelCount = $sessionHash{$num};
6677 }
6678 }
6679  
6680 # If there are no gauges visible, draw a gauge box with room for one gauge level anyway, in
6681 # the expectation that the first gauge might be added a moment from now
6682 if (! $levelCount) {
6683  
6684 $levelCount = 1;
6685 }
6686  
6687 # Add a frame
6688 my $frame = Gtk3::Frame->new(undef);
6689 $frame->set_border_width(0);
6690 $frame->set_size_request(
6691 -1,
6692 (
6693 2 # Size of frame border
6694 + $self->gaugeSpacingY
6695 + ($levelCount * ($self->gaugeHeight + $self->gaugeSpacingY))
6696 ),
6697 );
6698  
6699 $packingBox->pack_start($frame, TRUE, TRUE, 0);
6700  
6701 # The only way to detect the frame's size reliably is to store the frame's size allocation
6702 # whenever it is set
6703 $frame->signal_connect('size-allocate' => sub {
6704  
6705 my ($widget, $hashRef) = @_;
6706  
6707 $self->ivPoke('canvasFrameWidth', $$hashRef{width});
6708 $self->ivPoke('canvasFrameHeight', $$hashRef{height});
6709  
6710 if ($self->canvas) {
6711  
6712 $self->updateGauges();
6713  
6714 # The resized canvas won't be visible until a Gtk main loop occurs
6715 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->drawGaugeBox');
6716 }
6717 });
6718  
6719 # Add a drawing canvas, inside the frame
6720 my $canvas = GooCanvas2::Canvas->new();
6721 $frame->add($canvas);
6722  
6723 # Update IVs
6724 $self->ivPoke('packingBox', $packingBox);
6725 $self->ivPoke('frame', $frame);
6726 $self->ivPoke('canvas', $canvas);
6727  
6728 # Setup complete
6729 return 1;
6730 }
6731  
6732 sub removeGaugeBox {
6733  
6734 # Called by GA::Client->spinClientLoop or $self->removeSessionGauges
6735 # If this window's gauge box has been empty for too long, remove the gauge box entirely
6736 # (By waiting for a few seconds, we don't have to remove then re-draw the gauge box within
6737 # the space of a second if, for example, the Status task resets)
6738 #
6739 # Expected arguments
6740 # (none besides $self)
6741 #
6742 # Return values
6743 # 'undef' on improper arguments
6744 # 1 otherwise
6745  
6746 my ($self, $check) = @_;
6747  
6748 # Check for improper arguments
6749 if (defined $check) {
6750  
6751 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeGaugeBox', @_);
6752 }
6753  
6754 # Check that gauge box is actually drawn and doesn't currently contain any gauges
6755 if ($self->visibleFlag && ! $self->gaugeLevelHash) {
6756  
6757 # Destroy canvas objects
6758 foreach my $canvasObj ($self->gaugeCanvasList) {
6759  
6760 $canvasObj->remove();
6761 }
6762  
6763 # Update IVs
6764 $self->ivUndef('gaugeCheckTime');
6765  
6766 # Mark the strip object as hidden
6767 $self->winObj->hideStripObj($self);
6768 }
6769  
6770 return 1;
6771 }
6772  
6773 sub addGaugeLevel {
6774  
6775 # Can be called by anything
6776 # Adds a new gauge level to this window's gauge box (a horizontal band of gauges, of which
6777 # there can be 1 or more bands within the gauge box)
6778 # Updates IVs and redraws the gauge box (if it's not currently visible, draws it in the
6779 # expectation that a gauge is about to be added)
6780 #
6781 # Expected arguments
6782 # $session - The calling GA::Session
6783 #
6784 # Optional arguments
6785 # $noDrawFlag - If set to TRUE, $self->drawGaugeBox is not called immediately (in the
6786 # expectation that the calling function has not finished modifying its
6787 # gauges yet). Otherwise set to FALSE (or 'undef'). If adding gauges
6788 # on multiple levels, all at the same time, set this flag to TRUE for
6789 # a better visual effect
6790 #
6791 # Return values
6792 # 'undef' on improper arguments or on failure
6793 # Otherwise, returns the unique number of the gauge level created (the first one ever
6794 # created, but not necessarily the first one visible currently, is 0)
6795  
6796 my ($self, $session, $noDrawFlag, $check) = @_;
6797  
6798 # Local variables
6799 my ($count, $newObj);
6800  
6801 # Check for improper arguments
6802 if (! defined $session || defined $check) {
6803  
6804 return $axmud::CLIENT->writeImproper($self->_objClass . '->addGaugeLevel', @_);
6805 }
6806  
6807 # Count the number of gauge levels for this session. If we're already at the maximum, do
6808 # nothing
6809 $count = 0;
6810 foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {
6811  
6812 if ($gaugeLevelObj->session eq $session) {
6813  
6814 $count++;
6815 }
6816 }
6817  
6818 if ($count >= $self->gaugeLevelMax) {
6819  
6820 return undef;
6821 }
6822  
6823 # If the gauge box was due to be removed because it's been empty too long, we can now keep
6824 # it (on the understanding that a new gauge is about to be added)
6825 $self->ivUndef('gaugeCheckTime');
6826  
6827 # Create a new gauge level object
6828 $newObj = Games::Axmud::Obj::GaugeLevel->new($session, $self->gaugeLevelCount);
6829 if (! $newObj) {
6830  
6831 return undef;
6832 }
6833  
6834 # Update IVs
6835 $self->ivAdd('gaugeLevelHash', $newObj->number, $newObj);
6836 $self->ivIncrement('gaugeLevelCount');
6837  
6838 # Redraw the gauge box at the right size
6839 if (! $noDrawFlag) {
6840  
6841 # Redraw the gauge box now
6842 $self->drawGaugeBox();
6843 if (! $self->visibleFlag) {
6844 $self->winObj->revealStripObj($self);
6845 } else {
6846 $self->winObj->replaceStripObj($self);
6847 }
6848  
6849 } else {
6850  
6851 # Redraw the gauge box the next time $self->updateGauges is called
6852 $self->ivPoke('gaugeNoDrawFlag', TRUE);
6853 }
6854  
6855 return $newObj->number;
6856 }
6857  
6858 sub removeGaugeLevel {
6859  
6860 # Can be called by anything
6861 # Removes an existing gauge level from this window's gauge box (a horizontal band of gauges,
6862 # of which there can be 1 or more bands within the gauge box)
6863 # Any gauges that are currently drawn on that level are destroyed
6864 # Updates IVs. Redraws the gauge box, or removes it altogether if there are no gauge levels
6865 # left
6866 #
6867 # Expected arguments
6868 # $session - The calling GA::Session
6869 # $level - The unique number of the gauge level to remove (matches a key in
6870 # $self->gaugeLevelHash). The gauge level must belong to the specified
6871 # $session
6872 #
6873 # Optional arguments
6874 # $noDrawFlag - If set to TRUE, $self->updateGauges is not called immediately (in the
6875 # expectation that the calling function has not finished modifying its
6876 # gauges yet). Otherwise set to FALSE (or 'undef')
6877 #
6878 # Return values
6879 # 'undef' on improper arguments or on failure
6880 # Otherwise returns the number of gauges removed (might be 0)
6881  
6882 my ($self, $session, $level, $noDrawFlag, $check) = @_;
6883  
6884 # Local variables
6885 my (
6886 $gaugeLevelObj, $count,
6887 @list,
6888 );
6889  
6890 # Check for improper arguments
6891 if (! defined $level || defined $check) {
6892  
6893 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeGaugeLevel', @_);
6894 }
6895  
6896 # Do nothing if the gauge level doesn't exist or if it doesn't match the specified session
6897 $gaugeLevelObj = $self->ivShow('gaugeLevelHash', $level);
6898 if (! defined $gaugeLevelObj || $gaugeLevelObj->session ne $session) {
6899  
6900 return undef;
6901 }
6902  
6903 # Update IVs
6904 $count = $gaugeLevelObj->ivPairs('gaugeHash');
6905 $self->ivDelete('gaugeLevelHash', $level);
6906  
6907 # If there are no gauges levels left (in any session), set the time (shortly in the future)
6908 # when the gauge box will be removed entirely, if no new gauges have been drawn in the
6909 # mean time
6910 if (! $self->gaugeLevelHash) {
6911  
6912 $self->ivPoke('gaugeCheckTime', ($axmud::CLIENT->clientTime + $self->gaugeWaitTime));
6913 }
6914  
6915 # If the strip object itself is marked visible ($self->visibleFlag), redraw the gauge box as
6916 # the right size (even if it contains no gauges at this precise moment)
6917 $self->drawGaugeBox();
6918 if ($self->visibleFlag) {
6919  
6920 $self->winObj->replaceStripObj($self);
6921 if (! $noDrawFlag) {
6922  
6923 $self->updateGauges();
6924 }
6925 }
6926  
6927 return $count;
6928 }
6929  
6930 sub addGauge {
6931  
6932 # Can be called by anything
6933 # Adds a new graphical gauge to this window's gauge box, visible only when the calling
6934 # GA::Session is the window's visible session. (Text gauges are added with a call to
6935 # $self->addTextGauge)
6936 # If the gauge box itself is not yet visible, draws it
6937 #
6938 # Expected arguments
6939 # $session - The calling GA::Session
6940 #
6941 # Optional arguments
6942 # $level - The unique number of the GA::Obj::GaugeLevel object to use
6943 # (representing a horizontal band of gauges, of which there can be
6944 # 1 or more bands within the gauge box). If the $level number has
6945 # not been added via a call to $self->addGaugeLevel, the gauge is not
6946 # drawn (as a precaution against buggy code). However, if 'undef', the
6947 # gauge is added to the first visible level for the specified
6948 # GA::Session; if none exist for the session, one is created for it
6949 # - NB Ideally, anything that displays gauges (such as a task) should
6950 # create its own gauge level via a call to $self->addGaugeLevel
6951 # $value - The value to display (>= 0)...
6952 # $maxValue - ...and the maximum value (must be >= $value). If either $value or
6953 # $maxValue is undefined, the gauge is drawn a different colour than
6954 # usual
6955 # $addFlag - If TRUE, the total size of the gauge is ($value + $maxValue). If
6956 # FALSE (or 'undef'), the total size is $maxValue
6957 # $label - The label to use with the gauge. If 'undef' or an empty string, no
6958 # label is used
6959 # $fullColour - The colour to use in the 'full' part of the gauge - an Axmud colour
6960 # tag (standard, Xterm or RGB). If 'undef', an empty string or an
6961 # unrecognised colour tag, '#FFFFFF' is used
6962 # $emptyColour - The colour to use in the 'empty' part of the gauge - an Axmud colour
6963 # tag (standard, Xterm or RGB). If 'undef', an empty string or an
6964 # unrecognised colour tag, '#000000' is used
6965 # $labelColour - The label colour to use - - an Axmud colour tag (standard, Xterm or
6966 # RGB). If 'undef', an empty string or an unrecognised colour tag,
6967 # '#FF0000' is used
6968 # $labelFlag - If set to TRUE, the label text (if displayed) is supplemented with the
6969 # values; e.g. 'HP: 37/100'. If FALSE (or 'undef'), only the text in
6970 # $label is visible
6971 #
6972 # Return values
6973 # 'undef' on improper arguments or on failure
6974 # Otherwise returns the GA::Obj::Gauge created to store details about the new gauge
6975  
6976 my (
6977 $self, $session, $level, $value, $maxValue, $addFlag, $label, $fullColour, $emptyColour,
6978 $labelColour, $labelFlag, $check,
6979 ) = @_;
6980  
6981 # Local variables
6982 my (
6983 $gaugeLevelObj, $newObj,
6984 @list, @gaugeList,
6985 );
6986  
6987 # Check for improper arguments
6988 if (! defined $session || defined $check) {
6989  
6990 return $axmud::CLIENT->writeImproper($self->_objClass . '->addGauge', @_);
6991 }
6992  
6993 if (! defined $level) {
6994  
6995 # If no level was specified, use the first available one. If there are none, create a
6996 # new one
6997 # The first available level is the one with the lowest level number that belongs to
6998 # the calling session
6999 foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {
7000  
7001 if (
7002 $gaugeLevelObj->session eq $session
7003 && (
7004 ! defined $level
7005 || $level > $gaugeLevelObj->number
7006 )
7007 ) {
7008 $level = $gaugeLevelObj->number;
7009 }
7010 }
7011  
7012 if (! defined $level) {
7013  
7014 $level = $self->addGaugeLevel($session);
7015 if (! defined $level) {
7016  
7017 return undef;
7018 }
7019 }
7020  
7021 } elsif (! $self->ivExists('gaugeLevelHash', $level)) {
7022  
7023 # Specfied level has not been created, so as a precaution against buggy code, don't draw
7024 # the gauge
7025 return undef;
7026 }
7027  
7028 # (For other parts of the code, it's more convenient that $self->addGaugeLevel returns the
7029 # gauge level object's unique number, rather than the blessed reference itself. However,
7030 # we need the blessed reference)
7031 $gaugeLevelObj = $self->ivShow('gaugeLevelHash', $level);
7032  
7033 # Apply a check on the maximum number of gauges per level
7034 if ($gaugeLevelObj->ivPairs('gaugeHash') >= $self->gaugeMax) {
7035  
7036 return undef;
7037 }
7038  
7039 # If the gauge box isn't currently visible, draw it
7040 if (! $self->visibleFlag) {
7041  
7042 $self->drawGaugeBox();
7043 $self->winObj->revealStripObj($self);
7044 }
7045  
7046 # If the gauge box was due to be removed because it's been empty too long, we can now keep
7047 # it
7048 $self->ivUndef('gaugeCheckTime');
7049  
7050 # Set default values, translating any colour tags in RGB colour tags
7051 if ($fullColour) {
7052  
7053 $fullColour = $axmud::CLIENT->returnRGBColour($fullColour);
7054 }
7055  
7056 if (! $fullColour) {
7057  
7058 $fullColour = $self->gaugeFullColour;
7059 }
7060  
7061 if ($emptyColour) {
7062  
7063 $emptyColour = $axmud::CLIENT->returnRGBColour($emptyColour);
7064 }
7065  
7066 if (! $emptyColour) {
7067  
7068 $emptyColour = $self->gaugeEmptyColour;
7069 }
7070  
7071 if (! $addFlag) {
7072 $addFlag = FALSE;
7073 } else {
7074 $addFlag = TRUE;
7075 }
7076  
7077 if ($labelColour) {
7078  
7079 $labelColour = $axmud::CLIENT->returnRGBColour($labelColour);
7080 }
7081  
7082 if (! $labelColour) {
7083  
7084 $labelColour = $self->gaugeLabelColour;
7085 }
7086  
7087 if (! $labelFlag) {
7088 $labelFlag = FALSE;
7089 } else {
7090 $labelFlag = TRUE;
7091 }
7092  
7093 # Sanity check: $value and/or $maxValue can be 'undef', but if they're specified, they must
7094 # be a valid floating-point number
7095 if (defined $value && ! $axmud::CLIENT->floatCheck($value)) {
7096  
7097 $value = undef;
7098 }
7099  
7100 if (defined $maxValue && ! $axmud::CLIENT->floatCheck($maxValue)) {
7101  
7102 $maxValue = undef;
7103 }
7104  
7105 # Create a new GA::Obj::Gauge object for this gauge (do this before drawing the gauge,
7106 # because if $session isn't the current session, we don't draw it yet)
7107 # NB The FALSE argument means this is a graphical gauge, not a text gauge
7108 $newObj = Games::Axmud::Obj::Gauge->new(
7109 $session,
7110 $self->ivIncrement('gaugeCount'),
7111 $level,
7112 FALSE,
7113 );
7114  
7115 if (! $newObj) {
7116  
7117 return undef;
7118  
7119 } else {
7120  
7121 $gaugeLevelObj->ivAdd('gaugeHash', $newObj->number, $newObj);
7122  
7123 $newObj->ivPoke('value', $value);
7124 $newObj->ivPoke('maxValue', $maxValue);
7125 $newObj->ivPoke('addFlag', $addFlag);
7126 $newObj->ivPoke('label', $label);
7127  
7128 $newObj->ivPoke('fullColour', $fullColour);
7129 $newObj->ivPoke('emptyColour', $emptyColour);
7130 $newObj->ivPoke('labelColour', $labelColour);
7131 $newObj->ivPoke('labelFlag', $labelFlag);
7132 }
7133  
7134 # If $session is the visible one, redraw all of that session's gauges now
7135 if ($self->winObj->visibleSession && $self->winObj->visibleSession eq $session) {
7136  
7137 $self->updateGauges();
7138 }
7139  
7140 return $newObj;
7141 }
7142  
7143 sub addTextGauge {
7144  
7145 # Can be called by anything
7146 # Adds a new text gauge to the 'main' window's gauge box, visible only when the calling
7147 # GA::Session is the current session. (Graphical gauges are added with a call to
7148 # $self->addGauge)
7149 # If the gauge box itself is not yet visible, draws it
7150 #
7151 # Expected arguments
7152 # $session - The calling GA::Session
7153 #
7154 # Optional arguments
7155 # $level - The unique number of the GA::Obj::GaugeLevel object to use
7156 # (representing a horizontal band of gauges, of which there can be
7157 # 1 or more band within the gauge box). If the $level number has
7158 # not been added via a call to $self->addGaugeLevel, the gauge is not
7159 # drawn (as a precaution against buggy code). However, if 'undef', the
7160 # gauge is added to the first visible level for the specified
7161 # GA::Session; if none exist for the session, one is created for it
7162 # - NB Ideally, anything that displays gauges (such as a task) should
7163 # create its own gauge level via a call to $self->addGaugeLevel
7164 # $value - The value to display (>= 0)...
7165 # $maxValue - ...and the maximum value (must be >= $value). If either $value or
7166 # $maxValue is undefined, the gauge is drawn a different colour than
7167 # usual
7168 # $addFlag - If TRUE, the total size of the gauge is ($value + $maxValue). If
7169 # FALSE (or 'undef'), the total size is $maxValue
7170 # $label - The label to use with the gauge. If 'undef' or an empty string, no
7171 # label is used
7172 #
7173 # Return values
7174 # 'undef' on improper arguments or on failure
7175 # Otherwise returns the GA::Obj::Gauge created to store details about the new gauge
7176  
7177 my ($self, $session, $level, $value, $maxValue, $addFlag, $label, $check) = @_;
7178  
7179 # Local variables
7180 my (
7181 $gaugeLevelObj, $newObj,
7182 @list, @gaugeList,
7183 );
7184  
7185 # Check for improper arguments
7186 if (! defined $session || defined $check) {
7187  
7188 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTextGauge', @_);
7189 }
7190  
7191 if (! defined $level) {
7192  
7193 # If no level was specified, use the first available one. If there are none, create a
7194 # new one
7195 # The first available level is the one with the lowest level number that belongs to
7196 # the calling session
7197 foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {
7198  
7199 if (
7200 $gaugeLevelObj->session eq $session
7201 && (
7202 ! defined $level
7203 || $level > $gaugeLevelObj->number
7204 )
7205 ) {
7206 $level = $gaugeLevelObj->number;
7207 }
7208 }
7209  
7210 if (! defined $level) {
7211  
7212 $level = $self->addGaugeLevel($session);
7213 if (! defined $level) {
7214  
7215 return undef;
7216 }
7217 }
7218  
7219 } elsif (! $self->ivExists('gaugeLevelHash', $level)) {
7220  
7221 # Specfied level has not been created, so as a precaution against buggy code, don't draw
7222 # the gauge
7223 return undef;
7224 }
7225  
7226 # (For other parts of the code, it's more convenient that $self->addGaugeLevel returns the
7227 # gauge level object's unique number, rather than the blessed reference itself. However,
7228 # we need the blessed reference)
7229 $gaugeLevelObj = $self->ivShow('gaugeLevelHash', $level);
7230  
7231 # Apply a check on the maximum number of gauges per level
7232 if ($gaugeLevelObj->ivPairs('gaugeHash') >= $self->gaugeMax) {
7233  
7234 return undef;
7235 }
7236  
7237 # If the gauge box isn't currently visible, draw it
7238 if (! $self->visibleFlag) {
7239  
7240 $self->drawGaugeBox();
7241 $self->winObj->revealStripObj($self);
7242 }
7243  
7244 # If the gauge box was due to be removed because it's been empty too long, we can now keep
7245 # it
7246 $self->ivUndef('gaugeCheckTime');
7247  
7248 # Set default values
7249 if (! $addFlag) {
7250 $addFlag = FALSE;
7251 } else {
7252 $addFlag = TRUE;
7253 }
7254  
7255 # Sanity check: $value and/or $maxValue can be 'undef', but if they're specified, they must
7256 # be a valid decimal number
7257 if (defined $value && ! $axmud::CLIENT->floatCheck($value)) {
7258  
7259 $value = undef;
7260 }
7261  
7262 if (defined $maxValue && ! $axmud::CLIENT->floatCheck($maxValue)) {
7263  
7264 $maxValue = undef;
7265 }
7266  
7267 # Create a new GA::Obj::Gauge object for this gauge (do this before drawing the gauge,
7268 # because if $session isn't the current session, we don't draw it yet)
7269 # NB The TRUE argument means this is a text gauge, not a graphical gauge
7270 $newObj = Games::Axmud::Obj::Gauge->new(
7271 $session,
7272 $self->ivIncrement('gaugeCount'),
7273 $level,
7274 TRUE,
7275 );
7276  
7277 if (! $newObj) {
7278  
7279 return undef;
7280  
7281 } else {
7282  
7283 $gaugeLevelObj->ivAdd('gaugeHash', $newObj->number, $newObj);
7284  
7285 $newObj->ivPoke('value', $value);
7286 $newObj->ivPoke('maxValue', $maxValue);
7287 $newObj->ivPoke('addFlag', $addFlag);
7288 $newObj->ivPoke('label', $label);
7289 }
7290  
7291 # If $session is the visible one, redraw all of that session's gauges now
7292 if ($self->winObj->visibleSession && $self->winObj->visibleSession eq $session) {
7293  
7294 $self->updateGauges();
7295 }
7296  
7297 return $newObj;
7298 }
7299  
7300 sub removeGauges {
7301  
7302 # Can be called by anything
7303 # Removes one or more gauges. If the calling GA::Session is the visible one, redraws
7304 # everything in the gauge box. If all gauges have now been removed, sets the time at
7305 # which the gauge box itself is made invisible
7306 #
7307 # Expected arguments
7308 # $session - The calling GA::Session
7309 # $keepLevelFlag - Flag set to TRUE if the gauge level should not be destroyed, if all
7310 # its gauges are removed (probably because the calling code wants to
7311 # add new gauges to it in a moment); set to FALSE if the gauge level
7312 # should be destroyed if all its gauges are removed
7313 #
7314 # Optional arguments
7315 # @objList - A list of GA::Obj::Gauge objects (which don't have to belong to the
7316 # calling GA::Session). If it's an empty list, nothing is removed
7317 #
7318 # Return values
7319 # 'undef' on improper arguments or if we're not allowed to draw gauges at all
7320 # Otherwise returns the number of gauges removed (might be 0)
7321  
7322 my ($self, $session, $keepLevelFlag, @objList) = @_;
7323  
7324 # Local variables
7325 my (
7326 $removeCount, $redrawFlag, $redrawAllFlag,
7327 @drawList,
7328 );
7329  
7330 # Check for improper arguments
7331 if (! defined $session) {
7332  
7333 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeGauges', @_);
7334 }
7335  
7336 # Update registries
7337 $removeCount = 0;
7338 foreach my $gaugeObj (@objList) {
7339  
7340 my $gaugeLevelObj = $self->ivShow('gaugeLevelHash', $gaugeObj->level);
7341  
7342 # Remove the gauge from its gauge level
7343 if ($gaugeLevelObj && $gaugeLevelObj->ivExists('gaugeHash', $gaugeObj->number)) {
7344  
7345 $gaugeLevelObj->ivDelete('gaugeHash', $gaugeObj->number);
7346 $removeCount++;
7347  
7348 # If the calling GA::Session is the visible one, redraw everything in the gauge
7349 # box
7350 if (
7351 $self->winObj->visibleSession
7352 && $self->winObj->visibleSession eq $session
7353 && $gaugeObj->session eq $session
7354 ) {
7355 $redrawFlag = TRUE;
7356  
7357 # If the gauge level is now empty, remove it (unless the calling function told
7358 # us not to do that)
7359 if (! $keepLevelFlag && ! $gaugeLevelObj->gaugeHash) {
7360  
7361 $self->ivDelete('gaugeLevelHash', $gaugeLevelObj->number);
7362 $redrawAllFlag = TRUE;
7363 }
7364 }
7365 }
7366 }
7367  
7368 # Redraw widgets, as required
7369 if ($redrawAllFlag) {
7370  
7371 # Redraw the gauge box as the right size (even if it contains no gauges at this precise
7372 # moment)
7373 $self->drawGaugeBox();
7374 $self->winObj->replaceStripObj($self);
7375  
7376 } elsif ($redrawFlag) {
7377  
7378 # Redraw the gauges themselves
7379 $self->updateGauges();
7380 }
7381  
7382 # If there are no gauges left (in any session), set the time (shortly in the future) when
7383 # the gauge box will be removed entirely, if no new gauges have been drawn in the mean
7384 # time
7385 if ($redrawFlag || $redrawAllFlag) {
7386  
7387 if (! $self->gaugeLevelHash) {
7388  
7389 $self->ivPoke(
7390 'gaugeCheckTime',
7391 ($axmud::CLIENT->clientTime + $self->gaugeWaitTime),
7392 );
7393 }
7394 }
7395  
7396 return $removeCount;
7397 }
7398  
7399 sub removeSessionGauges {
7400  
7401 # Can be called by anything
7402 # Complementing $self->removeGauges, this is a short-cut which removes all gauges for a
7403 # particular session, without the need for the calling function to specify the gauges
7404 # to remove
7405 # (If the specified session isn't this window's visible session, then no visible gauges are
7406 # removed, but IVs are still updated)
7407 #
7408 # Expected arguments
7409 # $session - The GA::Session whose gauges should be removed
7410 #
7411 # Optional arguments
7412 # $boxFlag - Set to TRUE when called by GA::Session->reactDisconnect. If there are
7413 # no gauges left, the 'main' window code normally waits a few seconds
7414 # before removing the gauge box. However, that won't work if the only
7415 # session has just disconnected, as its timer loop has terminated.
7416 # When the flag is TRUE, the gauge box is removed immediately. Set to
7417 # FALSE (or 'undef') otherwise
7418 #
7419 # Return values
7420 # 'undef' on improper arguments or if we're not allowed to draw gauges at all
7421 # Otherwise returns the number of gauges removed (might be 0)
7422  
7423 my ($self, $session, $boxFlag, $check) = @_;
7424  
7425 # Local variables
7426 my (
7427 $result,
7428 @removeList,
7429 );
7430  
7431 # Check for improper arguments
7432 if (! defined $session || defined $check) {
7433  
7434 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeSessionGauges', @_);
7435 }
7436  
7437 # Get a list of gauges belonging to the specified session
7438 foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {
7439  
7440 if ($gaugeLevelObj->session eq $session) {
7441  
7442 push (@removeList, $gaugeLevelObj->ivValues('gaugeHash'));
7443 }
7444 }
7445  
7446 # The FALSE argument means 'don't keep an empty gauge level'
7447 $result = $self->removeGauges($session, FALSE, @removeList);
7448  
7449 # Remove the gauge box immediately, if instructed
7450 if (! $self->gaugeLevelHash && $boxFlag) {
7451  
7452 $self->removeGaugeBox();
7453 }
7454  
7455 return $result;
7456 }
7457  
7458 sub updateGauges {
7459  
7460 # Can be called by anything
7461 # Updates the gauges currently drawn in the gauge box, redrawing them. If this window's
7462 # visible session has changed, a new set of gauges is drawn, replacing the previous ones
7463 #
7464 # Expected arguments
7465 # (none besides $self)
7466 #
7467 # Return values
7468 # 'undef' on improper arguments
7469 # 1 otherwise
7470  
7471 my ($self, $check) = @_;
7472  
7473 # Local variables
7474 my (
7475 $result,
7476 @drawList,
7477 );
7478  
7479 # Check for improper arguments
7480 if (defined $check) {
7481  
7482 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateGauges', @_);
7483 }
7484  
7485 # Do nothing if the gauge box isn't actually visible (because no gauges have been drawn by
7486 # any session), or if another call to this function is still being processed
7487 if (! $self->visibleFlag || $self->gaugeUpdateFlag) {
7488 return undef;
7489 } else {
7490 $self->ivPoke('gaugeUpdateFlag', TRUE);
7491 }
7492  
7493 # If a recent call to $self->addGaugeLevel specified that the gauge box shouldn't be
7494 # redrawn yet, then redraw it now
7495 if ($self->gaugeNoDrawFlag) {
7496  
7497 $self->drawGaugeBox();
7498 $self->winObj->replaceStripObj($self);
7499 $self->ivPoke('gaugeNoDrawFlag', FALSE);
7500 }
7501  
7502 # Compile an ordered list of gauges that should be visible (so that gauge levels and gauges
7503 # are always drawn in the same order)
7504 foreach my $gaugeLevelObj (
7505 sort {$a->number <=> $b->number} ($self->ivValues('gaugeLevelHash'))
7506 ) {
7507 # (Session-specific gauges typically only apply to the main window)
7508 if (
7509 ! $self->winObj->visibleSession
7510 || $self->winObj->visibleSession eq $gaugeLevelObj->session
7511 ) {
7512 push (
7513 @drawList,
7514 sort {$a->number <=> $b->number} ($gaugeLevelObj->ivValues('gaugeHash')),
7515 );
7516 }
7517 }
7518  
7519 $result = $self->drawGauges(@drawList);
7520 # Subsequent calls to this function are now allowed again
7521 $self->ivPoke('gaugeUpdateFlag', FALSE);
7522  
7523 return $result;
7524 }
7525  
7526 sub drawGauges {
7527  
7528 # Called by $self->updateGauges or ->removeGauges (but not by any other code)
7529 # Draws 0, 1 or more gauges in the gauge box, destroying any canvas objects that were drawn
7530 # on the previous call to this function
7531 # The calling function should ensure that only the current session's gauges are specified
7532 # as arguments, and that all gauges belonging to that session are specified
7533 #
7534 # Expected arguments
7535 # (none besides $self)
7536 #
7537 # Optional arguments
7538 # @drawList - A list of GA::Obj::Gauge objects (which must belong to the current
7539 # GA::Session). If it's an empty list, no new gauges are drawn
7540 #
7541 # Return values
7542 # 'undef' on improper arguments
7543 # 1 otherwise
7544  
7545 my ($self, @drawList) = @_;
7546  
7547 # Local variables
7548 my (
7549 $root, $visLevel, $count,
7550 @canvasObjList,
7551 %levelHash, %widthHash, %checkHash,
7552 );
7553  
7554 # (No improper arguments to check)
7555  
7556 # Destroy any existing canvas objects
7557 foreach my $canvasObj ($self->gaugeCanvasList) {
7558  
7559 $canvasObj->remove;
7560 }
7561  
7562 $self->ivEmpty('gaugeCanvasList');
7563  
7564 # If there are no gauges to be drawn, end here
7565 # Also, don't try to draw gauges in a very small space
7566 if (! @drawList || $self->canvasFrameWidth < 100) {
7567  
7568 return undef;
7569 }
7570  
7571 # Reset the size of the canvas
7572 $self->canvas->set_bounds(
7573 0,
7574 0,
7575 $self->canvasFrameWidth,
7576 $self->canvasFrameHeight,
7577 );
7578  
7579 # Sort the gauges first by level, and then by the order they were created, so they are
7580 # always drawn in the same order, top to bottom and then left to right
7581 @drawList = sort {
7582  
7583 if ($a->level != $b->level) {
7584 $a->level <=> $b->level
7585 } else {
7586 $a->number <=> $b->number
7587 }
7588  
7589 } (@drawList);
7590  
7591 # Count the number of gauges for each level...
7592 foreach my $gaugeObj (@drawList) {
7593  
7594 if (! exists ($levelHash{$gaugeObj->level})) {
7595 $levelHash{$gaugeObj->level} = 1;
7596 } else {
7597 $levelHash{$gaugeObj->level} += 1;
7598 }
7599 }
7600  
7601 # ...and then work out the gauge width for each level. Every gauge on the same level should
7602 # be the same width. We leave $self->gaugeSpacingX pixels clear on one end of the gauge
7603 # box, and $self->gaugeSpacingX pixels clear at the opposite end of each gauge we draw, so
7604 # they appear equally-spaced
7605 foreach my $level (keys %levelHash) {
7606  
7607 $widthHash{$level}
7608 = int(($self->canvasFrameWidth - $self->gaugeSpacingX) / ($levelHash{$level}));
7609 }
7610  
7611 # Draw each gauge in turn
7612 $root = $self->canvas->get_root_item();
7613 $visLevel = -1;
7614  
7615 foreach my $gaugeObj (@drawList) {
7616  
7617 my (
7618 $blankFlag, $ratio, $w, $corrW, $f, $e, $x1, $x2, $x3, $x4, $l, $y1, $y2, $obj,
7619 $lText, $lCol,
7620 );
7621  
7622 if (! exists $checkHash{$gaugeObj->level}) {
7623  
7624 # First gauge drawn on this level
7625 $count = 0;
7626 $checkHash{$gaugeObj->level} = undef;
7627 $visLevel++;
7628  
7629 } else {
7630  
7631 # Not the first
7632 $count++;
7633 }
7634  
7635 if (! $gaugeObj->textFlag) {
7636  
7637 # How full/empty is the gauge?
7638 if (
7639 ! defined $gaugeObj->value
7640 || ! $axmud::CLIENT->floatCheck($gaugeObj->value)
7641 || ! defined $gaugeObj->maxValue
7642 || ! $axmud::CLIENT->floatCheck($gaugeObj->maxValue)
7643 ) {
7644 # If either value is not defined, or if the values aren't numerical (for some
7645 # reason), then draw the gauge a different colour
7646 $blankFlag = TRUE;
7647 $ratio = 0;
7648  
7649 } elsif ($gaugeObj->maxValue <= 0 && $gaugeObj->value > 0) {
7650  
7651 # The value is bigger than the maximum value, for some reason. Draw the gauge as
7652 # full
7653 $ratio = 1;
7654  
7655 } elsif ($gaugeObj->value <= 0 || $gaugeObj->maxValue <= 0) {
7656  
7657 # Otherwise, if either value is 0, gauge should definitely be drawn empty (and
7658 # this also avoids division by zero in the next code block)
7659 $ratio = 0;
7660  
7661 } else {
7662  
7663 if (! $gaugeObj->addFlag) {
7664 $ratio = $gaugeObj->value / $gaugeObj->maxValue;
7665 } else {
7666 $ratio = $gaugeObj->value / ($gaugeObj->value + $gaugeObj->maxValue);
7667 }
7668 }
7669  
7670 # (Sanity check)
7671 if ($ratio > 1) {
7672  
7673 $ratio = 1;
7674 }
7675 }
7676  
7677 # Total gauge width
7678 $w = $widthHash{$gaugeObj->level};
7679 # Edge correction - if this gauge is almost at the far right side of the gauge box, but
7680 # not quite (because of rounding errors introduced by int() in the setting of $f),
7681 # make it a bit larger, so as to fill the whole gauge box
7682 $corrW = $w;
7683 $x4 = $w * ($count + 1);
7684 if (
7685 $x4 < ($self->canvasFrameWidth - $self->gaugeSpacingX)
7686 && $x4 >= ($self->canvasFrameWidth - $self->gaugeSpacingX - $count)
7687 ) {
7688 $corrW += $self->canvasFrameWidth - $self->gaugeSpacingX - ($w * ($count + 1));
7689 }
7690  
7691 if (! $gaugeObj->textFlag) {
7692  
7693 # Full/empty widths
7694 $f = int(($corrW - $self->gaugeSpacingX) * $ratio);
7695 $e = $w - $f;
7696  
7697 # Full gauge portion
7698 $x1 = $self->gaugeSpacingX + ($count * $w) - 2;
7699 $x2 = $x1 + $f;
7700 # Empty gauge portion
7701 $x3 = $x2; # By moving $x3 1 pixel left, we avoid double black line
7702 $x4 = $x1 + $corrW - $self->gaugeSpacingX;
7703  
7704 # Special case: if the ratio is very close to 0 (but not enough to draw a pixel in
7705 # the 'full' portion of the gauge), then draw at least one pixel
7706 # (Actually, we need $x2 to be at least 2 pixels bigger than $x1, otherwise only the
7707 # border of the 'full' portion of the gauge is visible
7708 if ($ratio > 0 && ($x2 - $x1) <= 1) {
7709  
7710 $x2 = $x3 = $x1 + 2;
7711  
7712 # Likewise, if the ratio is very close to 1 (but not enough to draw a pixel in the
7713 # 'empty' portion of the gauge), then draw at least one pixel
7714 } elsif ($ratio < 1 && ($x4 - $x3) <= 1) {
7715  
7716 $x2 = $x3 = $x4 - 2;
7717 }
7718  
7719 # Vertical position depends only on the level, and is the same for both portions
7720 # (NB the visible level isn't necessarily the same as the GA::Obj::GaugeLevel
7721 # object's unique number)
7722 $y1 = $self->gaugeSpacingY
7723 + ($visLevel * ($self->gaugeHeight + $self->gaugeSpacingY));
7724 $y2 = $y1 + $self->gaugeHeight - 1;
7725  
7726 if ($blankFlag) {
7727  
7728 # Draw a blank gauge, because one or more values are unspecified (the labels are
7729 # still drawn, though)
7730 $obj = GooCanvas2::CanvasRect->new(
7731 'parent' => $root,
7732 'x' => $x1,
7733 'y' => $y1,
7734 'width' => ($x4 - $x1 + 1),
7735 'height' => ($y2 - $y1 + 1),
7736 'radius-x' => $self->gaugeCorner,
7737 'radius-y' => $self->gaugeCorner,
7738 'line-width' => 1,
7739 'stroke-color' => $self->gaugeBorderColour,
7740 'fill-color' => $self->gaugeBlankColour,
7741 );
7742  
7743 $obj->raise();
7744 push (@canvasObjList, $obj);
7745  
7746 } else {
7747  
7748 # Full gauge portion (don't draw, if empty)
7749 if (($x2 - $x1 + 1) > 1) {
7750  
7751 $obj = GooCanvas2::CanvasRect->new(
7752 'parent' => $root,
7753 'x' => $x1,
7754 'y' => $y1,
7755 'width' => ($x2 - $x1 + 1),
7756 'height' => ($y2 - $y1 + 1),
7757 'radius-x' => $self->gaugeCorner,
7758 'radius-y' => $self->gaugeCorner,
7759 'line-width' => 1,
7760 'stroke-color' => $self->gaugeBorderColour,
7761 'fill-color' => $gaugeObj->fullColour,
7762 );
7763  
7764 $obj->raise();
7765 push (@canvasObjList, $obj);
7766 }
7767  
7768 # Empty gauge portion (don't draw, if empty)
7769 if (($x4 - $x3 + 1) > 1) {
7770  
7771 $obj = GooCanvas2::CanvasRect->new(
7772 'parent' => $root,
7773 'x' => $x3,
7774 'y' => $y1,
7775 'width' => ($x4 - $x3 + 1),
7776 'height' => ($y2 - $y1 + 1),
7777 'radius-x' => $self->gaugeCorner,
7778 'radius-y' => $self->gaugeCorner,
7779 'line-width' => 1,
7780 'stroke-color' => $self->gaugeBorderColour,
7781 'fill-color' => $gaugeObj->emptyColour,
7782 );
7783  
7784 $obj->raise();
7785 push (@canvasObjList, $obj);
7786 }
7787 }
7788  
7789 # Draw a label over the gauge, if one is specified
7790 if ($gaugeObj->label) {
7791  
7792 if (! $gaugeObj->labelFlag) {
7793  
7794 $lText = $gaugeObj->label;
7795  
7796 } else {
7797  
7798 $lText = $gaugeObj->label . ': ';
7799 if (! defined $gaugeObj->value) {
7800 $lText .= '?';
7801 } else {
7802 $lText .= $gaugeObj->value;
7803 }
7804  
7805 if ($gaugeObj->addFlag) {
7806 $lText .= '-';
7807 } else {
7808 $lText .= '/';
7809 }
7810  
7811 if (! defined $gaugeObj->maxValue) {
7812 $lText .= '?';
7813 } else {
7814 $lText .= $gaugeObj->maxValue;
7815 }
7816 }
7817  
7818 if ($blankFlag) {
7819 $lCol = $self->gaugeLabelColour;
7820 } else {
7821 $lCol = $gaugeObj->labelColour;
7822 }
7823  
7824 $obj = GooCanvas2::CanvasText->new(
7825 'parent' => $root,
7826 # 'anchor' => 'nw',
7827 'x' => $x1 + $self->gaugeSpacingX,
7828 'y' => $y1,
7829 'font' => $self->gaugeLabelFont . ' ' . $self->gaugeLabelFontSize,
7830 'use-markup' => FALSE,
7831 'text' => $lText,
7832 'width' => -1,
7833 'fill-color' => $lCol,
7834 );
7835  
7836 $obj->raise();
7837 push (@canvasObjList, $obj);
7838 }
7839  
7840 } else {
7841  
7842 # Text gauges use the full available width
7843 $x1 = $self->gaugeSpacingX + ($count * $w);
7844 $y1 = $self->gaugeSpacingY
7845 + ($visLevel * ($self->gaugeHeight + $self->gaugeSpacingY));
7846  
7847 $lText = '';
7848 if ($gaugeObj->label) {
7849  
7850 $lText .= $gaugeObj->label . ': ';
7851 }
7852  
7853 if (! defined $gaugeObj->value) {
7854 $lText .= '?';
7855 } else {
7856 $lText .= $gaugeObj->value;
7857 }
7858  
7859 # (Don't show a maximum value if the world isn't supplying one)
7860 if (defined $gaugeObj->maxValue) {
7861  
7862 if ($gaugeObj->addFlag) {
7863 $lText .= '-';
7864 } else {
7865 $lText .= '/';
7866 }
7867  
7868 $lText .= $gaugeObj->maxValue;
7869 }
7870  
7871 $obj = GooCanvas2::CanvasText->new(
7872 'parent' => $root,
7873 # 'anchor' => 'nw',
7874 'x' => $x1,
7875 'y' => $y1,
7876 'font' => $self->gaugeLabelFont . ' ' . $self->gaugeLabelFontSize,
7877 'use-markup' => FALSE,
7878 'text' => $lText,
7879 'width' => -1,
7880 # 'fill-color' => $lCol,
7881 );
7882  
7883 $obj->raise();
7884 push (@canvasObjList, $obj);
7885 }
7886 }
7887  
7888 # Store the canvas objects drawn, so they can be destroyed on the next call to this
7889 # function
7890 $self->ivPoke('gaugeDrawnList', @drawList);
7891 $self->ivPoke('gaugeCanvasList', @canvasObjList);
7892  
7893 return 1;
7894 }
7895  
7896 ##################
7897 # Accessors - set
7898  
7899 ##################
7900 # Accessors - get
7901  
7902 sub frame
7903 { $_[0]->{frame} }
7904 sub canvas
7905 { $_[0]->{canvas} }
7906 sub gaugeCanvasList
7907 { my $self = shift; return @{$self->{gaugeCanvasList}}; }
7908  
7909 sub canvasFrameWidth
7910 { $_[0]->{canvasFrameWidth} }
7911 sub canvasFrameHeight
7912 { $_[0]->{canvasFrameHeight} }
7913  
7914 sub gaugeHeight
7915 { $_[0]->{gaugeHeight} }
7916 sub gaugeCorner
7917 { $_[0]->{gaugeCorner} }
7918 sub gaugeSpacingX
7919 { $_[0]->{gaugeSpacingX} }
7920 sub gaugeSpacingY
7921 { $_[0]->{gaugeSpacingY} }
7922 sub gaugeLabelFont
7923 { $_[0]->{gaugeLabelFont} }
7924 sub gaugeLabelFontSize
7925 { $_[0]->{gaugeLabelFontSize} }
7926 sub gaugeLevelHash
7927 { my $self = shift; return %{$self->{gaugeLevelHash}}; }
7928 sub gaugeLevelCount
7929 { $_[0]->{gaugeLevelCount} }
7930 sub gaugeLevelMax
7931 { $_[0]->{gaugeLevelMax} }
7932 sub gaugeCount
7933 { $_[0]->{gaugeCount} }
7934 sub gaugeMax
7935 { $_[0]->{gaugeMax} }
7936 sub gaugeDrawnList
7937 { my $self = shift; return @{$self->{gaugeDrawnList}}; }
7938 sub gaugeUpdateFlag
7939 { $_[0]->{gaugeUpdateFlag} }
7940 sub gaugeBlankColour
7941 { $_[0]->{gaugeBlankColour} }
7942 sub gaugeEmptyColour
7943 { $_[0]->{gaugeEmptyColour} }
7944 sub gaugeFullColour
7945 { $_[0]->{gaugeFullColour} }
7946 sub gaugeLabelColour
7947 { $_[0]->{gaugeLabelColour} }
7948 sub gaugeBorderColour
7949 { $_[0]->{gaugeBorderColour} }
7950 sub gaugeCheckTime
7951 { $_[0]->{gaugeCheckTime} }
7952 sub gaugeWaitTime
7953 { $_[0]->{gaugeWaitTime} }
7954 sub gaugeNoDrawFlag
7955 { $_[0]->{gaugeNoDrawFlag} }
7956 }
7957  
7958 { package Games::Axmud::Strip::SearchBox;
7959  
7960 use strict;
7961 use warnings;
7962 # use diagnostics;
7963  
7964 use Glib qw(TRUE FALSE);
7965  
7966 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
7967  
7968 ##################
7969 # Constructors
7970  
7971 sub new {
7972  
7973 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
7974 # Creates the GA::Strip::SearchBox - a non-compulsory strip object optionally containing
7975 # widgets for searching text in the window's current pane
7976 #
7977 # Expected arguments
7978 # $number - The strip object's number within the parent window (matches
7979 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
7980 # created to access its default IVs)
7981 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
7982 # objects
7983 #
7984 # Optional arguments
7985 # %initHash - A hash containing arbitrary data to use as the strip object's
7986 # initialisation settings. The strip object should use default
7987 # initialisation settings unless it can succesfully interpret one or more
7988 # of the key-value pairs in the hash, if there are any
7989 # - (This type of strip object requires no initialisation settings)
7990 #
7991 # Return values
7992 # 'undef' on improper arguments
7993 # Blessed reference to the newly-created object on success
7994  
7995 my ($class, $number, $winObj, %initHash) = @_;
7996  
7997 # Local variables
7998 my %modHash;
7999  
8000 # Check for improper arguments
8001 if (! defined $class || ! defined $number || ! defined $winObj) {
8002  
8003 return $axmud::CLIENT->writeImproper($class . '->new', @_);
8004 }
8005  
8006 # Setup
8007 my $self = {
8008 _objName => 'strip_' . $number,
8009 _objClass => $class,
8010 _parentFile => undef, # No parent file object
8011 _parentWorld => undef, # No parent file object
8012 _privFlag => TRUE, # All IVs are private
8013  
8014 # Standard strip object IVs
8015 # -------------------------
8016  
8017 # The strip object's number within the parent window (matches
8018 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
8019 # its default IVs)
8020 number => $number,
8021 # The type of strip object (custom strip objects should use a ->type starting with
8022 # 'custom_' to avoid clashing with future built-in strip objects)
8023 type => 'search_box',
8024 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
8025 winObj => $winObj,
8026  
8027 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
8028 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
8029 # still exists in GA::Win::Internal->stripHash, etc)
8030 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
8031 # have gauges to draw, or not, depending on current conditions. (Most strip objects
8032 # have this flag set to TRUE all the time)
8033 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
8034 # called by this object's functions
8035 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
8036 # the flag's value shouldn't be modified by anything other than
8037 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
8038 # $self->set_visibleFlag)
8039 visibleFlag => FALSE, # Wait until the search box needs to be drawn
8040 # Flag set to TRUE is the strip object should be given its share of any extra space
8041 # within the packing box (the extra space is divided equally between all children of
8042 # the box whose ->expandFlag is TRUE)
8043 expandFlag => FALSE,
8044 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
8045 # actually allocated within the strip object, FALSE if it is used as padding outside
8046 # it (on both sides)
8047 fillFlag => TRUE, # Force canvas to use available width
8048 # Flag set to TRUE if the strip object should be packed into its window with a small
8049 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
8050 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
8051 # for example in the toolbar strip object)
8052 spacingFlag => TRUE,
8053 # Flag set to TRUE if only one instance of this strip object should be added to the
8054 # parent window, set to FALSE if any number of instances can be added
8055 jealousyFlag => TRUE,
8056 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
8057 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
8058 # users)
8059 blindFlag => FALSE,
8060 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
8061 # allowed to accept the focus, FALSE if not. The restriction is applied during the
8062 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
8063 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
8064 # GA::Strip::MenuBar)
8065 allowFocusFlag => FALSE,
8066  
8067 # Initialisation settings stored as a hash (see the comments above)
8068 initHash => \%modHash,
8069 # Reference to a function to call when some widget is used. This IV is set only when
8070 # required by this type of strip object. It can be set by a call to
8071 # $self->set_func() or by some setting in $self->initHash, which is applied in the
8072 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
8073 # generic object function Games::Axmud->getMethodRef()
8074 funcRef => undef,
8075 # A value passed to ->funcRef when it is called which identifies this strip object and
8076 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
8077 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
8078 # to $self->objEnable()
8079 funcID => undef,
8080  
8081 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
8082 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
8083 packingBox => undef, # Gtk3::VBox
8084  
8085 # Other IVs
8086 # ---------
8087  
8088 # Widgets
8089 findEntry => undef, # Gtk3::Entry
8090 prevButton => undef, # Gtk3::Button
8091 nextButton => undef, # Gtk3::Button
8092 resetButton => undef, # Gtk3::Button
8093 caseButton => undef, # Gtk3::ToggleButton
8094 regexButton => undef, # Gtk3::ToggleButton
8095 splitButton => undef, # Gtk3::ToggleButton
8096  
8097 # Flags set to TRUE when the 'Case senstive', 'Use regex' and 'Split screen' buttons are
8098 # selected, FALSE when they are not selected
8099 caseFlag => FALSE,
8100 regexFlag => FALSE,
8101 splitFlag => FALSE,
8102  
8103 # The number of the textview object (GA::Obj::TextView) that was last search; required
8104 # in case the window's current pane is changed (when the user clicks a button in the
8105 # entry strip object)
8106 textViewNum => undef,
8107 };
8108  
8109 # Bless the object into existence
8110 bless $self, $class;
8111  
8112 return $self;
8113 }
8114  
8115 ##################
8116 # Methods
8117  
8118 # Standard strip object functions
8119  
8120 sub objEnable {
8121  
8122 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
8123 # Sets up the strip object's widgets
8124 #
8125 # Expected arguments
8126 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
8127 # parent window
8128 #
8129 # Return values
8130 # 'undef' on improper arguments
8131 # 1 on success
8132  
8133 my ($self, $winmapObj, $check) = @_;
8134  
8135 # Check for improper arguments
8136 if (! defined $winmapObj || defined $check) {
8137  
8138 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
8139 }
8140  
8141 # (IVs normally updated here are updated by $self->drawSearchBox, when it is called)
8142  
8143 return 1;
8144 }
8145  
8146 # sub objDestroy {} # Inherited from GA::Generic::Strip
8147  
8148 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Strip
8149  
8150 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Strip
8151  
8152 # ->signal_connects
8153  
8154 # Other functions
8155  
8156 sub drawSearchBox {
8157  
8158 # Called by $self->toggleBox
8159 # Draws a Gtk3::HBox to contain various widgets
8160 #
8161 # Expected arguments
8162 # (none besides $self)
8163 #
8164 # Return values
8165 # 'undef' on improper arguments
8166 # 1 otherwise
8167  
8168 my ($self, $check) = @_;
8169  
8170 # Check for improper arguments
8171 if (defined $check) {
8172  
8173 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawSearchBox', @_);
8174 }
8175  
8176 # Create a packing box
8177 my $packingBox = Gtk3::HBox->new(FALSE, 0);
8178 $packingBox->set_border_width(0);
8179  
8180 # Add some widgets for performing searches
8181 my $findLabel = Gtk3::Label->new();
8182 $packingBox->pack_start($findLabel, FALSE, FALSE, 5);
8183 $findLabel->set_markup('Find:');
8184  
8185 my $findEntry = Gtk3::Entry->new();
8186 $packingBox->pack_start($findEntry, TRUE, TRUE, 5);
8187 # ->signal_connects appear below
8188  
8189 my $prevButton = Gtk3::ToolButton->new(
8190 Gtk3::Image->new_from_file(
8191 $axmud::SHARE_DIR . $axmud::CLIENT->constUpIconPath,
8192 ),
8193 'Previous match',
8194 );
8195 $packingBox->pack_start($prevButton, FALSE, FALSE, 0);
8196 $prevButton->set_tooltip_text('Previous match');
8197 $prevButton->set_sensitive(FALSE);
8198 $prevButton->signal_connect('clicked' => sub {
8199  
8200 $self->doSearch(FALSE);
8201 });
8202  
8203 my $nextButton = Gtk3::ToolButton->new(
8204 Gtk3::Image->new_from_file(
8205 $axmud::SHARE_DIR . $axmud::CLIENT->constDownIconPath,
8206 ),
8207 'Next match',
8208 );
8209 $packingBox->pack_start($nextButton, FALSE, FALSE, 0);
8210 $nextButton->set_tooltip_text('Next match');
8211 $nextButton->set_sensitive(FALSE);
8212 $nextButton->signal_connect('clicked' => sub {
8213  
8214 $self->doSearch(TRUE);
8215 });
8216  
8217 my $separator = Gtk3::SeparatorToolItem->new();
8218 $packingBox->pack_start($separator, FALSE, FALSE, 0);
8219  
8220 my $resetButton = Gtk3::ToolButton->new(
8221 Gtk3::Image->new_from_file(
8222 $axmud::SHARE_DIR . $axmud::CLIENT->constResetIconPath,
8223 ),
8224 'Reset search box',
8225 );
8226 $packingBox->pack_start($resetButton, FALSE, FALSE, 0);
8227 $resetButton->set_tooltip_text('Reset search box');
8228 $resetButton->set_sensitive(FALSE);
8229 $resetButton->signal_connect('clicked' => sub {
8230  
8231 $self->doReset();
8232 });
8233  
8234 my $separator2 = Gtk3::SeparatorToolItem->new();
8235 $packingBox->pack_start($separator2, FALSE, FALSE, 0);
8236  
8237 my $caseButton = Gtk3::ToggleButton->new();
8238 $packingBox->pack_start($caseButton, FALSE, FALSE, 0);
8239 $caseButton->set_image(
8240 Gtk3::Image->new_from_file(
8241 $axmud::SHARE_DIR . $axmud::CLIENT->constCaseIconPath,
8242 )
8243 );
8244 $caseButton->set_tooltip_text('Case-sensitive searches');
8245 if ($self->caseFlag) {
8246  
8247 $caseButton->set_active(TRUE);
8248 }
8249 $caseButton->signal_connect('toggled' => sub {
8250  
8251 if (! $caseButton->get_active()) {
8252 $self->ivPoke('caseFlag', FALSE);
8253 } else {
8254 $self->ivPoke('caseFlag', TRUE);
8255 }
8256 });
8257  
8258 my $regexButton = Gtk3::ToggleButton->new();
8259 $packingBox->pack_start($regexButton, FALSE, FALSE, 0);
8260 $regexButton->set_image(
8261 Gtk3::Image->new_from_file(
8262 $axmud::SHARE_DIR . $axmud::CLIENT->constRegexIconPath,
8263 )
8264 );
8265 $regexButton->set_tooltip_text('Use patterns/regular expressions');
8266 if ($self->regexFlag) {
8267  
8268 $regexButton->set_active(TRUE);
8269 }
8270 $regexButton->signal_connect('toggled' => sub {
8271  
8272 if (! $regexButton->get_active()) {
8273 $self->ivPoke('regexFlag', FALSE);
8274 } else {
8275 $self->ivPoke('regexFlag', TRUE);
8276 }
8277 });
8278  
8279 my $splitButton = Gtk3::ToggleButton->new();
8280 $packingBox->pack_start($splitButton, FALSE, FALSE, 0);
8281 $splitButton->set_image(
8282 Gtk3::Image->new_from_file(
8283 $axmud::SHARE_DIR . $axmud::CLIENT->constDivideIconPath,
8284 )
8285 );
8286 $splitButton->set_tooltip_text('Split screen after a search');
8287 if ($self->splitFlag) {
8288  
8289 $splitButton->set_active(TRUE);
8290 }
8291 $splitButton->signal_connect('toggled' => sub {
8292  
8293 $self->toggleSplit($splitButton->get_active());
8294 });
8295  
8296 # ->signal_connects from above
8297 $findEntry->signal_connect('activate' => sub {
8298  
8299 # (Same as clicking the 'Previous' button)
8300 $findEntry->grab_focus();
8301 $self->doSearch(FALSE);
8302 });
8303 $findEntry->signal_connect('changed' => sub {
8304  
8305 my $text = $findEntry->get_text();
8306  
8307 if ($text eq '') {
8308  
8309 $prevButton->set_sensitive(FALSE);
8310 $nextButton->set_sensitive(FALSE);
8311 $resetButton->set_sensitive(FALSE);
8312  
8313 } else {
8314  
8315 $prevButton->set_sensitive(TRUE);
8316 $nextButton->set_sensitive(TRUE);
8317 $resetButton->set_sensitive(TRUE);
8318 }
8319 });
8320  
8321 # Update IVs
8322 $self->ivPoke('packingBox', $packingBox);
8323 $self->ivPoke('findEntry', $findEntry);
8324 $self->ivPoke('prevButton', $prevButton);
8325 $self->ivPoke('nextButton', $nextButton);
8326 $self->ivPoke('resetButton', $resetButton);
8327 $self->ivPoke('caseButton', $caseButton);
8328 $self->ivPoke('regexButton', $regexButton);
8329 $self->ivPoke('splitButton', $splitButton);
8330 # Previous searches are not relevant
8331 $self->ivUndef('textViewNum');
8332  
8333 # Setup complete
8334 return 1;
8335 }
8336  
8337 sub doSearch {
8338  
8339 # Called by various ->signal_connects in $self->drawSearchBox
8340 # Checks that the entry box contains some text and, if so, performs a search
8341 #
8342 # Expected arguments
8343 # $nextFlag - FALSE to search backwards in a textview object; TRUE to search forwards
8344 # in a textview
8345 #
8346 # Return values
8347 # 'undef' on improper arguments or if the user hasn't entered any text in the entry box
8348 # 1 otherwise
8349  
8350 my ($self, $nextFlag, $check) = @_;
8351  
8352 # Local variables
8353 my ($text, $entryStripObj, $paneObj, $tabObj, $textViewObj, $matchLine);
8354  
8355 # Check for improper arguments
8356 if (! defined $nextFlag || defined $check) {
8357  
8358 return $axmud::CLIENT->writeImproper($self->_objClass . '->doSearch', @_);
8359 }
8360  
8361 # Get the text to search
8362 if ($self->findEntry) {
8363  
8364 $text = $self->findEntry->get_text();
8365 }
8366  
8367 if (! defined $text || $text eq '') {
8368  
8369 return undef;
8370 }
8371  
8372 # Get the current pane, i.e. the first pane object in this window's
8373 # GA::Strip::Entry->paneObjList
8374 $entryStripObj = $self->winObj->getStrip('entry');
8375 if ($entryStripObj) {
8376  
8377 $paneObj = $entryStripObj->ivIndex('paneObjList', 0);
8378 }
8379  
8380 if (! $paneObj) {
8381  
8382 # There are no window panes, therefore there is no text to search
8383 return undef;
8384 }
8385  
8386 # Get the textview object in the pane object's visible tab
8387 $tabObj = $paneObj->getVisibleTab();
8388 if ($tabObj) {
8389  
8390 $textViewObj = $tabObj->textViewObj;
8391 }
8392  
8393 if (! $textViewObj) {
8394  
8395 # No textview object found, therefore there is no text to search
8396 return undef;
8397 }
8398  
8399 # If the previous search was conducted on a different textview (or if this is the first
8400 # search), start searching from the bottom (or top)
8401 if (! defined $self->textViewNum || $self->textViewNum != $textViewObj->number) {
8402  
8403 $self->ivPoke('textViewNum', $textViewObj->number);
8404  
8405 # Create a search mark at the end of the buffer, which moves up and down the buffer
8406 # every time the use clicks the 'Previous' or 'Next' buttons
8407 $textViewObj->setSearchMark();
8408 }
8409  
8410 # Split the screen, if required
8411 if ($self->splitFlag && $textViewObj->splitScreenMode ne 'split') {
8412  
8413 $paneObj->toggleSplitScreen()
8414 }
8415  
8416 # Convert a simple string to a regex, if required (otherwise, assume that $text is already
8417 # a regex)
8418 if (! $self->regexFlag) {
8419  
8420 $text = quotemeta($text);
8421 }
8422  
8423 # Perform the search. The TRUE argument means to select and scroll to the matching text
8424 ($matchLine) = $textViewObj->searchBuffer($text, $nextFlag, TRUE, $self->caseFlag);
8425 if (! defined $matchLine) {
8426 $self->findEntry->set_icon_from_stock('secondary', 'gtk-no');
8427 } else {
8428 $self->findEntry->set_icon_from_stock('secondary', 'gtk-yes');
8429 }
8430  
8431 return 1;
8432 }
8433  
8434 sub doReset {
8435  
8436 # Called by a ->signal_connect in $self->drawSearchBox, and by $self->doReset
8437 # Resets the search box and the textview object's search position. Unselects any selected
8438 # text
8439 #
8440 # Expected arguments
8441 # (none besides $self)
8442 #
8443 # Return values
8444 # 'undef' on improper arguments
8445 # 1 otherwise
8446  
8447 my ($self, $check) = @_;
8448  
8449 # Local variables
8450 my ($entryStripObj, $paneObj, $tabObj, $textViewObj);
8451  
8452 # Check for improper arguments
8453 if (defined $check) {
8454  
8455 return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_);
8456 }
8457  
8458 # Update widgets
8459 $self->findEntry->set_text('');
8460 $self->findEntry->set_icon_from_stock('secondary', undef);
8461  
8462 # Get the current pane, i.e. the first pane object in this window's
8463 # GA::Strip::Entry->paneObjList
8464 $entryStripObj = $self->winObj->getStrip('entry');
8465 if ($entryStripObj) {
8466  
8467 $paneObj = $entryStripObj->ivIndex('paneObjList', 0);
8468 }
8469  
8470 if (! $paneObj) {
8471  
8472 # There are no window panes, therefore there is no search position to reset
8473 return 1;
8474 }
8475  
8476 # Get the textview object in the pane object's visible tab
8477 $tabObj = $paneObj->getVisibleTab();
8478 if ($tabObj) {
8479  
8480 $textViewObj = $tabObj->textViewObj;
8481 }
8482  
8483 if (! $textViewObj) {
8484  
8485 # No textview object found, therefore there is no search position to reset
8486 return 1;
8487 }
8488  
8489 # Reset the textview's search position, so that the next search starts from the bottom (or
8490 # top)
8491 $textViewObj->setSearchMark();
8492 # Un-select any selected text
8493 $textViewObj->unselectText();
8494  
8495 # If split-screen mode is enabled, disable it
8496 if ($textViewObj->splitScreenMode eq 'split') {
8497  
8498 $paneObj->toggleSplitScreen();
8499 }
8500  
8501 return 1;
8502 }
8503  
8504 sub toggleSplit {
8505  
8506 # Called by a ->signal_connect in $self->drawSearchBox after the 'Split screen' is clicked
8507 # Updates the value of the IV. If the current textview's split screen mode is on, turn it
8508 # off
8509 #
8510 # Expected arguments
8511 # $flag - TRUE if the button has been selected, FALSE if it has been deselected
8512 #
8513 # Return values
8514 # 'undef' on improper arguments
8515 # 1 otherwise
8516  
8517 my ($self, $flag, $check) = @_;
8518  
8519 # Local variables
8520 my ($entryStripObj, $paneObj, $tabObj, $textViewObj);
8521  
8522 # Check for improper arguments
8523 if (! defined $flag || defined $check) {
8524  
8525 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleSplit', @_);
8526 }
8527  
8528 if (! $flag) {
8529  
8530 $self->ivPoke('splitFlag', FALSE);
8531  
8532 # Get the current pane, i.e. the first pane object in this window's
8533 # GA::Strip::Entry->paneObjList
8534 $entryStripObj = $self->winObj->getStrip('entry');
8535 if ($entryStripObj) {
8536  
8537 $paneObj = $entryStripObj->ivIndex('paneObjList', 0);
8538 if ($paneObj) {
8539  
8540 # Get the textview object in the pane object's visible tab
8541 $tabObj = $paneObj->getVisibleTab();
8542 if ($tabObj) {
8543  
8544 $textViewObj = $tabObj->textViewObj;
8545 }
8546 }
8547 }
8548  
8549 if ($textViewObj && $textViewObj->splitScreenMode eq 'split') {
8550  
8551 $paneObj->toggleSplitScreen();
8552 }
8553  
8554 } else {
8555  
8556 $self->ivPoke('splitFlag', TRUE);
8557 }
8558  
8559 return 1;
8560 }
8561  
8562 sub toggleBox {
8563  
8564 # Called by GA::Strip::Entry->setInputSignals
8565 # If the strip object is visible, hide it (and vice-versa)
8566 #
8567 # Expected arguments
8568 # (none besides $self)
8569 #
8570 # Return values
8571 # 'undef' on improper arguments
8572 # 1 otherwise
8573  
8574 my ($self, $check) = @_;
8575  
8576 # Check for improper arguments
8577 if (defined $check) {
8578  
8579 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleBox', @_);
8580 }
8581  
8582 if (! $self->visibleFlag) {
8583  
8584 # Reveal the search box
8585 $self->drawSearchBox();
8586 $self->winObj->revealStripObj($self);
8587  
8588 } else {
8589  
8590 # Hide the search box
8591 $self->doReset();
8592 $self->winObj->hideStripObj($self);
8593 }
8594  
8595 return 1;
8596 }
8597  
8598 ##################
8599 # Accessors - set
8600  
8601 ##################
8602 # Accessors - get
8603  
8604 sub findEntry
8605 { $_[0]->{findEntry} }
8606 sub prevButton
8607 { $_[0]->{prevButton} }
8608 sub nextButton
8609 { $_[0]->{nextButton} }
8610 sub resetButton
8611 { $_[0]->{resetButton} }
8612 sub caseButton
8613 { $_[0]->{caseButton} }
8614 sub regexButton
8615 { $_[0]->{regexButton} }
8616 sub splitButton
8617 { $_[0]->{splitButton} }
8618  
8619 sub caseFlag
8620 { $_[0]->{caseFlag} }
8621 sub regexFlag
8622 { $_[0]->{regexFlag} }
8623 sub splitFlag
8624 { $_[0]->{splitFlag} }
8625  
8626 sub textViewNum
8627 { $_[0]->{textViewNum} }
8628 }
8629  
8630 { package Games::Axmud::Strip::Entry;
8631  
8632 use strict;
8633 use warnings;
8634 # use diagnostics;
8635  
8636 use Glib qw(TRUE FALSE);
8637  
8638 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
8639  
8640 ##################
8641 # Constructors
8642  
8643 sub new {
8644  
8645 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
8646 # Creates the GA::Strip::Entry - a non-compulsory strip object containing a Gtk3::Entry
8647 #
8648 # Expected arguments
8649 # $number - The strip object's number within the parent window (matches
8650 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
8651 # created to access its default IVs)
8652 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
8653 # objects
8654 #
8655 # Optional arguments
8656 # %initHash - A hash containing arbitrary data to use as the strip object's
8657 # initialisation settings. The strip object should use default
8658 # initialisation settings unless it can succesfully interpret one or more
8659 # of the key-value pairs in the hash, if there are any
8660 # - This type of strip object recognises these initialisation settings:
8661 #
8662 # 'func' - Reference to a function to call when the user types something
8663 # in the entry box and presses 'return'. If not specified or 'undef',
8664 # it's up to the calling code to create its own ->signal_connect.
8665 # Ignored in 'main' windows, for which a ->signal_connect is always
8666 # created by this strip object. To obtain a reference to an OOP
8667 # method, you can use the generic object function
8668 # Games::Axmud->getMethodRef()
8669 # 'id' - A value passed to the function which identifies the button. If
8670 # specified, can be any value except 'undef'. It's up to the
8671 # calling code to keep track of the widgets it has created and their
8672 # corresponding 'id' values
8673 # 'wipe_flag' - TRUE if a 'wipe entry' button should be drawn to the left
8674 # of the entry box, FALSE if not (default is FALSE)
8675 # 'add_flag' - TRUE if an 'add entry' button should be drawn to the left
8676 # of the entry box, FALSE if not (default is FALSE)
8677 # 'console_flag' - TRUE if a 'toggle console' button should be drawn to
8678 # the right of the entry box, FALSE if not (default is FALSE)
8679 # 'input_flag' - TRUE if a 'toggle expand' button (for opening the quick
8680 # input window) should be drawn to the right of the entry box, FALSE
8681 # if not (default is FALSE)
8682 # 'search_flag' - TRUE if a 'search' button (for opening the search box
8683 # strip object) shown be drawn to the right of the entry box, FALSE if
8684 # not (default is FALSE)
8685 # 'cancel_flag' - TRUE if a 'cancel repeating/excess commands' button
8686 # should be drawn to the right of the entry box, FALSE if not (default
8687 # is FALSE)
8688 # 'switch_flag' - TRUE if a 'switch active pane' button should be drawn to
8689 # the right of the entry box, FALSE if not (default is FALSE)
8690 # 'scroll_flag' - TRUE if a 'scroll lock' button should be drawn to the
8691 # right of the entry box, FALSE if not (default is FALSE)
8692 # 'split_flag' - TRUE if a 'split screen' button should be drawn to the
8693 # right of the entry box, FALSE if not (default is FALSE)
8694 #
8695 # Return values
8696 # 'undef' on improper arguments
8697 # Blessed reference to the newly-created object on success
8698  
8699 my ($class, $number, $winObj, %initHash) = @_;
8700  
8701 # Local variables
8702 my %modHash;
8703  
8704 # Check for improper arguments
8705 if (! defined $class || ! defined $number || ! defined $winObj) {
8706  
8707 return $axmud::CLIENT->writeImproper($class . '->new', @_);
8708 }
8709  
8710 # Default initialisation settings
8711 %modHash = (
8712 'func' => undef,
8713 'id' => '',
8714 'wipe_flag' => FALSE,
8715 'add_flag' => FALSE,
8716 'console_flag' => FALSE,
8717 'input_flag' => FALSE,
8718 'search_flag' => FALSE,
8719 'cancel_flag' => FALSE,
8720 'switch_flag' => FALSE,
8721 'scroll_flag' => FALSE,
8722 'split_flag' => FALSE,
8723 );
8724  
8725 # Interpret the initialisation settings in %initHash, if any
8726 foreach my $key (keys %modHash) {
8727  
8728 if ($key eq 'id' && ! defined $initHash{$key}) {
8729  
8730 $modHash{$key} = ''; # 'id' value must not be 'undef'
8731  
8732 } elsif ($key eq 'func' || $key eq 'id') {
8733  
8734 $modHash{$key} = $initHash{$key};
8735  
8736 } elsif (exists $initHash{$key}) {
8737  
8738 if ($initHash{$key}) {
8739 $modHash{$key} = TRUE;
8740 } else {
8741 $modHash{$key} = FALSE;
8742 }
8743 }
8744 }
8745  
8746 # Setup
8747 my $self = {
8748 _objName => 'strip_' . $number,
8749 _objClass => $class,
8750 _parentFile => undef, # No parent file object
8751 _parentWorld => undef, # No parent file object
8752 _privFlag => TRUE, # All IVs are private
8753  
8754 # Standard strip object IVs
8755 # -------------------------
8756  
8757 # The strip object's number within the parent window (matches
8758 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to
8759 # access its default IVs)
8760 number => $number,
8761 # The type of strip object (custom strip objects should use a ->type starting with
8762 # 'custom_' to avoid clashing with future built-in strip objects)
8763 type => 'entry',
8764 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
8765 winObj => $winObj,
8766  
8767 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
8768 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
8769 # still exists in GA::Win::Internal->stripHash, etc)
8770 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
8771 # have gauges to draw, or not, depending on current conditions. (Most strip objects
8772 # have this flag set to TRUE all the time)
8773 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
8774 # called by this object's functions
8775 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
8776 # the flag's value shouldn't be modified by anything other than
8777 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
8778 # $self->set_visibleFlag)
8779 visibleFlag => TRUE,
8780 # Flag set to TRUE is the strip object should be given its share of any extra space
8781 # within the packing box (the extra space is divided equally between all children of
8782 # the box whose ->expandFlag is TRUE)
8783 expandFlag => FALSE,
8784 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
8785 # actually allocated within the strip object, FALSE if it is used as padding outside
8786 # it (on both sides)
8787 fillFlag => FALSE,
8788 # Flag set to TRUE if the strip object should be packed into its window with a small
8789 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
8790 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
8791 # for example in the toolbar strip object)
8792 spacingFlag => TRUE,
8793 # Flag set to TRUE if only one instance of this strip object should be added to the
8794 # parent window, set to FALSE if any number of instances can be added
8795 jealousyFlag => TRUE,
8796 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
8797 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
8798 # users)
8799 blindFlag => TRUE,
8800 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
8801 # allowed to accept the focus, FALSE if not. The restriction is applied during the
8802 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
8803 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
8804 # GA::Strip::MenuBar)
8805 allowFocusFlag => FALSE,
8806  
8807 # Initialisation settings stored as a hash (see the comments above)
8808 initHash => \%modHash,
8809 # Reference to a function to call when some widget is used. This IV is set only when
8810 # required by this type of strip object. It can be set by a call to
8811 # $self->set_func() or by some setting in $self->initHash, which is applied in the
8812 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
8813 # generic object function Games::Axmud->getMethodRef()
8814 funcRef => undef,
8815 # A value passed to ->funcRef when it is called which identifies this strip object and
8816 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
8817 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
8818 # to $self->objEnable()
8819 funcID => undef,
8820  
8821 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
8822 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
8823 packingBox => undef, # Gtk3::HBox
8824  
8825 # Other IVs
8826 # ---------
8827  
8828 # Widgets
8829 entry => undef, # Gtk3::Entry
8830 preEntry => undef, # Gtk3::Entry
8831 postEntry => undef, # Gtk3::Entry
8832 wipeButton => undef, # Gtk3::ToolButton
8833 addButton => undef, # Gtk3::ToolButton
8834 consoleButton => undef, # Gtk3::ToolButton
8835 inputButton => undef, # Gtk3::ToolButton
8836 searchButton => undef, # Gtk3::ToolButton
8837 cancelButton => undef, # Gtk3::ToolButton
8838 switchButton => undef, # Gtk3::ToolButton
8839 scrollButton => undef, # Gtk3::ToolButton
8840 splitButton => undef, # Gtk3::ToolButton
8841  
8842 # List of currently-existing pane objects. New pane objects are added to the end of the
8843 # list. The first pane object in the list is the one to which the scroll and split
8844 # buttons apply. Clicking the switch buttons moves the first pane in the list to the
8845 # end, so that the next pane object becomes the one to which the scroll and split
8846 # buttons apply
8847 # Keypresses captured by GA::Win::Internal are also applied to the first pane object
8848 # in the list
8849 paneObjList => [],
8850  
8851 # The strip can contain one, two or three entry boxes; a main one (stored in
8852 # $self->entry), a small box whose contents is prepended to every world commmand
8853 # ($self->preEntry), and a small box whose contents is appended to every world
8854 # command ($self->postEntry). Click $self->addButton cycles through different
8855 # combinations of these boxes; this IV stores the state we're in at the moment:
8856 # 'default' - show only the main entry box
8857 # 'pre' - show the prepending and main entry boxes
8858 # 'post' - show the main and appending entry boxes
8859 # 'both' - show all three boxes
8860 entryBoxMode => 'default',
8861 # For 'main' windows, when GA::Client->autoCompleteMode = 'auto', the first time the
8862 # user presses the 'up' or 'down' arrow key, this IV is set to the contents of the
8863 # entry box (even if it's an empty string). The IV is set back to 'undef' as soon as
8864 # the user presses the ENTER key
8865 originalEntryText => undef,
8866 # Any code can temporarily desensitise the entry box(es), when required, by calling
8867 # $self->captureEntry, which adds an entry to this hash IV
8868 # The entry box remains potentially desensitised until the next call to
8869 # $self->captureEntry removes the entry in the hash IV
8870 # 'Potentially desensitised' means that the entry box is desensitised when any of the
8871 # sessions in this hash IV are the parent window's visible session, but is
8872 # sensitised when some other session is the parent window's visible session
8873 # Hash in the form
8874 # $captureHash{session_number} = undef
8875 captureHash => {},
8876 # The current state of the console button, representing the icon to use when the button
8877 # isn't flashing. Set to 'empty', 'system', 'debug' or 'error' (or 'undef' if the
8878 # button isn't visible)
8879 consoleIconType => undef,
8880 # The temporary state of the console button, representing the icon to use when the
8881 # button is flashing. Set to 'system', 'debug' or 'error' (or 'undef' if the button
8882 # isn't visible)
8883 consoleIconTempType => undef,
8884 # When a system message is waiting to be displayed in a Session Console window, the
8885 # button may be made to flash by periodic calls to $self->set_consoleIconFlash. When
8886 # not flashing, this value is set to TRUE; when flashing, it is alternately set to
8887 # FALSE and TRUE
8888 consoleIconFlashFlag => TRUE,
8889  
8890 # Special echo mode. This flag is set by a call to $self->set_specialEchoFlag
8891 # When TRUE, characters are sent to the world, one at a time, as soon as they're typed
8892 # When false, instructions aren't executed until the user presses their RETURN key
8893 specialEchoFlag => FALSE,
8894 # When special echo mode is enabled and the entry box contains a non-world command (for
8895 # example, a client command), this is flag is set to TRUE (so that the escape, tab,
8896 # backspace and delete keys are applied to the contents of the entry, not sent to the
8897 # world directly)
8898 specialPreserveFlag => FALSE,
8899 # When special echo mode is enabled and ->specialPreserveFlag is TRUE, meaning that a
8900 # world command is being typed in the entry box (one letter at a time), the world
8901 # command is stored here, so it can be passed to the GA::Session
8902 # At all other times, this IV is set to an empty string
8903 specialWorldCmd => '',
8904  
8905 # The primary Gtk stock icon currently used in the (main) entry box (e.g. 'gtk-yes',
8906 # 'gtk-media-pause'). 'undef' if no icon used
8907 # The seceondary icon is reset whenever the visible session changes anyway, so is not
8908 # stored as an IV
8909 primaryIcon => undef,
8910  
8911 # When a 'main' window switches between visible sessions, we need to preserve the
8912 # current values of those IVs
8913 # Hash in the form
8914 # $sessionHash{session_number} = list_reference
8915 # ...where 'list_reference' is a list in the form
8916 # (special_echo_flag, special_preserve_flag, special_world_cmd, primary_icon)
8917 sessionHash => {},
8918 # IV set whenever $self->setWidgetsChangeSession is called, recording the visible
8919 # session's unique number (if there is one), or set to 'undef' (if there is no visible
8920 # session)
8921 # The next call to ->setWidgetsChangeSession can then update the hash just above, using
8922 # the previous visible session's settings
8923 prevVisibleSession => undef,
8924 };
8925  
8926 # Bless the object into existence
8927 bless $self, $class;
8928  
8929 return $self;
8930 }
8931  
8932 ##################
8933 # Methods
8934  
8935 # Standard strip object functions
8936  
8937 sub objEnable {
8938  
8939 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
8940 # Sets up the strip object's widgets
8941 #
8942 # Expected arguments
8943 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
8944 # parent window
8945 #
8946 # Return values
8947 # 'undef' on improper arguments
8948 # 1 on success
8949  
8950 my ($self, $winmapObj, $check) = @_;
8951  
8952 # Local variables
8953 my ($mainText, $preText, $postText);
8954  
8955 # Check for improper arguments
8956 if (! defined $winmapObj || defined $check) {
8957  
8958 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
8959 }
8960  
8961 # Create a packing box, if one doesn't exist already
8962 my $packingBox;
8963 if (! $self->packingBox) {
8964  
8965 # This function is being called for the first time
8966 $packingBox = Gtk3::HBox->new(FALSE, 0);
8967 $packingBox->set_border_width(0);
8968  
8969 } else {
8970  
8971 # This function is being called for a subsequent time. Temporarily store the contents
8972 # of the entry box(es), so they can be replaced
8973 $mainText = $self->entry->get_text();
8974 if ($self->preEntry) {
8975  
8976 $preText = $self->preEntry->get_text();
8977 }
8978  
8979 if ($self->postEntry) {
8980  
8981 $postText = $self->postEntry->get_text();
8982 }
8983  
8984 # Remove the packing box's current contents, so new widgets can be created
8985 $packingBox = $self->packingBox;
8986 foreach my $child ($self->packingBox->get_children()) {
8987  
8988 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $child);
8989 }
8990 }
8991  
8992 # Draw a Gtk3::Entry box (compulsory) and any buttons specified by $self->initHash
8993 # (->signal_connects for each appear later in the function)
8994  
8995 # Draw a 'wipe entry' icon as a toolbutton (optional)
8996 my $wipeButton;
8997 if ($self->ivShow('initHash', 'wipe_flag') && ! $axmud::BLIND_MODE_FLAG) {
8998  
8999 $wipeButton = Gtk3::ToolButton->new(
9000 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constWipeIconPath),
9001 'Clear command entry box',
9002 );
9003 $packingBox->pack_start($wipeButton, FALSE, FALSE, 0);
9004 $wipeButton->set_tooltip_text('Clear command entry box');
9005 }
9006  
9007 # Draw an 'add entries' icon as a toolbutton (optional)
9008 my $addButton;
9009 if ($self->ivShow('initHash', 'add_flag') && ! $axmud::BLIND_MODE_FLAG) {
9010  
9011 $addButton = Gtk3::ToolButton->new(
9012 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constAddIconPath),
9013 'Use additional entry boxes',
9014 );
9015 $packingBox->pack_start($addButton, FALSE, FALSE, 0);
9016 $addButton->set_tooltip_text('Use additional entry boxes');
9017 }
9018  
9019 # Draw one or more entry boxes, depending on the value of $self->entryBoxMode
9020 my ($entry, $preEntry, $postEntry);
9021  
9022 # Draw the prepending entry box, if allowed
9023 if ($self->entryBoxMode eq 'pre' || $self->entryBoxMode eq 'both') {
9024  
9025 $preEntry = Gtk3::Entry->new();
9026 $packingBox->pack_start($preEntry, FALSE, FALSE, 0);
9027 $preEntry->set_tooltip_text('Add to beginning of world commands');
9028 if (defined $preText && $preText ne '') {
9029  
9030 $preEntry->set_text($preText);
9031 }
9032 }
9033  
9034 # Draw the main entry box
9035 $entry = Gtk3::Entry->new();
9036 $packingBox->pack_start($entry, TRUE, TRUE, 0);
9037 $entry->set_tooltip_text('Command entry box');
9038 if (defined $mainText && $mainText ne '') {
9039  
9040 $entry->set_text($mainText);
9041 }
9042  
9043 # Draw the appending entry box, if allowed
9044 if ($self->entryBoxMode eq 'post' || $self->entryBoxMode eq 'both') {
9045  
9046 $postEntry = Gtk3::Entry->new();
9047 $packingBox->pack_start($postEntry, FALSE, FALSE, 0);
9048 $postEntry->set_tooltip_text('Add to end of world commands');
9049 if (defined $postText && $postText ne '') {
9050  
9051 $postEntry->set_text($postText);
9052 }
9053 }
9054  
9055 # The main entry is the only 'internal' window widget which can accept focus
9056 $entry->set_can_focus(TRUE);
9057 # For 'main' windows, the entries start desensitised. Afterwards, they are sensitised or
9058 # desensitised (as appropriate) by $self->setWidgetsIfSession. For other kinds of
9059 # 'internal' window, the entries start sensitised
9060 # Any other parts of the code which need to desensitise the entries temporarily should call
9061 # $self->captureEntry
9062 if ($self->winObj->winType eq 'main') {
9063  
9064 $entry->set_sensitive(FALSE);
9065 if ($preEntry) {
9066  
9067 $preEntry->set_sensitive(FALSE);
9068 }
9069  
9070 if ($postEntry) {
9071  
9072 $postEntry->set_sensitive(FALSE);
9073 }
9074 }
9075  
9076 # Draw a 'toggle console' icon as a toolbutton (optional)
9077 my $consoleButton;
9078 if ($self->ivShow('initHash', 'console_flag') && ! $axmud::BLIND_MODE_FLAG) {
9079  
9080 $consoleButton = Gtk3::ToolButton->new(
9081 Gtk3::Image->new_from_file(
9082 $axmud::SHARE_DIR . $axmud::CLIENT->constEmptyIconPath,
9083 ),
9084 'Open Session Console window',
9085 );
9086 $packingBox->pack_start($consoleButton, FALSE, FALSE, 0);
9087 $consoleButton->set_tooltip_text('Open Session Console window');
9088 $consoleButton->set_sensitive(FALSE);
9089  
9090 $self->ivPoke('consoleIconType', 'empty');
9091 $self->ivPoke('consoleIconTempType', 'empty');
9092 }
9093  
9094 # Draw a 'toggle expand' icon as a toolbutton (optional)
9095 my $inputButton;
9096 if ($self->ivShow('initHash', 'input_flag') && ! $axmud::BLIND_MODE_FLAG) {
9097  
9098 $inputButton = Gtk3::ToolButton->new(
9099 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constMultiIconPath),
9100 'Open Quick Input window',
9101 );
9102 $packingBox->pack_start($inputButton, FALSE, FALSE, 0);
9103 $inputButton->set_tooltip_text('Open Quick Input window');
9104 $inputButton->set_sensitive(FALSE);
9105 }
9106  
9107 # Draw a 'toggle search' icon as a toolbutton (optional)
9108 my $searchButton;
9109 if ($self->ivShow('initHash', 'search_flag') && ! $axmud::BLIND_MODE_FLAG) {
9110  
9111 $searchButton = Gtk3::ToolButton->new(
9112 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constSearchIconPath),
9113 'Open search box',
9114 );
9115 $packingBox->pack_start($searchButton, FALSE, FALSE, 0);
9116 $searchButton->set_tooltip_text('Open search box');
9117 $searchButton->set_sensitive(FALSE);
9118 }
9119  
9120 # Draw a 'cancel repeating/excess commands' icon as a toolbutton (optional)
9121 my $cancelButton;
9122 if ($self->ivShow('initHash', 'cancel_flag') && ! $axmud::BLIND_MODE_FLAG) {
9123  
9124 $cancelButton = Gtk3::ToolButton->new(
9125 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constCancelIconPath),
9126 'Cancel repeating/excess commands',
9127 );
9128 $packingBox->pack_start($cancelButton, FALSE, FALSE, 0);
9129 $cancelButton->set_tooltip_text('Cancel repeating/excess commands');
9130 $cancelButton->set_sensitive(FALSE);
9131 }
9132  
9133 # Draw a 'switch active pane' icon as a toolbutton (optional)
9134 my $switchButton;
9135 if ($self->ivShow('initHash', 'switch_flag') && ! $axmud::BLIND_MODE_FLAG) {
9136  
9137 $switchButton = Gtk3::ToolButton->new(
9138 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constSwitchIconPath),
9139 'Switch active pane',
9140 );
9141 $packingBox->pack_start($switchButton, FALSE, FALSE, 0);
9142 $switchButton->set_tooltip_text('Switch active pane');
9143 $switchButton->set_sensitive(FALSE);
9144 }
9145  
9146 # Draw a 'scroll lock' icon as a toolbutton (optional)
9147 my $scrollButton;
9148 if ($self->ivShow('initHash', 'scroll_flag') && ! $axmud::BLIND_MODE_FLAG) {
9149  
9150 $scrollButton = Gtk3::ToolButton->new(
9151 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constLockIconPath),
9152 'Apply/release scroll lock',
9153 );
9154 $packingBox->pack_start($scrollButton, FALSE, FALSE, 0);
9155 $scrollButton->set_tooltip_text('Apply/release scroll lock');
9156 $scrollButton->set_sensitive(FALSE);
9157 }
9158  
9159 # Draw a 'split screen' icon as a toolbutton, and place it in the HBox (optional)
9160 my $splitButton;
9161 if ($self->ivShow('initHash', 'split_flag') && ! $axmud::BLIND_MODE_FLAG) {
9162  
9163 $splitButton = Gtk3::ToolButton->new(
9164 Gtk3::Image->new_from_file(
9165 $axmud::SHARE_DIR . $axmud::CLIENT->constRestoreIconPath,
9166 ),
9167 'Split/restore screen',
9168 );
9169 $packingBox->pack_start($splitButton, FALSE, FALSE, 0);
9170 $splitButton->set_tooltip_text('Split/restore screen');
9171 $splitButton->set_sensitive(FALSE);
9172 }
9173  
9174 # Update IVs
9175 $self->ivPoke('funcRef', $self->ivShow('initHash', 'func'));
9176 $self->ivPoke('funcID', $self->ivShow('initHash', 'id'));
9177 $self->ivPoke('packingBox', $packingBox);
9178 $self->ivPoke('entry', $entry);
9179 $self->ivPoke('preEntry', $preEntry);
9180 $self->ivPoke('postEntry', $postEntry);
9181 $self->ivPoke('wipeButton', $wipeButton);
9182 $self->ivPoke('addButton', $addButton);
9183 $self->ivPoke('consoleButton', $consoleButton);
9184 $self->ivPoke('inputButton', $inputButton);
9185 $self->ivPoke('searchButton', $searchButton);
9186 $self->ivPoke('cancelButton', $cancelButton);
9187 $self->ivPoke('switchButton', $switchButton);
9188 $self->ivPoke('scrollButton', $scrollButton);
9189 $self->ivPoke('splitButton', $splitButton);
9190  
9191 # Get a list of pane objects that already exist, and update our list of pane objects in
9192 # this window
9193 # (New panes are added to this list via a call to $self->notify_addTableObj, and old panes
9194 # are removed from it via a call to $self->notify_removeTableObj)
9195 if ($self->winObj->tableStripObj) {
9196  
9197 foreach my $tableObj (
9198 sort {$a->number <=> $b->number}
9199 ($self->winObj->tableStripObj->ivValues('tableObjHash'))
9200 ) {
9201 if ($tableObj->type eq 'pane') {
9202  
9203 $self->ivPush('paneObjList', $tableObj);
9204 }
9205 }
9206 }
9207  
9208 # Create ->signal_connects for each ($wipeButton manipulates $entry, and perhaps others will
9209 # in the future too, so we'll wait until now to do ->signal_connects)
9210 $self->setEntrySignals(); # 'activate'
9211 $self->setWipeSignals(); # 'clicked'
9212 $self->setAddSignals(); # 'clicked'
9213 $self->setConsoleSignals(); # 'clicked'
9214 $self->setInputSignals(); # 'clicked'
9215 $self->setSearchSignals(); # 'clicked'
9216 $self->setCancelSignals(); # 'clicked'
9217 $self->setSwitchSignals(); # 'clicked'
9218 $self->setScrollSignals(); # 'clicked'
9219 $self->setSplitSignals(); # 'clicked'
9220  
9221 return 1;
9222 }
9223  
9224 sub objDestroy {
9225  
9226 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
9227 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
9228 # to do any necessary tidying up
9229 #
9230 # Expected arguments
9231 # (none besides $self)
9232 #
9233 # Return values
9234 # 'undef' on improper arguments
9235 # 1 otherwise
9236  
9237 my ($self, $check) = @_;
9238  
9239 # Check for improper arguments
9240 if (defined $check) {
9241  
9242 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
9243 }
9244  
9245 # (No tidying up required for this type of strip object)
9246 # ...
9247  
9248 return 1;
9249 }
9250  
9251 sub setWidgetsIfSession {
9252  
9253 # Called by GA::Win::Internal->setWidgetsIfSession. (Also called by $self->setAddSignals)
9254 # Allows this strip object to sensitise or desensitise its widgets, depending on whether
9255 # the parent window has a ->visibleSession at the moment
9256 # (NB Only 'main' windows have a ->visibleSession; for other 'grid' windows, the flag
9257 # argument will be FALSE)
9258 #
9259 # Expected arguments
9260 # $flag - TRUE if the parent window has a visible session, FALSE if not
9261 #
9262 # Return values
9263 # 'undef' on improper arguments
9264 # 1 otherwise
9265  
9266 my ($self, $flag, $check) = @_;
9267  
9268 # Check for improper arguments
9269 if (! defined $flag || defined $check) {
9270  
9271 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
9272 }
9273  
9274 # Sensitise/desensitise entry box(es)
9275 if ($self->entry) {
9276  
9277 if ($flag) {
9278  
9279 if ($self->ivExists('captureHash', $self->winObj->visibleSession->number)) {
9280  
9281 $self->entry->set_sensitive(FALSE);
9282 if ($self->preEntry) {
9283  
9284 $self->preEntry->set_sensitive(FALSE);
9285 }
9286  
9287 if ($self->postEntry) {
9288  
9289 $self->postEntry->set_sensitive(FALSE);
9290 }
9291  
9292 } else {
9293  
9294 $self->entry->set_sensitive(TRUE);
9295 $self->entry->grab_focus();
9296  
9297 if ($self->preEntry) {
9298  
9299 $self->preEntry->set_sensitive(TRUE);
9300 }
9301  
9302 if ($self->postEntry) {
9303  
9304 $self->postEntry->set_sensitive(TRUE);
9305 }
9306 }
9307  
9308 } else {
9309  
9310 $self->entry->set_sensitive(FALSE);
9311 if ($self->preEntry) {
9312  
9313 $self->preEntry->set_sensitive(FALSE);
9314 }
9315  
9316 if ($self->postEntry) {
9317  
9318 $self->postEntry->set_sensitive(FALSE);
9319 }
9320 }
9321 }
9322  
9323 # Sensitise/desensitise buttons
9324 if ($self->wipeButton) {
9325  
9326 $self->wipeButton->set_sensitive($flag);
9327 }
9328  
9329 if ($self->inputButton) {
9330  
9331 $self->inputButton->set_sensitive($flag);
9332 }
9333  
9334 if ($self->searchButton) {
9335  
9336 $self->searchButton->set_sensitive($flag);
9337 }
9338  
9339 if ($self->consoleButton) {
9340  
9341 $self->consoleButton->set_sensitive($flag);
9342 }
9343  
9344 if ($self->cancelButton) {
9345  
9346 $self->cancelButton->set_sensitive($flag);
9347 }
9348  
9349 if ($self->switchButton) {
9350  
9351 $self->switchButton->set_sensitive($flag);
9352 }
9353  
9354 if ($self->scrollButton) {
9355  
9356 $self->scrollButton->set_sensitive($flag);
9357 # Restore default icon, too
9358 $self->scrollButton->set_icon_widget(
9359 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constLockIconPath),
9360 );
9361 }
9362  
9363 if ($self->splitButton) {
9364  
9365 $self->splitButton->set_sensitive($flag);
9366 # Restore default icon, too
9367 $self->splitButton->set_icon_widget(
9368 Gtk3::Image->new_from_file(
9369 $axmud::SHARE_DIR . $axmud::CLIENT->constRestoreIconPath,
9370 ),
9371 );
9372 }
9373  
9374 return 1;
9375 }
9376  
9377 sub setWidgetsChangeSession {
9378  
9379 # Called by GA::Win::Internal->setWidgetsChangeSession
9380 # Allows this strip object to update its widgets whenever the visible session in any 'main'
9381 # window changes
9382 #
9383 # Expected arguments
9384 # (none besides $self)
9385 #
9386 # Return values
9387 # 'undef' on improper arguments
9388 # 1 otherwise
9389  
9390 my ($self, $check) = @_;
9391  
9392 # Local variables
9393 my (
9394 $listRef, $specialEchoFlag, $specialPreserveFlag, $specialWorldCmd, $primaryIcon,
9395 $textViewObj, $iv,
9396 );
9397  
9398 # Check for improper arguments
9399 if (defined $check) {
9400  
9401 return $axmud::CLIENT->writeImproper(
9402 $self->_objClass . '->setWidgetsChangeSession',
9403 @_,
9404 );
9405 }
9406  
9407 # Update IVs that store settings for the previous visible session (if any)
9408 if (defined $self->prevVisibleSession) {
9409  
9410 $self->ivAdd(
9411 'sessionHash',
9412 $self->prevVisibleSession,
9413 [
9414 $self->specialEchoFlag,
9415 $self->specialPreserveFlag,
9416 $self->specialWorldCmd,
9417 $self->primaryIcon,
9418 ],
9419 );
9420  
9421 $self->ivUndef('prevVisibleSession');
9422 }
9423  
9424 # Update button icons to match the visible session
9425 if ($self->winObj->visibleSession) {
9426  
9427 # Retrieve settings used the last time this was the visible session
9428 $listRef = $self->ivShow('sessionHash', $self->winObj->visibleSession->number);
9429 if (! defined $listRef) {
9430  
9431 # Use default settings for the new visible session. ->primaryIcon has a default
9432 # value of 'undef' anyway
9433 $specialEchoFlag = FALSE;
9434 $specialPreserveFlag = FALSE;
9435 $specialWorldCmd = '';
9436  
9437 } else {
9438  
9439 # Use the previous settings
9440 ($specialEchoFlag, $specialPreserveFlag, $specialWorldCmd, $primaryIcon)
9441 = @$listRef;
9442 }
9443  
9444 $self->ivPoke('specialEchoFlag', $specialEchoFlag);
9445 $self->ivPoke('specialPreserveFlag', $specialPreserveFlag);
9446 $self->ivPoke('specialWorldCmd', $specialWorldCmd);
9447 $self->ivPoke('primaryIcon', $primaryIcon);
9448 $self->ivPoke('prevVisibleSession', $self->winObj->visibleSession->number);
9449  
9450 # (->defaultTabObj won't be set yet, if GA::Session->start is still executing)
9451 if ($self->winObj->visibleSession->defaultTabObj) {
9452  
9453 $textViewObj = $self->winObj->visibleSession->defaultTabObj->textViewObj;
9454 }
9455  
9456 if ($self->addButton) {
9457  
9458 $self->addButton->set_sensitive(! $self->specialEchoFlag);
9459 }
9460  
9461 if ($self->consoleButton) {
9462  
9463 # e.g. constEmptyIconPath
9464 $iv = 'const' . ucfirst($self->winObj->visibleSession->systemMsgMode) . 'IconPath';
9465  
9466 $self->consoleButton->set_icon_widget(
9467 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->$iv),
9468 );
9469  
9470 $self->ivPoke('consoleIconType', $self->winObj->visibleSession->systemMsgMode);
9471 $self->ivPoke('consoleIconFlashFlag', TRUE);
9472 }
9473  
9474 if ($self->scrollButton) {
9475  
9476 if (! $textViewObj || $textViewObj->scrollLockFlag) {
9477  
9478 $self->scrollButton->set_icon_widget(
9479 Gtk3::Image->new_from_file(
9480 $axmud::SHARE_DIR . $axmud::CLIENT->constLockIconPath
9481 ),
9482 );
9483  
9484 } else {
9485  
9486 $self->scrollButton->set_icon_widget(
9487 Gtk3::Image->new_from_file(
9488 $axmud::SHARE_DIR . $axmud::CLIENT->constScrollIconPath
9489 ),
9490 );
9491 }
9492 }
9493  
9494 if ($self->splitButton) {
9495  
9496 if (! $textViewObj || $textViewObj->splitScreenMode eq 'split') {
9497  
9498 $self->splitButton->set_icon_widget(
9499 Gtk3::Image->new_from_file(
9500 $axmud::SHARE_DIR . $axmud::CLIENT->constRestoreIconPath,
9501 ),
9502 );
9503  
9504 } else {
9505  
9506 $self->splitButton->set_icon_widget(
9507 Gtk3::Image->new_from_file(
9508 $axmud::SHARE_DIR . $axmud::CLIENT->constSplitIconPath,
9509 ),
9510 );
9511 }
9512 }
9513  
9514 if ($self->entry) {
9515  
9516 # If the current current session's server has suggested that the client stop
9517 # ECHOing, and the client has agreed, text in the entry box(es) must be obscured
9518 # If not, or if special echo mode is on, it must be un-obscured (in case it was
9519 # obscured by the previous session)
9520 # In either case, text in the entry box is removed when switching sessions
9521 if (
9522 $self->winObj->visibleSession->echoMode eq 'client_agree'
9523 && ! $self->specialEchoFlag
9524 ) {
9525 $self->obscureEntry(TRUE);
9526 } else {
9527 $self->obscureEntry(FALSE);
9528 }
9529  
9530 # Set (or reset) entry box icons. Those associated with recordings may have changed
9531 # since the last time the session was the visible session
9532 $self->entry->set_icon_from_stock('primary', $self->primaryIcon);
9533  
9534 if ($self->winObj->visibleSession->recordingPausedFlag) {
9535 $self->entry->set_icon_from_stock('secondary', 'gtk-media-pause');
9536 } elsif ($self->winObj->visibleSession->recordingFlag) {
9537 $self->entry->set_icon_from_stock('secondary', 'gtk-media-record');
9538 } else {
9539 $self->entry->set_icon_from_stock('secondary', undef);
9540 }
9541 }
9542  
9543 } else {
9544  
9545 # No visible session; use the default settings
9546 $self->ivPoke('specialEchoFlag', FALSE);
9547 $self->ivPoke('specialPreserveFlag', FALSE);
9548 $self->ivPoke('specialWorldCmd', '');
9549 $self->ivPoke('primaryIcon', undef);
9550 $self->ivPoke('prevVisibleSession', undef);
9551  
9552 if ($self->entry) {
9553  
9554 if (! $axmud::CLIENT->sessionHash) {
9555  
9556 # If there are no sessions at all, the main entry box must be empty, and the
9557 # minor entry boxes must be removed entirely
9558 $self->entry->set_text('');
9559 if ($self->preEntry) {
9560  
9561 $axmud::CLIENT->desktopObj->removeWidget(
9562 $self->packingBox,
9563 $self->preEntry,
9564 );
9565  
9566 $self->ivUndef('preEntry');
9567 }
9568  
9569 if ($self->postEntry) {
9570  
9571 $axmud::CLIENT->desktopObj->removeWidget(
9572 $self->packingBox,
9573 $self->postEntry,
9574 );
9575  
9576 $self->ivUndef('postEntry');
9577 }
9578 }
9579 }
9580 }
9581  
9582 return 1;
9583 }
9584  
9585 # ->signal_connects
9586  
9587 sub setEntrySignals {
9588  
9589 # Called by $self->objEnable
9590 # Set up a ->signal_connect to watch out for the user input in the entry box
9591 #
9592 # Expected arguments
9593 # (none besides $self)
9594 #
9595 # Return values
9596 # 'undef' on improper arguments
9597 # 1 otherwise
9598  
9599 my ($self, $check) = @_;
9600  
9601 # Local variables
9602 my %shortHash;
9603  
9604 # Check for improper arguments
9605 if (defined $check) {
9606  
9607 return $axmud::CLIENT->writeImproper($self->_objClass . '->setEntrySignals', @_);
9608 }
9609  
9610 # Deal with user pressing their ENTER key
9611 $self->entry->signal_connect('activate' => sub {
9612  
9613 my (
9614 $instruct, $thisFuncRef, $preText, $postText, $successFlag, $type,
9615 @instructList,
9616 );
9617  
9618 $instruct = $self->entry->get_text();
9619 $thisFuncRef = $self->funcRef;
9620  
9621 # The entry box's behaviour depends on whether the parent window is a 'main' window, or
9622 # not
9623 if ($self->winObj->winType eq 'main') {
9624  
9625 if (
9626 $self->specialEchoFlag
9627 && ! $self->specialPreserveFlag
9628 && $self->specialWorldCmd
9629 && $self->winObj->visibleSession
9630 ) {
9631 # Pass the stored world command to the visible session, calling ->dispatchCmd
9632 # directly, since it already checks for special echo mode
9633 $self->winObj->visibleSession->dispatchCmd($self->specialWorldCmd);
9634 # Also update the instruction buffer, since we bypassed GA::Session->doInstruct
9635 $self->winObj->visibleSession->updateInstructBuffer(
9636 $self->specialWorldCmd,
9637 'world',
9638 );
9639  
9640 } elsif ($self->winObj->visibleSession) {
9641  
9642 # Pass the typed instruction to the visible session, along with any pre- or
9643 # post-world command strings that exist
9644 if ($self->preEntry) {
9645  
9646 $preText = $self->preEntry->get_text();
9647 if ($preText eq '') {
9648  
9649 $preText = undef;
9650 }
9651 }
9652  
9653 if ($self->postEntry) {
9654  
9655 $postText = $self->postEntry->get_text();
9656 if ($postText eq '') {
9657  
9658 $postText = undef;
9659 }
9660 }
9661  
9662 # The user may have copied a set of instructions, separated by newline
9663 # characters (for example from a text editor). If so, split them up into
9664 # indiviual instructions
9665 # Because $instruct might well be an empty string (if the user just pressed
9666 # RETURN), then we cannot do a Perl split in all cases
9667 if ($instruct =~ m/\n/) {
9668 @instructList = split(/\n/, $instruct);
9669 } else {
9670 push (@instructList, $instruct);
9671 }
9672  
9673 foreach my $thisInstruct (@instructList) {
9674  
9675 ($successFlag, $type) = $self->winObj->visibleSession->doInstruct(
9676 $thisInstruct,
9677 undef,
9678 $preText,
9679 $postText,
9680 );
9681 }
9682  
9683 # Deal with the new contents of the entry box
9684 if (
9685 defined $type
9686 # (If $instruct was ';stopsession', there will be no visible session now)
9687 && $self->winObj->visibleSession
9688 && $self->winObj->visibleSession->echoMode ne 'client_agree'
9689 && (
9690 (
9691 $axmud::CLIENT->preserveWorldCmdFlag
9692 && (
9693 $type eq 'world' || $type eq 'multi' || $type eq 'speed'
9694 || $type eq 'bypass'
9695 )
9696 ) || (
9697 $axmud::CLIENT->preserveOtherCmdFlag
9698 && (
9699 $type ne 'world' && $type ne 'multi' && $type ne 'speed'
9700 && $type ne 'bypass'
9701 )
9702 )
9703 )
9704 ) {
9705 # Preserve the typed command and select all of the text
9706 $self->entry->grab_focus();
9707  
9708 } else {
9709  
9710 # Empty the entry box
9711 $self->entry->set_text('');
9712 }
9713  
9714 # Reset the text stored for the benefit of GA::Session->autoCompleteBuffer
9715 $self->ivUndef('originalEntryText');
9716  
9717 } else {
9718  
9719 $self->entry->set_text('');
9720  
9721 # Reset the text stored for the benefit of GA::Session->autoCompleteBuffer
9722 $self->ivUndef('originalEntryText');
9723 }
9724  
9725 # For other 'internal' windows, redirect the entry box's contents to the specified
9726 # function (if any)
9727 } elsif ($thisFuncRef) {
9728  
9729 &$thisFuncRef($self, $self->entry, $self->funcID, $instruct);
9730  
9731 $self->entry->set_text('');
9732 }
9733  
9734 # Update IVs
9735 $self->entry->set_icon_from_stock('primary', undef);
9736 $self->ivUndef('primaryIcon');
9737 $self->ivPoke('specialPreserveFlag', FALSE);
9738 $self->ivPoke('specialWorldCmd', '');
9739  
9740 return 1;
9741 });
9742  
9743 # Deal with user entering or removing any character(s) from the entry box, during special
9744 # echo mode
9745 # In special echo mode, world commands are sent to the world immediately, one character at a
9746 # time; but non-world commands (such as client commands) behave as normal. Forced client
9747 # commands also behave as normal
9748 # To implement this we need to work out when the user is typing an instruction that begins
9749 # with a recognised instruction sigil, and when they're not
9750  
9751 # Most instruction sigils are one character long, but GA::Client->constForcedSigil is two.
9752 # In any case, some user might edit GA::Client->new to alter the literal values
9753 # Save a bit of time by compiling a hash of strings that start a multi-character sigil
9754 # (for example, for the forced world command sigil ',,' add an entry for ',')
9755 # We assume that the user has followed the instructions in GA::Client->new, and has made
9756 # sure each sigil starts with a different character
9757 foreach my $type (qw(client forced echo perl script multi speed bypass)) {
9758  
9759 my $iv = 'const' . ucfirst($type) . 'Sigil'; # e.g. 'constClientSigil'
9760  
9761 if (length ($axmud::CLIENT->$iv) > 1) {
9762  
9763 for (my $num = 1; $num <= length($axmud::CLIENT->$iv); $num++) {
9764  
9765 $shortHash{substr($axmud::CLIENT->$iv, 0, $num)} = undef;
9766 }
9767 }
9768 }
9769  
9770 $self->entry->signal_connect('changed' => sub {
9771  
9772 my $instruct = $self->entry->get_text();
9773  
9774 if (! $self->specialEchoFlag || $instruct eq '') {
9775  
9776 # Special echo mode is off or the command entry box is empty, so do nothing with
9777 # ordinary keypresses
9778 return undef;
9779  
9780 } else {
9781  
9782 # Special echo mode is on. Trim initial whitespace, so we can work out whether
9783 # $instruct starts with an instruction sigil, or not; but if $instruct actually
9784 # contains just space character(s), don't trim it
9785 $instruct =~ s/^\s*(\S.*)/$1/;
9786  
9787 # Is the whole of instruct a partial multi-character sigil (for example, a single
9788 # comma from the forced world command sigil ',,') ?
9789 foreach my $short (keys %shortHash) {
9790  
9791 if ($instruct eq $short) {
9792  
9793 # Decide what to do once the the user has typed another character
9794 # Meanwhile, set the entry icon for non-world commands
9795 $self->entry->set_icon_from_stock('primary', 'gtk-disconnect');
9796 $self->ivPoke('primaryIcon', 'gtk-disconnect');
9797 # Don't let GA::Win::Internal->setKeyPressEvent intercept the escape, tab,
9798 # backspace and delete keys, which should instead apply to our entry box
9799 $self->ivPoke('specialPreserveFlag', TRUE);
9800 $self->ivPoke('specialWorldCmd', '');
9801  
9802 return undef;
9803 }
9804 }
9805  
9806 # Now check that $instruct begins with an instruction sigil that's currently
9807 # enabled
9808 foreach my $type (qw(client forced echo perl script multi speed bypass)) {
9809  
9810 my ($constIV, $flagIV);
9811  
9812 $constIV = 'const' . ucfirst($type) . 'Sigil'; # e.g. 'constClientSigil'
9813 $flagIV = $type . 'SigilFlag'; # e.g. 'echoSigilFlag'
9814  
9815 if (
9816 index($instruct, $axmud::CLIENT->$constIV) == 0
9817 && (
9818 # The IVs ->clientSigilFlag and ->forcedSigilFlag don't exist
9819 $type eq 'client'
9820 || $type eq 'forced'
9821 || $axmud::CLIENT->$flagIV
9822 )
9823 ) {
9824 # $instruct begins with an instruction sigil that's enabled. Set the entry
9825 # icon for non-world commands
9826 $self->entry->set_icon_from_stock('primary', 'gtk-disconnect');
9827 $self->ivPoke('primaryIcon', 'gtk-disconnect');
9828 # Don't let GA::Win::Internal->setKeyPressEvent intercept the escape, tab,
9829 # backspace and delete keys, which should instead apply to our entry box
9830 $self->ivPoke('specialPreserveFlag', TRUE);
9831 $self->ivPoke('specialWorldCmd', '');
9832  
9833 return undef;
9834 }
9835 }
9836  
9837 # $instruct is part of a world command, so send it to the world immediately (the
9838 # TRUE argument means to encode $instruct using the session's current character
9839 # set)
9840 $self->winObj->visibleSession->put($instruct, TRUE);
9841 # Reset the entry box, and set the icon for world commands
9842 $self->entry->set_text('');
9843 $self->entry->set_icon_from_stock('primary', 'gtk-connect');
9844 $self->ivPoke('primaryIcon', 'gtk-connect');
9845 # Update IVs
9846 $self->ivPoke('specialPreserveFlag', FALSE);
9847 $self->ivPoke('specialWorldCmd', $self->specialWorldCmd . $instruct);
9848  
9849 return undef;
9850 }
9851 });
9852  
9853 return 1;
9854 }
9855  
9856 sub setWipeSignals {
9857  
9858 # Called by $self->objEnable
9859 # Set up a ->signal_connect to watch out for the button being clicked
9860 #
9861 # Expected arguments
9862 # (none besides $self)
9863 #
9864 # Return values
9865 # 'undef' on improper arguments
9866 # 1 otherwise
9867  
9868 my ($self, $check) = @_;
9869  
9870 # Check for improper arguments
9871 if (defined $check) {
9872  
9873 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWipeSignals', @_);
9874 }
9875  
9876 if ($self->wipeButton) {
9877  
9878 $self->wipeButton->signal_connect('clicked' => sub {
9879  
9880 $self->entry->set_text('');
9881  
9882 # Update IVs. Clicking the button means that the user wants to start typing a new
9883 # world command, without having pressed their RETURN key (for example, if they've
9884 # just been navigating menus)
9885 $self->ivPoke('specialPreserveFlag', FALSE);
9886 $self->ivPoke('specialWorldCmd', '');
9887 # Remove the icon, too
9888 $self->entry->set_icon_from_stock('primary', undef);
9889 $self->ivUndef('primaryIcon');
9890 });
9891 }
9892  
9893 return 1;
9894 }
9895  
9896 sub setAddSignals {
9897  
9898 # Called by $self->objEnable
9899 # Set up a ->signal_connect to watch out for the button being clicked
9900 #
9901 # Expected arguments
9902 # (none besides $self)
9903 #
9904 # Return values
9905 # 'undef' on improper arguments
9906 # 1 otherwise
9907  
9908 my ($self, $check) = @_;
9909  
9910 # Check for improper arguments
9911 if (defined $check) {
9912  
9913 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAddSignals', @_);
9914 }
9915  
9916 if ($self->addButton) {
9917  
9918 $self->addButton->signal_connect('clicked' => sub {
9919  
9920 # Update IVs, cycling through various modes, in which one or more entry boxes are
9921 # drawn
9922 if ($self->entryBoxMode eq 'default') {
9923 $self->ivPoke('entryBoxMode', 'pre');
9924 } elsif ($self->entryBoxMode eq 'pre') {
9925 $self->ivPoke('entryBoxMode', 'both');
9926 } elsif ($self->entryBoxMode eq 'both') {
9927 $self->ivPoke('entryBoxMode', 'post');
9928 } elsif ($self->entryBoxMode eq 'post') {
9929 $self->ivPoke('entryBoxMode', 'default');
9930 }
9931  
9932 # Redraw the whole strip, which draws the right number of entries
9933 $self->objEnable($axmud::CLIENT->ivShow('winmapHash', $self->winObj->winmap));
9934 if ($self->winObj->winType ne 'main') {
9935 $self->setWidgetsIfSession(FALSE);
9936 } else {
9937 $self->setWidgetsIfSession(TRUE);
9938 }
9939  
9940 $self->winObj->replaceStripObj($self);
9941 $self->entry->grab_focus();
9942 });
9943 }
9944  
9945 return 1;
9946 }
9947  
9948 sub setConsoleSignals {
9949  
9950 # Called by $self->objEnable
9951 # Set up a ->signal_connect to watch out for the button being clicked
9952 #
9953 # Expected arguments
9954 # (none besides $self)
9955 #
9956 # Return values
9957 # 'undef' on improper arguments
9958 # 1 otherwise
9959  
9960 my ($self, $check) = @_;
9961  
9962 # Check for improper arguments
9963 if (defined $check) {
9964  
9965 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInputSignals', @_);
9966 }
9967  
9968 if ($self->consoleButton) {
9969  
9970 $self->consoleButton->signal_connect('clicked' => sub {
9971  
9972 if ($self->winObj->visibleSession) {
9973  
9974 if (! $self->winObj->visibleSession->consoleWin) {
9975  
9976 # Open an Session Console window
9977 $self->winObj->createFreeWin(
9978 'Games::Axmud::OtherWin::SessionConsole',
9979 $self->winObj,
9980 $self->winObj->visibleSession,
9981 undef, # Let the window set its own title
9982 );
9983  
9984 } else {
9985  
9986 # Close the existing window
9987 $self->winObj->visibleSession->consoleWin->winDestroy();
9988 }
9989 }
9990 });
9991 }
9992  
9993 return 1;
9994 }
9995  
9996 sub setInputSignals {
9997  
9998 # Called by $self->objEnable
9999 # Set up a ->signal_connect to watch out for the button being clicked
10000 #
10001 # Expected arguments
10002 # (none besides $self)
10003 #
10004 # Return values
10005 # 'undef' on improper arguments
10006 # 1 otherwise
10007  
10008 my ($self, $check) = @_;
10009  
10010 # Check for improper arguments
10011 if (defined $check) {
10012  
10013 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInputSignals', @_);
10014 }
10015  
10016 if ($self->inputButton) {
10017  
10018 $self->inputButton->signal_connect('clicked' => sub {
10019  
10020 if ($self->winObj->visibleSession) {
10021  
10022 $self->winObj->visibleSession->pseudoCmd('quickinput');
10023 }
10024 });
10025 }
10026  
10027 return 1;
10028 }
10029  
10030 sub setSearchSignals {
10031  
10032 # Called by $self->objEnable
10033 # Set up a ->signal_connect to watch out for the button being clicked
10034 #
10035 # Expected arguments
10036 # (none besides $self)
10037 #
10038 # Return values
10039 # 'undef' on improper arguments
10040 # 1 otherwise
10041  
10042 my ($self, $check) = @_;
10043  
10044 # Check for improper arguments
10045 if (defined $check) {
10046  
10047 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSearchSignals', @_);
10048 }
10049  
10050 if ($self->searchButton) {
10051  
10052 $self->searchButton->signal_connect('clicked' => sub {
10053  
10054 my $searchStripObj = $self->winObj->getStrip('search');
10055  
10056 if ($searchStripObj) {
10057  
10058 $searchStripObj->toggleBox();
10059 $searchStripObj->findEntry->grab_focus();
10060 }
10061 });
10062 }
10063  
10064 return 1;
10065 }
10066  
10067 sub setCancelSignals {
10068  
10069 # Called by $self->objEnable
10070 # Set up a ->signal_connect to watch out for the button being clicked
10071 #
10072 # Expected arguments
10073 # (none besides $self)
10074 #
10075 # Return values
10076 # 'undef' on improper arguments
10077 # 1 otherwise
10078  
10079 my ($self, $check) = @_;
10080  
10081 # Check for improper arguments
10082 if (defined $check) {
10083  
10084 return $axmud::CLIENT->writeImproper($self->_objClass . '->setCancelSignals', @_);
10085 }
10086  
10087 if ($self->cancelButton) {
10088  
10089 $self->cancelButton->signal_connect('clicked' => sub {
10090  
10091 if (
10092 $self->winObj->visibleSession
10093 && (
10094 $self->winObj->visibleSession->status eq 'connected'
10095 || $self->winObj->visibleSession->status eq 'offline'
10096 )
10097 ) {
10098 $self->winObj->visibleSession->pseudoCmd('stopcommand');
10099 }
10100 });
10101 }
10102  
10103 return 1;
10104 }
10105  
10106 sub setSwitchSignals {
10107  
10108 # Called by $self->objEnable
10109 # Set up a ->signal_connect to watch out for the button being clicked
10110 #
10111 # Expected arguments
10112 # (none besides $self)
10113 #
10114 # Return values
10115 # 'undef' on improper arguments
10116 # 1 otherwise
10117  
10118 my ($self, $check) = @_;
10119  
10120 # Check for improper arguments
10121 if (defined $check) {
10122  
10123 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSwitchSignals', @_);
10124 }
10125  
10126 if ($self->switchButton) {
10127  
10128 $self->switchButton->signal_connect('clicked' => sub {
10129  
10130 # The first pane object in $self->paneObjList is the new 'active' pane object, to
10131 # which the scroll and split buttons are applied
10132 if ($self->paneObjList) {
10133  
10134 my $paneObj = $self->ivShift('paneObjList');
10135 $self->ivPush('paneObjList', $paneObj);
10136  
10137 # Briefly increase the size of the 'active' pane object's border width, so the
10138 # user can see which one it is
10139 $axmud::CLIENT->paneModifyBorder($self->ivFirst('paneObjList'));
10140 }
10141 });
10142 }
10143  
10144 return 1;
10145 }
10146  
10147 sub setScrollSignals {
10148  
10149 # Called by $self->objEnable
10150 # Set up a ->signal_connect to watch out for the button being clicked
10151 #
10152 # Expected arguments
10153 # (none besides $self)
10154 #
10155 # Return values
10156 # 'undef' on improper arguments
10157 # 1 otherwise
10158  
10159 my ($self, $check) = @_;
10160  
10161 # Check for improper arguments
10162 if (defined $check) {
10163  
10164 return $axmud::CLIENT->writeImproper($self->_objClass . '->setScrollSignals', @_);
10165 }
10166  
10167 if ($self->scrollButton) {
10168  
10169 $self->scrollButton->signal_connect('clicked' => sub {
10170  
10171 my $paneObj;
10172  
10173 # Get the active pane object and toggle the scroll lock for the visible tab
10174 if ($self->paneObjList) {
10175  
10176 $paneObj = $self->ivFirst('paneObjList');
10177 $paneObj->toggleScrollLock();
10178 }
10179 });
10180 }
10181  
10182 return 1;
10183 }
10184  
10185 sub setSplitSignals {
10186  
10187 # Called by $self->objEnable
10188 # Set up a ->signal_connect to watch out for the button being clicked
10189 #
10190 # Expected arguments
10191 # (none besides $self)
10192 #
10193 # Return values
10194 # 'undef' on improper arguments
10195 # 1 otherwise
10196  
10197 my ($self, $check) = @_;
10198  
10199 # Check for improper arguments
10200 if (defined $check) {
10201  
10202 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSplitSignals', @_);
10203 }
10204  
10205 if ($self->splitButton) {
10206  
10207 $self->splitButton->signal_connect('clicked' => sub {
10208  
10209 my $paneObj;
10210  
10211 # Get the active pane object and toggle the split screen for the visible tab
10212 if ($self->paneObjList) {
10213  
10214 $paneObj = $self->ivFirst('paneObjList');
10215 $paneObj->toggleSplitScreen();
10216 }
10217 });
10218 }
10219  
10220 return 1;
10221 }
10222  
10223 # Other functions
10224  
10225 sub captureEntry {
10226  
10227 # Can be called by any code which wants to make temporarily set the Gtk3::Entry as
10228 # insensitive, and called again to restore its previous state (which might be
10229 # sensitive, or not)
10230 #
10231 # Expected arguments
10232 # $session - The calling GA::Session
10233 # $flag - Set to TRUE to desensitise the entry, FALSE to restore it to its previous
10234 # state (which might be insensitive) by calling $self->setWidgetsIfSession
10235 #
10236 # Return values
10237 # 'undef' on improper arguments or if the entry is already captured (or not captured) by
10238 # the calling session
10239 # 1 otherwise
10240  
10241 my ($self, $session, $flag, $check) = @_;
10242  
10243 # Check for improper arguments
10244 if (! defined $session || ! defined $flag || defined $check) {
10245  
10246 return $axmud::CLIENT->writeImproper($self->_objClass . '->captureEntry', @_);
10247 }
10248  
10249 if (
10250 $flag eq TRUE && $self->ivExists('captureHash', $session->number)
10251 || $flag eq FALSE && ! $self->ivExists('captureHash', $session->number)
10252 ) {
10253 # No changes to make
10254 return undef;
10255 }
10256  
10257 if ($flag) {
10258 $self->ivAdd('captureHash', $session->number, undef);
10259 } else {
10260 $self->ivDelete('captureHash', $session->number);
10261 }
10262  
10263 $self->seWidgetsIfSession();
10264  
10265 return 1;
10266 }
10267  
10268 sub obscureEntry {
10269  
10270 # Called by GA::Session->updateEcho and ->setWidgetsChangeSession
10271 # Empties the entry box, and modifies the box so that any text typed into it is either
10272 # obscured, or not (as required)
10273 #
10274 # Expected arguments
10275 # (none besides $self)
10276 #
10277 # Optional arguments
10278 # $flag - Flag set to TRUE if the entry box should be obscured, FALSE (or 'undef') if it
10279 # should be shown
10280 #
10281 # Return values
10282 # 'undef' on improper arguments
10283 # 1 otherwise
10284  
10285 my ($self, $flag, $check) = @_;
10286  
10287 # Check for improper arguments
10288 if (defined $check) {
10289  
10290 return $axmud::CLIENT->writeImproper($self->_objClass . '->obscureEntry', @_);
10291 }
10292  
10293 if ($self->entry) {
10294  
10295 $self->entry->set_text('');
10296 if ($flag) {
10297 $self->entry->set_visibility(FALSE);
10298 } else {
10299 $self->entry->set_visibility(TRUE);
10300 }
10301 }
10302  
10303 if ($self->preEntry) {
10304  
10305 $self->preEntry->set_text('');
10306 if ($flag) {
10307 $self->preEntry->set_visibility(FALSE);
10308 } else {
10309 $self->preEntry->set_visibility(TRUE);
10310 }
10311 }
10312  
10313 if ($self->postEntry) {
10314  
10315 $self->postEntry->set_text('');
10316 if ($flag) {
10317 $self->postEntry->set_visibility(FALSE);
10318 } else {
10319 $self->postEntry->set_visibility(TRUE);
10320 }
10321 }
10322  
10323 # (If $self->entry doesn't exist, the other two entry boxes don't exist either)
10324 if ($self->entry) {
10325  
10326 $self->winObj->winShowAll($self->_objClass . '->obscureEntry');
10327 }
10328  
10329 return 1;
10330 }
10331  
10332 sub commandeerEntry {
10333  
10334 # Called by GA::Obj::TextView->setButtonPressEvent and ->createPopupMenu
10335 # When an MXP <SEND>..</SEND> construction (or any other code) wants to insert a command
10336 # into the client's command line (instead of sending it to the world directly), this
10337 # function is called
10338 # The command is copied into the entry box (but only if the calling session is this window's
10339 # visible session, which it almost certainly is)
10340 #
10341 # Expected arguments
10342 # $session - The calling GA::Session
10343 # $cmd - The command to display in the entry box
10344 #
10345 # Return values
10346 # 'undef' on improper arguments, if $session is not this window's visible session or if
10347 # the $cmd is not displayed
10348 # 1 if the $cmd is displayed
10349  
10350 my ($self, $session, $cmd, $check) = @_;
10351  
10352 # Check for improper arguments
10353 if (! defined $session || ! defined $cmd || defined $check) {
10354  
10355 return $axmud::CLIENT->writeImproper($self->_objClass . '->commandeerEntry', @_);
10356 }
10357  
10358 if (! $self->winObj->visibleSession || $self->winObj->visibleSession ne $session) {
10359  
10360 # Do nothing
10361 return undef;
10362  
10363 } else {
10364  
10365 $self->entry->set_text($cmd);
10366 $self->entry->set_visibility(TRUE);
10367 $self->entry->grab_focus();
10368  
10369 $self->winObj->winShowAll($self->_objClass . '->commandeerEntry');
10370  
10371 return 1;
10372 }
10373 }
10374  
10375 sub applyBackspace {
10376  
10377 # Called by GA::Win::Internal->setKeyPressEvent when the user presses the backspace key in
10378 # special echo mode
10379 # $self->specialWorldCmd stores a copy of the world command that's being sent to the world,
10380 # one character at a time; amend the copy by removing its final character
10381 # (This doesn't guarantee that the world command stored in ->specialWorldCmd is exactly the
10382 # same as the command the world thinks it's receiving, but it should be close enough)
10383 #
10384 # Expected arguments
10385 # (none besides $self)
10386 #
10387 # Return values
10388 # 'undef' on improper arguments
10389 # 1 otherwise
10390  
10391 my ($self, $check) = @_;
10392  
10393 # Check for improper arguments
10394 if (defined $check) {
10395  
10396 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyBackspace', @_);
10397 }
10398  
10399 # The calling function has done most of the checking, so just update ->specialWorldCmd
10400 if ($self->specialWorldCmd ne '') {
10401  
10402 $self->ivPoke(
10403 'specialWorldCmd',
10404 substr($self->specialWorldCmd, 0, ((length ($self->specialWorldCmd)) - 1)),
10405 );
10406 }
10407  
10408 return 1;
10409 }
10410  
10411 sub updateScrollButton {
10412  
10413 # Called by GA::Table::Pane->toggleScrollLock and ->toggleSplitScreen, and by
10414 # $self->setScrollSignals
10415 # Updates the icon shown on the 'scroll lock' button, which indicates whether the scroll
10416 # lock is applied to the active textview, or not
10417 #
10418 # Expected arguments
10419 # (none besides $self)
10420 #
10421 # Optional arguments
10422 # $flag - TRUE if the scroll lock is applied on the active textview, FALSE if it is not.
10423 # Set to 'undef' if the calling function doesn't know whether the scroll lock
10424 # is applied in the active textview, or not
10425 #
10426 # Return values
10427 # 'undef' on improper arguments
10428 # 1 otherwise
10429  
10430 my ($self, $flag, $check) = @_;
10431  
10432 # Local variables
10433 my ($paneObj, $tabNum, $tabObj);
10434  
10435 # Check for improper arguments
10436 if (defined $check) {
10437  
10438 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateScrollButton', @_);
10439 }
10440  
10441 if (! defined $flag) {
10442  
10443 # Is there an active textview, and is its scroll lock applied?
10444 if ($self->paneObjList) {
10445  
10446 $paneObj = $self->ivFirst('paneObjList');
10447 if ($paneObj) {
10448  
10449 if (! $paneObj->notebook) {
10450 $tabNum = 0;
10451 } else {
10452 $tabNum = $paneObj->notebook->get_current_page();
10453 }
10454  
10455 if (defined $tabNum) {
10456  
10457 $tabObj = $paneObj->ivShow('tabObjHash', $tabNum);
10458 $flag = $tabObj->textViewObj->scrollLockFlag;
10459 }
10460 }
10461 }
10462 }
10463  
10464 # Do nothing if the button isn't visible...
10465 if ($self->scrollButton) {
10466  
10467 if (! $flag) {
10468  
10469 $self->scrollButton->set_icon_widget(
10470 Gtk3::Image->new_from_file(
10471 $axmud::SHARE_DIR . $axmud::CLIENT->constScrollIconPath
10472 ),
10473 );
10474  
10475 } else {
10476  
10477 # (Default)
10478 $self->scrollButton->set_icon_widget(
10479 Gtk3::Image->new_from_file(
10480 $axmud::SHARE_DIR . $axmud::CLIENT->constLockIconPath
10481 ),
10482 );
10483 }
10484  
10485 $self->winObj->winShowAll($self->_objClass . '->updateScrollButton');
10486 }
10487  
10488 return 1;
10489 }
10490  
10491 sub updateSplitButton {
10492  
10493 # Called by GA::Table::Pane->toggleSplitScreen
10494 # Updates the icon shown on the 'split screen' button, which indicates whether the split
10495 # screen is applied to the active textview, or not
10496 #
10497 # Expected arguments
10498 # (none besides $self)
10499 #
10500 # Optional arguments
10501 # $flag - TRUE if the split screen is applied on the active textview, FALSE if it is
10502 # not. Set to 'undef' if the calling function doesn't know whether the split
10503 # screen lock is applied in the active textview, or not
10504 #
10505 # Return values
10506 # 'undef' on improper arguments
10507 # 1 otherwise
10508  
10509 my ($self, $flag, $check) = @_;
10510  
10511 # Local variables
10512 my ($paneObj, $tabNum, $tabObj);
10513  
10514 # Check for improper arguments
10515 if (defined $check) {
10516  
10517 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateSplitButton', @_);
10518 }
10519  
10520 if (! defined $flag) {
10521  
10522 # Is there an active textview, and is its split screen applied?
10523 if ($self->paneObjList) {
10524  
10525 $paneObj = $self->ivFirst('paneObjList');
10526 if ($paneObj) {
10527  
10528 if (! $paneObj->notebook) {
10529 $tabNum = 0;
10530 } else {
10531 $tabNum = $paneObj->notebook->get_current_page();
10532 }
10533  
10534 if (defined $tabNum) {
10535  
10536 $tabObj = $paneObj->ivShow('tabObjHash', $tabNum);
10537 if ($tabObj->textViewObj->splitScreenMode eq 'split') {
10538 $flag = TRUE;
10539 } else {
10540 $flag = FALSE;
10541 }
10542 }
10543 }
10544 }
10545 }
10546  
10547 # Do nothing if the button isn't visible...
10548 if ($self->splitButton) {
10549  
10550 if (! $flag) {
10551  
10552 $self->splitButton->set_icon_widget(
10553 Gtk3::Image->new_from_file(
10554 $axmud::SHARE_DIR . $axmud::CLIENT->constRestoreIconPath
10555 ),
10556 );
10557  
10558 } else {
10559  
10560 # (Default)
10561 $self->splitButton->set_icon_widget(
10562 Gtk3::Image->new_from_file(
10563 $axmud::SHARE_DIR . $axmud::CLIENT->constSplitIconPath
10564 ),
10565 );
10566 }
10567  
10568 $self->winObj->winShowAll($self->_objClass . '->updateSplitButton');
10569 }
10570  
10571 return 1;
10572 }
10573  
10574 sub updateConsoleButton {
10575  
10576 # Called by GA::Session->add_systemMsg and ->reset_systemMsg
10577 # The argument corresponds to the icon to draw on the console button
10578 #
10579 # Expected arguments
10580 # $type - One of the strings 'empty', 'system', 'debug' or 'error', corresponding to
10581 # one of the icons in ../share/icons/button that's used to draw the
10582 # button when it's not flashing
10583 #
10584 # Optional arguments
10585 # $tempType - One of the strings 'system', 'debug' or 'error', corresponding to the icon
10586 # that's used to draw the button when it's flashing ('undef' when $type is
10587 # 'empty')
10588 #
10589 # Return values
10590 # 'undef' on improper arguments
10591 # 1 otherwise
10592  
10593 my ($self, $type, $tempType, $check) = @_;
10594  
10595 # Local variables
10596 my $iv;
10597  
10598 # Check for improper arguments
10599 if (
10600 ! defined $type
10601 || ($type ne 'empty' && $type ne 'system' && $type ne 'debug' && $type ne 'error')
10602 || (
10603 defined $tempType && $tempType ne 'system' && $tempType ne 'debug'
10604 && $tempType ne 'error'
10605 )
10606 || defined $check
10607 ) {
10608 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateConsoleButton', @_);
10609 }
10610  
10611 if ($self->consoleButton) {
10612  
10613 if (! $self->consoleIconFlashFlag) {
10614 $iv = 'constEmptyIconPath';
10615 } elsif ($tempType) {
10616 $iv = 'const' . ucfirst($tempType) . 'IconPath';
10617 } else {
10618 $iv = 'const' . ucfirst($type) . 'IconPath';
10619 }
10620  
10621 $self->consoleButton->set_icon_widget(
10622 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->$iv),
10623 );
10624  
10625 $self->ivPoke('consoleIconType', $type);
10626 $self->ivPoke('consoleIconTempType', $tempType);
10627 $self->ivPoke('consoleIconFlashFlag', TRUE);
10628  
10629 $self->winObj->winShowAll($self->_objClass . '->updateConsoleButton');
10630 }
10631  
10632 return 1;
10633 }
10634  
10635 ##################
10636 # Accessors - set
10637  
10638 sub notify_addTableObj {
10639  
10640 # Called by GA::Strip::Table->addTableObj whenever a table object is added to the window's
10641 # Gtk3::Grid
10642  
10643 my ($self, $tableObj, $check) = @_;
10644  
10645 # Check for improper arguments
10646 if (! defined $tableObj || defined $check) {
10647  
10648 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addTableObj', @_);
10649 }
10650  
10651 if ($tableObj->type eq 'pane') {
10652  
10653 # Add the pane object to the list of pane objects which can be made active with the
10654 # switch button
10655 $self->ivPush('paneObjList', $tableObj);
10656 }
10657  
10658 return 1;
10659 }
10660  
10661 sub set_consoleIconFlash {
10662  
10663 # Called by GA::Client->spinClientLoop to flash the console button
10664  
10665 my ($self, $check) = @_;
10666  
10667 # Local variables
10668 my $iv;
10669  
10670 # Check for improper arguments
10671 if (defined $check) {
10672  
10673 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_consoleIconFlash', @_);
10674 }
10675  
10676 # (The calling function has already compared IVs against this window's visible session)
10677  
10678 if ($self->consoleButton && $self->consoleIconType) {
10679  
10680 if ($self->consoleIconFlashFlag) {
10681  
10682 $self->consoleButton->set_icon_widget(
10683 Gtk3::Image->new_from_file(
10684 $axmud::SHARE_DIR . $axmud::CLIENT->constEmptyIconPath,
10685 ),
10686 );
10687  
10688 $self->ivPoke('consoleIconFlashFlag', FALSE);
10689  
10690 } else {
10691  
10692 $iv = 'const' . ucfirst($self->consoleIconTempType) . 'IconPath';
10693  
10694 $self->consoleButton->set_icon_widget(
10695 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->$iv),
10696 );
10697  
10698 $self->ivPoke('consoleIconFlashFlag', TRUE);
10699 }
10700  
10701 $self->consoleButton->show_all();
10702 }
10703  
10704 return 1;
10705 }
10706  
10707 sub reset_consoleIconFlash {
10708  
10709 # Called by GA::Session->spinMaintainLoop to stop the console button's flashing
10710  
10711 my ($self, $check) = @_;
10712  
10713 # Local variables
10714 my $iv;
10715  
10716 # Check for improper arguments
10717 if (defined $check) {
10718  
10719 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_consoleIconFlash', @_);
10720 }
10721  
10722 if ($self->consoleButton && $self->consoleIconType) {
10723  
10724 $iv = 'const' . ucfirst($self->consoleIconType) . 'IconPath';
10725  
10726 $self->consoleButton->set_icon_widget(
10727 Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->$iv),
10728 );
10729  
10730 $self->consoleButton->show_all();
10731  
10732 $self->ivPoke('consoleIconTempType', 'empty');
10733 $self->ivPoke('consoleIconFlashFlag', TRUE);
10734 }
10735  
10736 return 1;
10737 }
10738  
10739 sub set_originalEntryText {
10740  
10741 # Called by GA::Win::Internal->setKeyPressEvent
10742  
10743 my ($self, $text, $check) = @_;
10744  
10745 # Check for improper arguments
10746 if (defined $check) {
10747  
10748 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_originalEntryText', @_);
10749 }
10750  
10751 $self->ivPoke('originalEntryText', $text);
10752  
10753 return 1;
10754 }
10755  
10756 sub set_recordIcon {
10757  
10758 # Called by Games::Axmud::Cmd::Record->do, etc
10759 # Updates the entry icon showing the session's recording status (but only if it's the
10760 # visible session)
10761  
10762 my ($self, $session, $check) = @_;
10763  
10764 # Check for improper arguments
10765 if (! defined $session || defined $check) {
10766  
10767 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_recordIcon', @_);
10768 }
10769  
10770 if (
10771 $self->entry
10772 && $self->winObj->visibleSession
10773 && $self->winObj->visibleSession eq $session
10774 ) {
10775 if ($session->recordingPausedFlag) {
10776 $self->entry->set_icon_from_stock('secondary', 'gtk-media-pause');
10777 } elsif ($session->recordingFlag) {
10778 $self->entry->set_icon_from_stock('secondary', 'gtk-media-record');
10779 } else {
10780 $self->entry->set_icon_from_stock('secondary', undef);
10781 }
10782 }
10783  
10784 # (No IVs to update)
10785  
10786 return 1;
10787 }
10788  
10789 sub notify_removeTableObj {
10790  
10791 # Called by GA::Strip::Table->removeTableObj whenever a table object is removed from the
10792 # window's Gtk3::Grid
10793  
10794 my ($self, $tableObj, $check) = @_;
10795  
10796 # Local variables
10797 my @list;
10798  
10799 # Check for improper arguments
10800 if (! defined $tableObj || defined $check) {
10801  
10802 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeTableObj', @_);
10803 }
10804  
10805 # Remove the pane object from the list of pane objects which can be made active with the
10806 # switch button
10807 foreach my $paneObj ($self->paneObjList) {
10808  
10809 if ($paneObj ne $tableObj) {
10810  
10811 push (@list, $paneObj);
10812 }
10813 }
10814  
10815 $self->ivPoke('paneObjList', @list);
10816  
10817 return 1;
10818 }
10819  
10820 sub set_specialEchoFlag {
10821  
10822 # Called by GA::Session->updateSpecialEcho
10823  
10824 my ($self, $flag, $check) = @_;
10825  
10826 # Check for improper arguments
10827 if (! defined $flag || defined $check) {
10828  
10829 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_specialEchoFlag', @_);
10830 }
10831  
10832 if (! $flag) {
10833  
10834 $self->ivPoke('specialEchoFlag', FALSE);
10835 $self->ivPoke('specialPreserveFlag', FALSE);
10836 $self->ivPoke('specialWorldCmd', '');
10837  
10838 } else {
10839  
10840 $self->ivPoke('specialEchoFlag', TRUE);
10841 }
10842  
10843 if ($self->addButton) {
10844  
10845 $self->addButton->set_sensitive(! $self->specialEchoFlag);
10846 }
10847  
10848 if ($self->entry) {
10849  
10850 $self->entry->set_text('');
10851 $self->entry->set_icon_from_stock('primary', undef);
10852 $self->ivUndef('primaryIcon');
10853 }
10854  
10855 return 1;
10856 }
10857  
10858 ##################
10859 # Accessors - get
10860  
10861 sub entry
10862 { $_[0]->{entry} }
10863 sub preEntry
10864 { $_[0]->{preEntry} }
10865 sub postEntry
10866 { $_[0]->{postEntry} }
10867 sub wipeButton
10868 { $_[0]->{wipeButton} }
10869 sub addButton
10870 { $_[0]->{addButton} }
10871 sub consoleButton
10872 { $_[0]->{consoleButton} }
10873 sub inputButton
10874 { $_[0]->{inputButton} }
10875 sub searchButton
10876 { $_[0]->{searchButton} }
10877 sub cancelButton
10878 { $_[0]->{cancelButton} }
10879 sub switchButton
10880 { $_[0]->{switchButton} }
10881 sub scrollButton
10882 { $_[0]->{scrollButton} }
10883 sub splitButton
10884 { $_[0]->{splitButton} }
10885  
10886 sub paneObjList
10887 { my $self = shift; return @{$self->{paneObjList}}; }
10888  
10889 sub entryBoxMode
10890 { $_[0]->{entryBoxMode} }
10891 sub originalEntryText
10892 { $_[0]->{originalEntryText} }
10893 sub captureHash
10894 { my $self = shift; return %{$self->{captureHash}}; }
10895 sub consoleIconType
10896 { $_[0]->{consoleIconType} }
10897 sub consoleIconTempType
10898 { $_[0]->{consoleIconTempType} }
10899 sub consoleIconFlashFlag
10900 { $_[0]->{consoleIconFlashFlag} }
10901  
10902 sub specialEchoFlag
10903 { $_[0]->{specialEchoFlag} }
10904 sub specialPreserveFlag
10905 { $_[0]->{specialPreserveFlag} }
10906 sub specialWorldCmd
10907 { $_[0]->{specialWorldCmd} }
10908  
10909 sub primaryIcon
10910 { $_[0]->{primaryIcon} }
10911  
10912 sub sessionHash
10913 { my $self = shift; return %{$self->{sessionHash}}; }
10914 sub prevVisibleSession
10915 { $_[0]->{prevVisibleSession} }
10916 }
10917  
10918 { package Games::Axmud::Strip::ConnectInfo;
10919  
10920 use strict;
10921 use warnings;
10922 # use diagnostics;
10923  
10924 use Glib qw(TRUE FALSE);
10925  
10926 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
10927  
10928 ##################
10929 # Constructors
10930  
10931 sub new {
10932  
10933 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
10934 # Creates the GA::Strip::ConnectInfo - a non-compulsory strip object containing
10935 # Gtk3::Labels and blinkers
10936 #
10937 # Expected arguments
10938 # $number - The strip object's number within the parent window (matches
10939 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
10940 # created to access its default IVs)
10941 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
10942 # objects
10943 #
10944 # Optional arguments
10945 # %initHash - A hash containing arbitrary data to use as the strip object's
10946 # initialisation settings. The strip object should use default
10947 # initialisation settings unless it can succesfully interpret one or more
10948 # of the key-value pairs in the hash, if there are any
10949 # - (This type of strip object requires no initialisation settings)
10950 #
10951 # Return values
10952 # 'undef' on improper arguments
10953 # Blessed reference to the newly-created object on success
10954  
10955 my ($class, $number, $winObj, %initHash) = @_;
10956  
10957 # Local variables
10958 my %modHash;
10959  
10960 # Check for improper arguments
10961 if (! defined $class || ! defined $number || ! defined $winObj) {
10962  
10963 return $axmud::CLIENT->writeImproper($class . '->new', @_);
10964 }
10965  
10966 # Setup
10967 my $self = {
10968 _objName => 'strip_' . $number,
10969 _objClass => $class,
10970 _parentFile => undef, # No parent file object
10971 _parentWorld => undef, # No parent file object
10972 _privFlag => TRUE, # All IVs are private
10973  
10974 # Standard strip object IVs
10975 # -------------------------
10976  
10977 # The strip object's number within the parent window (matches
10978 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
10979 # its default IVs)
10980 number => $number,
10981 # The type of strip object (custom strip objects should use a ->type starting with
10982 # 'custom_' to avoid clashing with future built-in strip objects)
10983 type => 'connect_info',
10984 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
10985 winObj => $winObj,
10986  
10987 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
10988 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
10989 # still exists in GA::Win::Internal->stripHash, etc)
10990 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which might
10991 # have gauges to draw, or not, depending on current conditions. (Most strip objects
10992 # have this flag set to TRUE all the time)
10993 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
10994 # called by this object's functions
10995 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
10996 # the flag's value shouldn't be modified by anything other than
10997 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
10998 # $self->set_visibleFlag)
10999 visibleFlag => TRUE,
11000 # Flag set to TRUE is the strip object should be given its share of any extra space
11001 # within the packing box (the extra space is divided equally between all children of
11002 # the box whose ->expandFlag is TRUE)
11003 expandFlag => FALSE,
11004 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
11005 # actually allocated within the strip object, FALSE if it is used as padding outside
11006 # it (on both sides)
11007 fillFlag => FALSE,
11008 # Flag set to TRUE if the strip object should be packed into its window with a small
11009 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
11010 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
11011 # for example in the toolbar strip object)
11012 spacingFlag => TRUE,
11013 # Flag set to TRUE if only one instance of this strip object should be added to the
11014 # parent window, set to FALSE if any number of instances can be added
11015 jealousyFlag => TRUE,
11016 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
11017 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
11018 # users)
11019 blindFlag => FALSE,
11020 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
11021 # allowed to accept the focus, FALSE if not. The restriction is applied during the
11022 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
11023 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
11024 # GA::Strip::MenuBar)
11025 allowFocusFlag => FALSE,
11026  
11027 # Initialisation settings stored as a hash (see the comments above)
11028 initHash => \%modHash,
11029 # Reference to a function to call when some widget is used. This IV is set only when
11030 # required by this type of strip object. It can be set by a call to
11031 # $self->set_func() or by some setting in $self->initHash, which is applied in the
11032 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
11033 # generic object function Games::Axmud->getMethodRef()
11034 funcRef => undef,
11035 # A value passed to ->funcRef when it is called which identifies this strip object and
11036 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
11037 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
11038 # to $self->objEnable()
11039 funcID => undef,
11040  
11041 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
11042 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
11043 packingBox => undef, # Gtk3::HBox or Gtk3::VBox
11044  
11045 # Other IVs
11046 # ---------
11047  
11048 # Widgets
11049 hostLabel => undef, # Gtk3::Label
11050 frame => undef, # Gtk3::Frame
11051 canvas => undef, # GooCanvas2::Canvas
11052 timeLabel => undef, # Gtk3::Label
11053  
11054 # The GooCanvas2::CanvasRect objects that are drawn as blinkers - little blobs of colour
11055 # which are lit up (briefly) when data is sent to and forth from the world
11056 # This version of Axmud implements the following blinker numbers:
11057 # 0 - blinker turned on when data is received from the world
11058 # 1 - blinker turned on when telnet option/protocol data (invisible to users) is
11059 # received from the world
11060 # 2 - blinker turned on when a world command is sent
11061 # In each window, only the window object's ->visibleSession can light up blinkers; when
11062 # the visible session changes, all blinkers are reset
11063 #
11064 # Hash of blinker objects (GA::Obj::Blinker), one for each blinker, in the form
11065 # $blinkerHash{number} = blessed_reference_to_blinker_object
11066 blinkerHash => {},
11067 # Number of blinker objects created
11068 blinkerCount => 3,
11069 # The portion of the GooCanvas2::Canvas required for each blinker, in pixels
11070 blinkerWidth => 20,
11071 blinkerHeight => 15,
11072 };
11073  
11074 # Bless the object into existence
11075 bless $self, $class;
11076  
11077 return $self;
11078 }
11079  
11080 ##################
11081 # Methods
11082  
11083 # Standard strip object functions
11084  
11085 sub objEnable {
11086  
11087 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
11088 # Sets up the strip object's widgets
11089 #
11090 # Expected arguments
11091 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
11092 # parent window
11093 #
11094 # Return values
11095 # 'undef' on improper arguments
11096 # 1 on success
11097  
11098 my ($self, $winmapObj, $check) = @_;
11099  
11100 # Check for improper arguments
11101 if (! defined $winmapObj || defined $check) {
11102  
11103 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
11104 }
11105  
11106 # Create a packing box
11107 my $hBox = Gtk3::HBox->new(FALSE, 0);
11108 $hBox->set_border_width(0);
11109  
11110 # Add two labels and a Gtk3::Canvas for drawing blinkers
11111 my $hostLabel = Gtk3::Label->new();
11112 $hBox->pack_start($hostLabel, FALSE, FALSE, 0);
11113 $hostLabel->set_markup($self->winObj->hostLabelText);
11114  
11115 my $frame = Gtk3::Frame->new(undef);
11116 $hBox->pack_end($frame, FALSE, FALSE, 0);
11117 $frame->set_border_width(0);
11118 $frame->set_tooltip_text("Command sent | Out-of-bounds data | Text received");
11119  
11120 my $canvas = GooCanvas2::Canvas->new();
11121 $frame->add($canvas);
11122 $canvas->set_size_request(
11123 ($self->blinkerCount * $self->blinkerWidth),
11124 $self->blinkerHeight,
11125 );
11126 $canvas->set_bounds(
11127 0,
11128 0,
11129 ($self->blinkerCount * $self->blinkerWidth),
11130 $self->blinkerHeight,
11131 );
11132  
11133 my $timeLabel = Gtk3::Label->new();
11134 $hBox->pack_end($timeLabel, FALSE, FALSE, 0);
11135 $timeLabel->set_markup($self->winObj->timeLabelText);
11136 $timeLabel->set_tooltip_text("Connected | delayed Quit\nWorld idle | User idle");
11137  
11138 # Update IVs
11139 $self->ivPoke('packingBox', $hBox);
11140 $self->ivPoke('hostLabel', $hostLabel);
11141 $self->ivPoke('frame', $frame);
11142 $self->ivPoke('canvas', $canvas);
11143 $self->ivPoke('timeLabel', $timeLabel);
11144  
11145 # Create blinker objects (GA::Obj::Blinker)
11146 $self->createStandardBlinkers();
11147  
11148 # Draw the blinkers for the first time to set their 'off' colours
11149 $self->drawBlinker(
11150 -1, # Draw all three blinkers
11151 FALSE, # ...using their 'off' colour
11152 );
11153  
11154 return 1;
11155 }
11156  
11157 sub objDestroy {
11158  
11159 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
11160 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
11161 # to do any necessary tidying up
11162 #
11163 # Expected arguments
11164 # (none besides $self)
11165 #
11166 # Return values
11167 # 'undef' on improper arguments
11168 # 1 otherwise
11169  
11170 my ($self, $check) = @_;
11171  
11172 # Check for improper arguments
11173 if (defined $check) {
11174  
11175 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
11176 }
11177  
11178 # Only polite to destroy the GooCanvas2::Canvas and its items
11179 if ($self->canvas) {
11180  
11181 foreach my $blinkerObj ($self->ivValues('blinkerHash')) {
11182  
11183 if (defined $blinkerObj->canvasObj) {
11184  
11185 $blinkerObj->canvasObj->remove();
11186 }
11187 }
11188  
11189 $self->canvas->destroy();
11190 }
11191  
11192 return 1;
11193 }
11194  
11195 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Strip
11196  
11197 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Strip
11198  
11199 # ->signal_connects
11200  
11201 # Other functions
11202  
11203 sub createStandardBlinkers {
11204  
11205 # Called by $self->objEnable
11206 # Creates blinker objects (GA::Obj::Blinker)
11207 #
11208 # Expected arguments
11209 # (none besides $self)
11210 #
11211 # Return values
11212 # 'undef'
11213  
11214 my ($self, $check) = @_;
11215  
11216 # Check for improper arguments
11217 if (defined $check) {
11218  
11219 return $axmud::CLIENT->writeImproper($self->_objClass . '->createStandardBlinkers', @_);
11220 }
11221  
11222 for (my $count = 0; $count < $self->blinkerCount; $count++) {
11223  
11224 my $blinkerObj = Games::Axmud::Obj::Blinker->new($count);
11225 if ($blinkerObj) {
11226  
11227 $self->ivAdd('blinkerHash', $blinkerObj->number, $blinkerObj);
11228 }
11229 }
11230  
11231 return 1;
11232 }
11233  
11234 sub drawBlinker {
11235  
11236 # Called by GA::Client->spinClientLoop or GA::Win::Internal->resetBlinkers
11237 # Draws one (or all) of the blinkers in this strip object
11238 #
11239 # Expected arguments
11240 # $choice - Which blinker to draw. -1 to draw all blinkers, or one of the keys in
11241 # $self->blinkerHash (matching GA::Obj::Blinker->number)
11242 #
11243 # Optional arguments
11244 # $onFlag - TRUE if the blinker(s) should be drawn 'on', FALSE (or 'undef') if the
11245 # blinker(s) should be drawn 'off'
11246 #
11247 # Return values
11248 # 'undef'
11249  
11250 my ($self, $choice, $onFlag, $check) = @_;
11251  
11252 # Local variables
11253 my @list;
11254  
11255 # Check for improper arguments
11256 if (! defined $choice || defined $check) {
11257  
11258 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawBlinker', @_);
11259 }
11260  
11261 # Check that the blinker widgets are actually drawn (unlikely that they aren't)
11262 if (! $self->canvas) {
11263  
11264 return undef;
11265 }
11266  
11267 # Compile a list of blinkers to draw
11268 if ($choice == -1) {
11269  
11270 for (my $count = 0; $count < $self->blinkerCount; $count++) {
11271  
11272 push (@list, $count);
11273 }
11274  
11275 } else {
11276  
11277 push (@list, $choice);
11278 }
11279  
11280 # Draw each blinker in turn
11281 foreach my $number (@list) {
11282  
11283 my ($blinkerObj, $colour, $canvasObj);
11284  
11285 # Draw this blinker
11286 $blinkerObj = $self->ivShow('blinkerHash', $number);
11287 if ($blinkerObj) {
11288  
11289 # Set the colour to use
11290 if (! $onFlag) {
11291 $colour = $blinkerObj->offColour;
11292 } else {
11293 $colour = $blinkerObj->onColour;
11294 }
11295  
11296 # Destroy the old canvas item, so it can be replaced
11297 if ($blinkerObj->canvasObj) {
11298  
11299 $blinkerObj->canvasObj->remove();
11300 }
11301  
11302 $canvasObj = GooCanvas2::CanvasRect->new(
11303 'parent' => $self->canvas->get_root_item(),
11304 'x' => (($self->blinkerWidth * $number) + 3), # 2 / 22 / 42...
11305 'y' => 3, # 2
11306 'width' => $self->blinkerWidth - 6,
11307 'height' => $self->blinkerHeight - 6,
11308 # line_width = 1 looks a little harsh - doing this improves the aesthetic a bit
11309 'line_width' => 0.8,
11310 'stroke-color' => '#000000',
11311 'fill-color' => $colour,
11312 );
11313  
11314 $canvasObj->raise();
11315  
11316 # Update IVs
11317 $blinkerObj->ivPoke('canvasObj', $canvasObj);
11318 if (! $onFlag) {
11319 $blinkerObj->ivPoke('onFlag', FALSE);
11320 } else {
11321 $blinkerObj->ivPoke('onFlag', TRUE);
11322 }
11323 }
11324 }
11325  
11326 return undef;
11327 }
11328  
11329 ##################
11330 # Accessors - set
11331  
11332 sub set_hostLabel {
11333  
11334 my ($self, $text, $tooltip, $check) = @_;
11335  
11336 # Check for improper arguments
11337 if (! defined $text || defined $check) {
11338  
11339 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_hostLabel', @_);
11340 }
11341  
11342 $self->hostLabel->set_markup($text);
11343 if (defined $tooltip) {
11344  
11345 $self->hostLabel->set_tooltip_text($tooltip);
11346  
11347 } else {
11348  
11349 # Make sure any earlier tooltip is no longer visible
11350 $self->hostLabel->set_tooltip_text('');
11351 }
11352  
11353 return 1;
11354 }
11355  
11356 sub set_timeLabel {
11357  
11358 my ($self, $text, $check) = @_;
11359  
11360 # Check for improper arguments
11361 if (! defined $text || defined $check) {
11362  
11363 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_timeLabel', @_);
11364 }
11365  
11366 $self->timeLabel->set_markup($text);
11367  
11368 return 1;
11369 }
11370  
11371 ##################
11372 # Accessors - get
11373  
11374 sub hostLabel
11375 { $_[0]->{hostLabel} }
11376 sub frame
11377 { $_[0]->{frame} }
11378 sub canvas
11379 { $_[0]->{canvas} }
11380 sub timeLabel
11381 { $_[0]->{timeLabel} }
11382  
11383 sub blinkerHash
11384 { my $self = shift; return %{$self->{blinkerHash}}; }
11385 sub blinkerCount
11386 { $_[0]->{blinkerCount} }
11387 sub blinkerWidth
11388 { $_[0]->{blinkerWidth} }
11389 sub blinkerHeight
11390 { $_[0]->{blinkerHeight} }
11391 }
11392  
11393 { package Games::Axmud::Strip::Custom;
11394  
11395 # Any user-written strip objects should inherit from this object
11396  
11397 use strict;
11398 use warnings;
11399 # use diagnostics;
11400  
11401 use Glib qw(TRUE FALSE);
11402  
11403 our @ISA = qw(Games::Axmud::Generic::Strip Games::Axmud);
11404  
11405 ##################
11406 # Constructors
11407  
11408 # sub new {} # Inherited from GA::Generic::Strip
11409  
11410 ##################
11411 # Methods
11412  
11413 # Standard strip object functions
11414  
11415 # sub objEnable {} # Inherited from GA::Generic::Strip
11416  
11417 # sub objDestroy {} # Inherited from GA::Generic::Strip
11418  
11419 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Strip
11420  
11421 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Strip
11422  
11423 # ->signal_connects
11424  
11425 # Other functions
11426  
11427 ##################
11428 # Accessors - set
11429  
11430 ##################
11431 # Accessors - get
11432 }
11433  
11434 # Package must return a true value
11435 1