| 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::OtherWin::About | ||
| 16 | # The About window, showing Axmud quick help, licenses, etc | ||
| 17 | # | ||
| 18 | # Games::Axmud::OtherWin::Connect | ||
| 19 | # The Connections window, allowing the user to open a connection to a world | ||
| 20 | # | ||
| 21 | # Games::Axmud::OtherWin::ClientConsole | ||
| 22 | # The Client Console window, which can display system messages when there is no session running | ||
| 23 | # | ||
| 24 | # Games::Axmud::OtherWin::LabelDelete | ||
| 25 | # The Quick Label Deletion window, which displays labels in a region (or the whole world model), and | ||
| 26 | # invites the user to select any that should be deleted | ||
| 27 | # | ||
| 28 | # Games::Axmud::OtherWin::McpSimpleEdit | ||
| 29 | # The MCP Simple Edit window, containing a textview in which the user can type text, and some | ||
| 30 | # widgets that specify what should be done with the text | ||
| 31 | # | ||
| 32 | # Games::Axmud::OtherWin::PatternTest | ||
| 33 | # The Pattern Test window, allowing the user to check patterns/regular expressions/regexes | ||
| 34 | # | ||
| 35 | # Games::Axmud::OtherWin::QuickInput | ||
| 36 | # The Quick Input window, containing a textview in which the user can type text, and some widgets to | ||
| 37 | # specify what should be done with the text | ||
| 38 | # | ||
| 39 | # Games::Axmud::OtherWin::QuickWord | ||
| 40 | # The Quick Word window, containing various widgets for adding words to the current dictionary | ||
| 41 | # | ||
| 42 | # Games::Axmud::OtherWin::SessionConsole | ||
| 43 | # The Session Console window, which can display system messages when it's not possible to display | ||
| 44 | # them in the 'main' window | ||
| 45 | # | ||
| 46 | # Games::Axmud::OtherWin::Simulate | ||
| 47 | # The Simulate window, allowing the user to simulates various things, such as receiving text from a | ||
| 48 | # world | ||
| 49 | # | ||
| 50 | # Games::Axmud::OtherWin::SourceCode | ||
| 51 | # The Source Code Viewer window, containing a textview to show the source code for a world model | ||
| 52 | # object | ||
| 53 | # | ||
| 54 | # Games::Axmud::OtherWin::Viewer | ||
| 55 | # The data viewer window | ||
| 56 | |||
| 57 | { package Games::Axmud::OtherWin::About; | ||
| 58 | |||
| 59 | use strict; | ||
| 60 | use warnings; | ||
| 61 | # use diagnostics; | ||
| 62 | |||
| 63 | use Glib qw(TRUE FALSE); | ||
| 64 | |||
| 65 | our @ISA = qw( | ||
| 66 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 67 | Games::Axmud | ||
| 68 | ); | ||
| 69 | |||
| 70 | ################## | ||
| 71 | # Constructors | ||
| 72 | |||
| 73 | sub new { | ||
| 74 | |||
| 75 | # Called by GA::Generic::Win->createFreeWin | ||
| 76 | # Creates a new instance of the About window, which displays information usually displayed | ||
| 77 | # by the ';about' command, as well as credits, quick help and the GPL/LGPL licenses | ||
| 78 | # | ||
| 79 | # Expected arguments | ||
| 80 | # $number - Unique number for this window object | ||
| 81 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 82 | # should be created | ||
| 83 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 84 | # 'free' window object. When this window opens/closes, the owner is | ||
| 85 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 86 | # functions | ||
| 87 | # | ||
| 88 | # Optional arguments | ||
| 89 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 90 | # calling function didn't specify a session and $owner's ->session IV | ||
| 91 | # is also 'undef' | ||
| 92 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 93 | # $editObj - Ignored if set | ||
| 94 | # $tempFlag - Ignored if set | ||
| 95 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 96 | # particular 'other' window; set to an empty hash if not required | ||
| 97 | # - This type of window object recognises these initialisation settings: | ||
| 98 | # | ||
| 99 | # 'first_tab' => The tab to open when the window is created - 'about', | ||
| 100 | # 'credits', 'help', 'license' or 'license_2'. If not specified or | ||
| 101 | # 'undef', the first tab is opened | ||
| 102 | # | ||
| 103 | # Return values | ||
| 104 | # 'undef' on improper arguments | ||
| 105 | # Blessed reference to the newly-created object on success | ||
| 106 | |||
| 107 | my ( | ||
| 108 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 109 | %configHash, | ||
| 110 | ) = @_; | ||
| 111 | |||
| 112 | # Local variables | ||
| 113 | my ($widthPixels, $heightPixels); | ||
| 114 | |||
| 115 | # Check for improper arguments | ||
| 116 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 117 | |||
| 118 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 119 | } | ||
| 120 | |||
| 121 | # Only one About window can be open at a time | ||
| 122 | if ($axmud::CLIENT->aboutWin) { | ||
| 123 | |||
| 124 | $axmud::CLIENT->aboutWin->restoreFocus(); | ||
| 125 | return undef; | ||
| 126 | } | ||
| 127 | |||
| 128 | # Set the window size. Use a slightly larger window than the default, unless the user has | ||
| 129 | # specified their own default size, in which case use that | ||
| 130 | if ($axmud::CLIENT->customFreeWinWidth == $axmud::CLIENT->constFreeWinWidth) { | ||
| 131 | $widthPixels = $axmud::CLIENT->constFreeWinWidth + 50; | ||
| 132 | } else { | ||
| 133 | $widthPixels = $axmud::CLIENT->customFreeWinWidth; | ||
| 134 | } | ||
| 135 | |||
| 136 | if ($axmud::CLIENT->customFreeWinHeight == $axmud::CLIENT->constFreeWinHeight) { | ||
| 137 | $heightPixels = $axmud::CLIENT->constFreeWinHeight + 50; | ||
| 138 | } else { | ||
| 139 | $heightPixels = $axmud::CLIENT->customFreeWinHeight; | ||
| 140 | } | ||
| 141 | |||
| 142 | # Setup | ||
| 143 | my $self = { | ||
| 144 | _objName => 'other_win_' . $number, | ||
| 145 | _objClass => $class, | ||
| 146 | _parentFile => undef, # No parent file object | ||
| 147 | _parentWorld => undef, # No parent file object | ||
| 148 | _privFlag => TRUE, # All IVs are private | ||
| 149 | |||
| 150 | # Standard window object IVs | ||
| 151 | # -------------------------- | ||
| 152 | |||
| 153 | # Unique number for this window object | ||
| 154 | number => $number, | ||
| 155 | # The window category - 'grid' or 'free' | ||
| 156 | winCategory => 'free', | ||
| 157 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 158 | winType => 'other', | ||
| 159 | # A name for the window (for some 'free' windows, the same as the window type) | ||
| 160 | winName => 'about', | ||
| 161 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 162 | workspaceObj => $workspaceObj, | ||
| 163 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 164 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 165 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 166 | owner => $owner, | ||
| 167 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 168 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 169 | session => $session, | ||
| 170 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 171 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 172 | # displayed in a 'dialogue' window) | ||
| 173 | pseudoCmdMode => 'win_error', | ||
| 174 | |||
| 175 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 176 | # parent 'main' window's Gtk3::Window | ||
| 177 | # The code should use this IV when it wants to do something to the window itself | ||
| 178 | # (minimise it, make it active, etc) | ||
| 179 | winWidget => undef, | ||
| 180 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 181 | # the parent GA::Table::PseudoWin table object | ||
| 182 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 183 | # window itself | ||
| 184 | winBox => undef, | ||
| 185 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 186 | # FALSE if not | ||
| 187 | enabledFlag => FALSE, | ||
| 188 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 189 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 190 | visibleFlag => TRUE, | ||
| 191 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 192 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 193 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 194 | childFreeWinHash => {}, | ||
| 195 | |||
| 196 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 197 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 198 | # area) | ||
| 199 | packingBox => undef, # Gtk3::VBox | ||
| 200 | |||
| 201 | # Standard IVs for 'free' windows | ||
| 202 | |||
| 203 | # The window's default size, in pixels | ||
| 204 | widthPixels => $widthPixels, | ||
| 205 | heightPixels => $heightPixels, | ||
| 206 | # Default border/item spacing sizes used in the window, in pixels | ||
| 207 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 208 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 209 | |||
| 210 | # A string to use as the window title. If 'undef', a generic title is used | ||
| 211 | title => $axmud::SCRIPT . ' information', | ||
| 212 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 213 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 214 | # name and type. Set to an empty hash if not required | ||
| 215 | configHash => {%configHash}, | ||
| 216 | |||
| 217 | # IVs for this type of window | ||
| 218 | |||
| 219 | # Widgets | ||
| 220 | notebook => undef, # Gtk3::Notebook | ||
| 221 | button => undef, # Gtk3::Button | ||
| 222 | }; | ||
| 223 | |||
| 224 | # Bless the object into existence | ||
| 225 | bless $self, $class; | ||
| 226 | |||
| 227 | return $self; | ||
| 228 | } | ||
| 229 | |||
| 230 | ################## | ||
| 231 | # Methods | ||
| 232 | |||
| 233 | # Standard window object functions | ||
| 234 | |||
| 235 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 236 | |||
| 237 | sub winEnable { | ||
| 238 | |||
| 239 | # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup | ||
| 240 | # After the Gtk3::Window has been setup and moved into position, makes it visible | ||
| 241 | # | ||
| 242 | # Expected arguments | ||
| 243 | # (none besides $self) | ||
| 244 | # | ||
| 245 | # Return values | ||
| 246 | # 'undef' on improper arguments | ||
| 247 | # 1 on success | ||
| 248 | |||
| 249 | my ($self, $check) = @_; | ||
| 250 | |||
| 251 | # Local variables | ||
| 252 | my $firstTab; | ||
| 253 | |||
| 254 | # Check for improper arguments | ||
| 255 | if (defined $check) { | ||
| 256 | |||
| 257 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_); | ||
| 258 | } | ||
| 259 | |||
| 260 | # Make the window appear on the desktop | ||
| 261 | $self->winShowAll($self->_objClass . '->winEnable'); | ||
| 262 | $self->ivPoke('enabledFlag', TRUE); | ||
| 263 | |||
| 264 | # This type of window is unique (only one can be open at any time); inform the GA::Client | ||
| 265 | # it has opened | ||
| 266 | $axmud::CLIENT->set_aboutWin($self); | ||
| 267 | |||
| 268 | # If a tab to show on startup was specified, open it | ||
| 269 | $firstTab = $self->ivShow('configHash', 'first_tab'); | ||
| 270 | if (defined $firstTab) { | ||
| 271 | |||
| 272 | # (Window is open at the 'about' tab by default, so we don't have to check that | ||
| 273 | # $firstTab is set to 'about') | ||
| 274 | if ($firstTab eq 'credits') { | ||
| 275 | $self->notebook->set_current_page(1); | ||
| 276 | } elsif ($firstTab eq 'help') { | ||
| 277 | $self->notebook->set_current_page(2); | ||
| 278 | } elsif ($firstTab eq 'peek') { | ||
| 279 | $self->notebook->set_current_page(3); | ||
| 280 | } elsif ($firstTab eq 'changes') { | ||
| 281 | $self->notebook->set_current_page(4); | ||
| 282 | } elsif ($firstTab eq 'install') { | ||
| 283 | $self->notebook->set_current_page(5); | ||
| 284 | } elsif ($firstTab eq 'license') { | ||
| 285 | $self->notebook->set_current_page(6); | ||
| 286 | } elsif ($firstTab eq 'license_2') { | ||
| 287 | $self->notebook->set_current_page(7); | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 | return 1; | ||
| 292 | } | ||
| 293 | |||
| 294 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 295 | |||
| 296 | sub winDestroy { | ||
| 297 | |||
| 298 | # Can be called by anything | ||
| 299 | # Updates IVs | ||
| 300 | # | ||
| 301 | # Expected arguments | ||
| 302 | # (none besides $self) | ||
| 303 | # | ||
| 304 | # Return values | ||
| 305 | # 'undef' on improper arguments, if the window can't be destroyed or if it has already | ||
| 306 | # been destroyed | ||
| 307 | # 1 on success | ||
| 308 | |||
| 309 | my ($self, $check) = @_; | ||
| 310 | |||
| 311 | # Check for improper arguments | ||
| 312 | if (defined $check) { | ||
| 313 | |||
| 314 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_); | ||
| 315 | } | ||
| 316 | |||
| 317 | if (! $self->winBox) { | ||
| 318 | |||
| 319 | # Window already destroyed in a previous call to this function | ||
| 320 | return undef; | ||
| 321 | } | ||
| 322 | |||
| 323 | # Close any 'free' windows for which this window is a parent | ||
| 324 | foreach my $winObj ($self->ivValues('childFreeWinHash')) { | ||
| 325 | |||
| 326 | $winObj->winDestroy(); | ||
| 327 | } | ||
| 328 | |||
| 329 | # Destroy the Gtk3::Window | ||
| 330 | eval { $self->winBox->destroy(); }; | ||
| 331 | if ($@) { | ||
| 332 | |||
| 333 | # Window can't be destroyed | ||
| 334 | return undef; | ||
| 335 | |||
| 336 | } else { | ||
| 337 | |||
| 338 | $self->ivUndef('winWidget'); | ||
| 339 | $self->ivUndef('winBox'); | ||
| 340 | } | ||
| 341 | |||
| 342 | # Inform the owner and the desktop object of this 'free' window's demise | ||
| 343 | $axmud::CLIENT->desktopObj->del_freeWin($self); | ||
| 344 | if ($self->owner) { | ||
| 345 | |||
| 346 | $self->owner->del_childFreeWin($self); | ||
| 347 | } | ||
| 348 | |||
| 349 | # This type of window is unique (only one can be open at any time); inform the GA::Client | ||
| 350 | # it has closed | ||
| 351 | $axmud::CLIENT->set_aboutWin(); | ||
| 352 | |||
| 353 | return 1; | ||
| 354 | } | ||
| 355 | |||
| 356 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 357 | |||
| 358 | sub drawWidgets { | ||
| 359 | |||
| 360 | # Called by $self->winSetup | ||
| 361 | # Sets up the About window with its standard widgets | ||
| 362 | # | ||
| 363 | # Expected arguments | ||
| 364 | # (none besides $self) | ||
| 365 | # | ||
| 366 | # Return values | ||
| 367 | # 'undef' on improper arguments | ||
| 368 | # 1 otherwise | ||
| 369 | |||
| 370 | my ($self, $check) = @_; | ||
| 371 | |||
| 372 | # Local variables | ||
| 373 | my ( | ||
| 374 | $file, $fileHandle, | ||
| 375 | @aboutList, @helpList, @peekList, @changesList, @installList, @licenseList, | ||
| 376 | @license2List, | ||
| 377 | ); | ||
| 378 | |||
| 379 | # Check for improper arguments | ||
| 380 | if (defined $check) { | ||
| 381 | |||
| 382 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 383 | } | ||
| 384 | |||
| 385 | # Create a packing box | ||
| 386 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 387 | $self->winBox->add($packingBox); | ||
| 388 | $packingBox->set_border_width(0); | ||
| 389 | |||
| 390 | # Create an image on the left | ||
| 391 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 392 | $packingBox->pack_start($hBox, TRUE, TRUE, 0); | ||
| 393 | |||
| 394 | my $vBox = Gtk3::VBox->new(FALSE, 0); | ||
| 395 | $hBox->pack_start($vBox, FALSE, FALSE, 0); | ||
| 396 | |||
| 397 | my $frame = Gtk3::Frame->new(undef); | ||
| 398 | $vBox->pack_start($frame, FALSE, FALSE, 0); | ||
| 399 | $frame->set_size_request(64, 64); | ||
| 400 | $frame->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 401 | |||
| 402 | my $image = Gtk3::Image->new_from_file($axmud::CLIENT->getDialogueIcon()); | ||
| 403 | $frame->add($image); | ||
| 404 | |||
| 405 | # Create a notebook on the right | ||
| 406 | my $notebook = Gtk3::Notebook->new(); | ||
| 407 | $hBox->pack_start($notebook, TRUE, TRUE, $self->spacingPixels); | ||
| 408 | $notebook->set_scrollable(TRUE); | ||
| 409 | $notebook->popup_enable(); | ||
| 410 | |||
| 411 | # Create a button at the bottom | ||
| 412 | my $hBox2 = Gtk3::HBox->new(FALSE, 0); | ||
| 413 | $packingBox->pack_end($hBox2, FALSE, FALSE, $self->spacingPixels); | ||
| 414 | |||
| 415 | # The button's label includes some extra space characters to make it a little easier to | ||
| 416 | # click on | ||
| 417 | my $button = Gtk3::Button->new(' OK '); | ||
| 418 | $hBox2->pack_end($button, FALSE, FALSE, 0); | ||
| 419 | $button->get_child->set_width_chars(10); | ||
| 420 | $button->signal_connect('clicked' => sub { | ||
| 421 | |||
| 422 | $self->winDestroy(); | ||
| 423 | }); | ||
| 424 | |||
| 425 | # Add the 'about' tab to the notebook | ||
| 426 | push (@aboutList, | ||
| 427 | $axmud::SCRIPT . ' v' . $axmud::VERSION . ' (' . $axmud::DATE . ') by ' | ||
| 428 | . $axmud::AUTHORS, | ||
| 429 | $axmud::COPYRIGHT, | ||
| 430 | 'Website: ' . $axmud::URL, | ||
| 431 | ' ', # Empty line | ||
| 432 | @axmud::LICENSE_LIST, | ||
| 433 | ); | ||
| 434 | |||
| 435 | $self->addTab($notebook, '_About', TRUE, @aboutList); | ||
| 436 | |||
| 437 | # Add the 'credits' tab to the notebook | ||
| 438 | $self->addTab($notebook, '_Credits', TRUE, @axmud::CREDIT_LIST); | ||
| 439 | |||
| 440 | # Load the quick help file | ||
| 441 | $file = $axmud::SHARE_DIR . '/help/misc/quickhelp'; | ||
| 442 | if (! (-e $file)) { | ||
| 443 | |||
| 444 | push (@helpList, 'Quick help file missing'); | ||
| 445 | |||
| 446 | } else { | ||
| 447 | |||
| 448 | if (! open($fileHandle, $file)) { | ||
| 449 | |||
| 450 | push (@helpList, 'Unable to read quick help file'); | ||
| 451 | |||
| 452 | } else { | ||
| 453 | |||
| 454 | @helpList = <$fileHandle>; | ||
| 455 | close($fileHandle); | ||
| 456 | } | ||
| 457 | } | ||
| 458 | |||
| 459 | # Add the 'help' tab to the notebook | ||
| 460 | $self->addTab($notebook, 'Quick _help', FALSE, @helpList); | ||
| 461 | |||
| 462 | # Load the peek/poke help file | ||
| 463 | $file = $axmud::SHARE_DIR . '/help/misc/peekpoke'; | ||
| 464 | if (! (-e $file)) { | ||
| 465 | |||
| 466 | push (@peekList, 'Peek/poke help file missing'); | ||
| 467 | |||
| 468 | } else { | ||
| 469 | |||
| 470 | if (! open($fileHandle, $file)) { | ||
| 471 | |||
| 472 | push (@peekList, 'Unable to read peek/poke help file'); | ||
| 473 | |||
| 474 | } else { | ||
| 475 | |||
| 476 | @peekList = <$fileHandle>; | ||
| 477 | close($fileHandle); | ||
| 478 | } | ||
| 479 | } | ||
| 480 | |||
| 481 | # Add the 'peek/poke' tab to the notebook | ||
| 482 | $self->addTab($notebook, '_Peek/Poke', FALSE, @peekList); | ||
| 483 | |||
| 484 | # Load the CHANGES file | ||
| 485 | $file = $axmud::SHARE_DIR . '/../CHANGES'; | ||
| 486 | if (! (-e $file)) { | ||
| 487 | |||
| 488 | push (@peekList, 'Changes file missing'); | ||
| 489 | |||
| 490 | } else { | ||
| 491 | |||
| 492 | if (! open($fileHandle, $file)) { | ||
| 493 | |||
| 494 | push ( | ||
| 495 | @changesList, | ||
| 496 | 'Unable to read changes file', | ||
| 497 | ); | ||
| 498 | |||
| 499 | } else { | ||
| 500 | |||
| 501 | @changesList = <$fileHandle>; | ||
| 502 | close($fileHandle); | ||
| 503 | } | ||
| 504 | } | ||
| 505 | |||
| 506 | # Add the 'changes' tab to the notebook | ||
| 507 | $self->addTab($notebook, 'Cha_nges', FALSE, @changesList); | ||
| 508 | |||
| 509 | # Load the GPL license file | ||
| 510 | $file = $axmud::SHARE_DIR . '/../COPYING'; | ||
| 511 | if (! (-e $file)) { | ||
| 512 | |||
| 513 | push (@licenseList, 'License file missing. Go to <http://www.gnu.org/licenses/>'); | ||
| 514 | |||
| 515 | } else { | ||
| 516 | |||
| 517 | if (! open($fileHandle, $file)) { | ||
| 518 | |||
| 519 | push ( | ||
| 520 | @licenseList, | ||
| 521 | 'Unable to read license file. Go to <http://www.gnu.org/licenses/>', | ||
| 522 | ); | ||
| 523 | |||
| 524 | } else { | ||
| 525 | |||
| 526 | @licenseList = <$fileHandle>; | ||
| 527 | close($fileHandle); | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | # Add the 'license' tab to the notebook | ||
| 532 | $self->addTab($notebook, '_GPL License', FALSE, @licenseList); | ||
| 533 | |||
| 534 | # Load the LGPL license file | ||
| 535 | $file = $axmud::SHARE_DIR . '/../COPYING.LESSER'; | ||
| 536 | if (! (-e $file)) { | ||
| 537 | |||
| 538 | push (@license2List, 'License file missing. Go to <http://www.gnu.org/licenses/>'); | ||
| 539 | |||
| 540 | } else { | ||
| 541 | |||
| 542 | if (! open($fileHandle, $file)) { | ||
| 543 | |||
| 544 | push ( | ||
| 545 | @license2List, | ||
| 546 | 'Unable to read license file. Go to <http://www.gnu.org/licenses/>', | ||
| 547 | ); | ||
| 548 | |||
| 549 | } else { | ||
| 550 | |||
| 551 | @license2List = <$fileHandle>; | ||
| 552 | close($fileHandle); | ||
| 553 | } | ||
| 554 | } | ||
| 555 | |||
| 556 | # Add the 'license' tab to the notebook | ||
| 557 | $self->addTab($notebook, '_LGPL License', FALSE, @license2List); | ||
| 558 | |||
| 559 | # Update IVs | ||
| 560 | $self->ivPoke('packingBox', $packingBox); | ||
| 561 | $self->ivPoke('notebook', $notebook); | ||
| 562 | $self->ivPoke('button', $button); | ||
| 563 | |||
| 564 | return 1; | ||
| 565 | } | ||
| 566 | |||
| 567 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 568 | |||
| 569 | # ->signal_connects | ||
| 570 | |||
| 571 | # Other functions | ||
| 572 | |||
| 573 | sub addTab { | ||
| 574 | |||
| 575 | # Called by $self->drawWidgets | ||
| 576 | # Adds a tab to the About window's notebook | ||
| 577 | # | ||
| 578 | # Expected arguments | ||
| 579 | # $notebook - The Gtk3::Notebook to which the tab must be added | ||
| 580 | # $label - The tab's label text | ||
| 581 | # | ||
| 582 | # Optional arguments | ||
| 583 | # $newlineFlag - TRUE if a newline character should be added to every line in @list, | ||
| 584 | # FALSE if not (because the contents of @list were loaded from a file | ||
| 585 | # and already contain newline characters) | ||
| 586 | # @list - A list of lines to add to the Gtk3::TextView (can be an empty list) | ||
| 587 | # | ||
| 588 | # Return values | ||
| 589 | # 'undef' on improper arguments | ||
| 590 | # 1 otherwise | ||
| 591 | |||
| 592 | my ($self, $notebook, $label, $newlineFlag, @list) = @_; | ||
| 593 | |||
| 594 | # Check for improper arguments | ||
| 595 | if (! defined $notebook || ! defined $label) { | ||
| 596 | |||
| 597 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addTab', @_); | ||
| 598 | } | ||
| 599 | |||
| 600 | # Add the tab | ||
| 601 | my $tab = Gtk3::Label->new_with_mnemonic($label); | ||
| 602 | |||
| 603 | my $scroller = Gtk3::ScrolledWindow->new(); | ||
| 604 | $notebook->append_page($scroller, $tab); | ||
| 605 | $scroller->set_policy('automatic', 'automatic'); | ||
| 606 | |||
| 607 | # Create a textview using the system's preferred colours and fonts | ||
| 608 | my $textView = Gtk3::TextView->new(); | ||
| 609 | $scroller->add_with_viewport($textView); | ||
| 610 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 611 | $textView->set_buffer($buffer); | ||
| 612 | $textView->set_editable(FALSE); | ||
| 613 | $textView->set_cursor_visible(FALSE); | ||
| 614 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView); | ||
| 615 | |||
| 616 | # Fill the textview | ||
| 617 | if (! $newlineFlag) { | ||
| 618 | $buffer->set_text(join("", @list)); | ||
| 619 | } else { | ||
| 620 | $buffer->set_text(join("\n", @list)); | ||
| 621 | } | ||
| 622 | |||
| 623 | return 1 | ||
| 624 | } | ||
| 625 | |||
| 626 | ################## | ||
| 627 | # Accessors - set | ||
| 628 | |||
| 629 | ################## | ||
| 630 | # Accessors - get | ||
| 631 | |||
| 632 | sub notebook | ||
| 633 | { $_[0]->{notebook} } | ||
| 634 | sub button | ||
| 635 | { $_[0]->{button} } | ||
| 636 | } | ||
| 637 | |||
| 638 | { package Games::Axmud::OtherWin::Connect; | ||
| 639 | |||
| 640 | use strict; | ||
| 641 | use warnings; | ||
| 642 | # use diagnostics; | ||
| 643 | |||
| 644 | use Glib qw(TRUE FALSE); | ||
| 645 | |||
| 646 | our @ISA = qw( | ||
| 647 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 648 | Games::Axmud | ||
| 649 | ); | ||
| 650 | |||
| 651 | ################## | ||
| 652 | # Constructors | ||
| 653 | |||
| 654 | sub new { | ||
| 655 | |||
| 656 | # Called by GA::Generic::Win->createFreeWin | ||
| 657 | # Creates a new instance of the Connections window, which displays a list of world | ||
| 658 | # profiles and invites the user to connect to one of them | ||
| 659 | # | ||
| 660 | # Expected arguments | ||
| 661 | # $number - Unique number for this window object | ||
| 662 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 663 | # should be created | ||
| 664 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 665 | # 'free' window object. When this window opens/closes, the owner is | ||
| 666 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 667 | # functions | ||
| 668 | # | ||
| 669 | # Optional arguments | ||
| 670 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 671 | # calling function didn't specify a session and $owner's ->session IV | ||
| 672 | # is also 'undef' | ||
| 673 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 674 | # $editObj - Ignored if set | ||
| 675 | # $tempFlag - Ignored if set | ||
| 676 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 677 | # particular 'other' window; set to an empty hash if not required | ||
| 678 | # - This type of window object recognises these initialisation settings: | ||
| 679 | # | ||
| 680 | # ... | ||
| 681 | # | ||
| 682 | # Return values | ||
| 683 | # 'undef' on improper arguments | ||
| 684 | # Blessed reference to the newly-created object on success | ||
| 685 | |||
| 686 | my ( | ||
| 687 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 688 | %configHash, | ||
| 689 | ) = @_; | ||
| 690 | |||
| 691 | # Local variables | ||
| 692 | my ($widthPixels, $heightPixels); | ||
| 693 | |||
| 694 | # Check for improper arguments | ||
| 695 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 696 | |||
| 697 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 698 | } | ||
| 699 | |||
| 700 | # Only one Connections window can be open at a time | ||
| 701 | if ($axmud::CLIENT->connectWin) { | ||
| 702 | |||
| 703 | $axmud::CLIENT->connectWin->restoreFocus(); | ||
| 704 | return undef; | ||
| 705 | } | ||
| 706 | |||
| 707 | # Set the window size. Use a slightly larger window than the default, unless the user has | ||
| 708 | # specified their own default size, in which case use that | ||
| 709 | if ($axmud::CLIENT->customFreeWinWidth == $axmud::CLIENT->constFreeWinWidth) { | ||
| 710 | $widthPixels = $axmud::CLIENT->constFreeWinWidth + 100; | ||
| 711 | } else { | ||
| 712 | $widthPixels = $axmud::CLIENT->customFreeWinWidth; | ||
| 713 | } | ||
| 714 | |||
| 715 | if ($axmud::CLIENT->customFreeWinHeight == $axmud::CLIENT->constFreeWinHeight) { | ||
| 716 | $heightPixels = $axmud::CLIENT->constFreeWinHeight + 50; | ||
| 717 | } else { | ||
| 718 | $heightPixels = $axmud::CLIENT->customFreeWinHeight; | ||
| 719 | } | ||
| 720 | |||
| 721 | # Setup | ||
| 722 | my $self = { | ||
| 723 | _objName => 'other_win_' . $number, | ||
| 724 | _objClass => $class, | ||
| 725 | _parentFile => undef, # No parent file object | ||
| 726 | _parentWorld => undef, # No parent file object | ||
| 727 | _privFlag => TRUE, # All IVs are private | ||
| 728 | |||
| 729 | # Standard window object IVs | ||
| 730 | # -------------------------- | ||
| 731 | |||
| 732 | # Unique number for this window object | ||
| 733 | number => $number, | ||
| 734 | # The window category - 'grid' or 'free' | ||
| 735 | winCategory => 'free', | ||
| 736 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 737 | winType => 'other', | ||
| 738 | # A name for the window (for some 'free' windows, the same as the window type) | ||
| 739 | winName => 'connect' , | ||
| 740 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 741 | workspaceObj => $workspaceObj, | ||
| 742 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 743 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 744 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 745 | owner => $owner, | ||
| 746 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 747 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 748 | session => $session, | ||
| 749 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 750 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 751 | # displayed in a 'dialogue' window) | ||
| 752 | pseudoCmdMode => 'win_error', | ||
| 753 | |||
| 754 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 755 | # parent 'main' window's Gtk3::Window | ||
| 756 | # The code should use this IV when it wants to do something to the window itself | ||
| 757 | # (minimise it, make it active, etc) | ||
| 758 | winWidget => undef, | ||
| 759 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 760 | # the parent GA::Table::PseudoWin table object | ||
| 761 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 762 | # window itself | ||
| 763 | winBox => undef, | ||
| 764 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 765 | # FALSE if not | ||
| 766 | enabledFlag => FALSE, | ||
| 767 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 768 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 769 | visibleFlag => TRUE, | ||
| 770 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 771 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 772 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 773 | childFreeWinHash => {}, | ||
| 774 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 775 | # window is informed via a call to $self->del_childFreeWin | ||
| 776 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 777 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 778 | # this hash; a hash in the form | ||
| 779 | # $childDestroyHash{unique_number} = list_reference | ||
| 780 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 781 | # reference to a list in groups of 2, in the form | ||
| 782 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 783 | childDestroyHash => {}, | ||
| 784 | |||
| 785 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 786 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 787 | # area) | ||
| 788 | packingBox => undef, | ||
| 789 | |||
| 790 | # Standard IVs for 'free' windows | ||
| 791 | |||
| 792 | # The window's default size, in pixels | ||
| 793 | widthPixels => $widthPixels, | ||
| 794 | heightPixels => $heightPixels, | ||
| 795 | # Default border/item spacing sizes used in the window, in pixels | ||
| 796 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 797 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 798 | |||
| 799 | # A string to use as the window title. If 'undef', a generic title is used | ||
| 800 | title => $axmud::SCRIPT . ' Connections', | ||
| 801 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 802 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 803 | # name and type. Set to an empty hash if not required | ||
| 804 | configHash => {%configHash}, | ||
| 805 | |||
| 806 | # IVs for this type of window | ||
| 807 | |||
| 808 | # Widgets | ||
| 809 | hPaned => undef, # Gtk3::HPaned | ||
| 810 | # Left section widgets | ||
| 811 | vBox => undef, # Gtk3::VBox | ||
| 812 | frame => undef, # Gtk3::Frame | ||
| 813 | image => undef, # Gtk3::Image | ||
| 814 | hBox => undef, # Gtk3::HBox | ||
| 815 | objModel => undef, # Gtk3::TreeStore | ||
| 816 | treeView => undef, # Gtk3::TreeView | ||
| 817 | treeViewColumn => undef, # Gtk3::TreeViewColumn | ||
| 818 | frame2 => undef, # Gtk3::Frame | ||
| 819 | scroller => undef, # Gtk3::ScrolledWindow | ||
| 820 | # Right section widgets | ||
| 821 | frame3 => undef, # Gtk3::Frame | ||
| 822 | scroller2 => undef, # Gtk3::ScrolledWindow | ||
| 823 | grid => undef, # Gtk3::Grid | ||
| 824 | # Strip widgets | ||
| 825 | preConfigButton => undef, # Gtk3::RadioToolButton | ||
| 826 | otherWorldButton => undef, # Gtk3::RadioToolButton | ||
| 827 | sortAzButton => undef, # Gtk3::RadioToolButton | ||
| 828 | sortZaButton => undef, # Gtk3::RadioToolButton | ||
| 829 | sortRandButton => undef, # Gtk3::RadioToolButton | ||
| 830 | searchButton => undef, # Gtk3::Button | ||
| 831 | cancelSearchButton => undef, # Gtk3::Button | ||
| 832 | consoleButton => undef, # Gtk3::Button | ||
| 833 | # Grid widgets | ||
| 834 | entry => undef, # Gtk3::Entry | ||
| 835 | entry2 => undef, # Gtk3::Entry | ||
| 836 | entry3 => undef, # Gtk3::Entry | ||
| 837 | radioButton => undef, # Gtk3::RadioButton | ||
| 838 | radioButton2 => undef, # Gtk3::RadioButton | ||
| 839 | radioButton3 => undef, # Gtk3::RadioButton | ||
| 840 | radioButton4 => undef, # Gtk3::RadioButton | ||
| 841 | checkButton => undef, # Gtk3::CheckButton | ||
| 842 | comboBox => undef, # Gtk3::ComboBox | ||
| 843 | addCharButton => undef, # Gtk3::Button | ||
| 844 | editPwdButton => undef, # Gtk3::Button | ||
| 845 | editAccButton => undef, # Gtk3::Button | ||
| 846 | websiteLabel => undef, # Gtk3::Label | ||
| 847 | connectionLabel => undef, # Gtk3::Label | ||
| 848 | descripTextView => undef, # Gtk3::TextView | ||
| 849 | descripBuffer => undef, # Gtk3::TextBuffer | ||
| 850 | createWorldButton => undef, # Gtk3::Button | ||
| 851 | resetWorldButton => undef, # Gtk3::Button | ||
| 852 | offlineButton => undef, # Gtk3::Button | ||
| 853 | connectButton => undef, # Gtk3::Button | ||
| 854 | |||
| 855 | # Path to the default icon to use in the top-left corner | ||
| 856 | defaultIcon => $axmud::CLIENT->getClientLogo(), | ||
| 857 | # The size of the image containing each world's icon (or the default icon) | ||
| 858 | imageWidth => 300, | ||
| 859 | imageHeight => 200, | ||
| 860 | # Standard size of the Gtk3::Grid used (a 12x12 grid, with a spare cell around every | ||
| 861 | # border) | ||
| 862 | gridWidth => 13, | ||
| 863 | gridHeight => 13, | ||
| 864 | |||
| 865 | # A hash linking all the world names listed in the treeview to their corresponding | ||
| 866 | # world profile object. Hash in the form | ||
| 867 | # $worldHash{name} = blessed_reference_to_world_profile | ||
| 868 | # ...where 'name' can be the world's ->name or its ->longName, depending on how it was | ||
| 869 | # displayed in the treeview | ||
| 870 | # NB ->worldHash also contains an entry in the form | ||
| 871 | # $worldHash{create_new_world_string} = undef; | ||
| 872 | worldHash => {}, | ||
| 873 | # A hash of GA::Obj::MiniWorld objects, which store changes made to the profiles in the | ||
| 874 | # Connections window until it's time to copy them into the main world profile object. | ||
| 875 | # Hash in the form | ||
| 876 | # $miniWorldHash{profile} = blessed_reference_to_the_mini_world_object | ||
| 877 | miniWorldHash => {}, | ||
| 878 | # The GA::Profile::World that's currently displayed in the window. If the user is | ||
| 879 | # creating a new world from here, set to 'undef' (even if the entry box for the new | ||
| 880 | # world's name contains text) | ||
| 881 | worldObj => undef, | ||
| 882 | # The GA::Obj::MiniWorld that stores the changes being made by the user to the grid | ||
| 883 | # widgets. For an existing world profile, the mini-world exists in $self->worldHash; | ||
| 884 | # otherwise it's a temporary GA::Obj::MiniWorld that might (or might not) be stored as | ||
| 885 | # a world profile, at some point | ||
| 886 | miniWorldObj => undef, | ||
| 887 | # Flag set to TRUE when $self->resetGridWidgets or $self->updateGridWidgets are | ||
| 888 | # changing the value displayed in the grid widgets; this stops the mini-world object | ||
| 889 | # from being modified (the mini-world object should only store changes made by the | ||
| 890 | # user) | ||
| 891 | updateFlag => undef, | ||
| 892 | |||
| 893 | # First line displayed in the Gtk3::TreeView | ||
| 894 | newWorldString => '<b><i>Create new world</i></b>', | ||
| 895 | # First line displayed in the Gtk3::ComboBox | ||
| 896 | noCharString => '<no character>', | ||
| 897 | # First line displayed in 'information' section | ||
| 898 | noWebsiteString => 'Websites: (no websites)', | ||
| 899 | # Second line | ||
| 900 | noConnectString => 'Connections: 0', | ||
| 901 | |||
| 902 | # Current search terms. If 'undef', all worlds are listed; otherwise, only those worlds | ||
| 903 | # matching one or both search terms are listed | ||
| 904 | searchRegex => undef, | ||
| 905 | searchLanguage => undef, | ||
| 906 | }; | ||
| 907 | |||
| 908 | # Bless the object into existence | ||
| 909 | bless $self, $class; | ||
| 910 | |||
| 911 | return $self; | ||
| 912 | } | ||
| 913 | |||
| 914 | ################## | ||
| 915 | # Methods | ||
| 916 | |||
| 917 | # Standard window object functions | ||
| 918 | |||
| 919 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 920 | |||
| 921 | sub winEnable { | ||
| 922 | |||
| 923 | # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup | ||
| 924 | # After the Gtk3::Window has been setup and moved into position, makes it visible | ||
| 925 | # | ||
| 926 | # Expected arguments | ||
| 927 | # (none besides $self) | ||
| 928 | # | ||
| 929 | # Return values | ||
| 930 | # 'undef' on improper arguments | ||
| 931 | # 1 on success | ||
| 932 | |||
| 933 | my ($self, $check) = @_; | ||
| 934 | |||
| 935 | # Check for improper arguments | ||
| 936 | if (defined $check) { | ||
| 937 | |||
| 938 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_); | ||
| 939 | } | ||
| 940 | |||
| 941 | # Make the window appear on the desktop | ||
| 942 | $self->winShowAll($self->_objClass . '->winEnable'); | ||
| 943 | $self->ivPoke('enabledFlag', TRUE); | ||
| 944 | |||
| 945 | # Fill the treeview | ||
| 946 | $self->resetTreeView($self->treeView); | ||
| 947 | |||
| 948 | # The 'connect' button should have focus | ||
| 949 | $self->connectButton->grab_focus(); | ||
| 950 | |||
| 951 | # This type of window is unique (only one can be open at any time); inform the GA::Client | ||
| 952 | # it has opened | ||
| 953 | $axmud::CLIENT->set_connectWin($self); | ||
| 954 | |||
| 955 | return 1; | ||
| 956 | } | ||
| 957 | |||
| 958 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 959 | |||
| 960 | sub winDestroy { | ||
| 961 | |||
| 962 | # Can be called by anything | ||
| 963 | # Updates IVs | ||
| 964 | # | ||
| 965 | # Expected arguments | ||
| 966 | # (none besides $self) | ||
| 967 | # | ||
| 968 | # Return values | ||
| 969 | # 'undef' on improper arguments, if the window can't be destroyed or if it has already | ||
| 970 | # been destroyed | ||
| 971 | # 1 on success | ||
| 972 | |||
| 973 | my ($self, $check) = @_; | ||
| 974 | |||
| 975 | # Check for improper arguments | ||
| 976 | if (defined $check) { | ||
| 977 | |||
| 978 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_); | ||
| 979 | } | ||
| 980 | |||
| 981 | if (! $self->winBox) { | ||
| 982 | |||
| 983 | # Window already destroyed in a previous call to this function | ||
| 984 | return undef; | ||
| 985 | } | ||
| 986 | |||
| 987 | # Close any 'free' windows for which this window is a parent | ||
| 988 | foreach my $winObj ($self->ivValues('childFreeWinHash')) { | ||
| 989 | |||
| 990 | $winObj->winDestroy(); | ||
| 991 | } | ||
| 992 | |||
| 993 | # Destroy the Gtk3::Window | ||
| 994 | eval { $self->winBox->destroy(); }; | ||
| 995 | if ($@) { | ||
| 996 | |||
| 997 | # Window can't be destroyed | ||
| 998 | return undef; | ||
| 999 | |||
| 1000 | } else { | ||
| 1001 | |||
| 1002 | $self->ivUndef('winWidget'); | ||
| 1003 | $self->ivUndef('winBox'); | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | # Inform the owner and the desktop object of this 'free' window's demise | ||
| 1007 | $axmud::CLIENT->desktopObj->del_freeWin($self); | ||
| 1008 | if ($self->owner) { | ||
| 1009 | |||
| 1010 | $self->owner->del_childFreeWin($self); | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | # This type of window is unique (only one can be open at any time); inform the GA::Client | ||
| 1014 | # it has closed | ||
| 1015 | $axmud::CLIENT->set_connectWin(); | ||
| 1016 | |||
| 1017 | return 1; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 1021 | |||
| 1022 | sub drawWidgets { | ||
| 1023 | |||
| 1024 | # Called by $self->winSetup | ||
| 1025 | # Sets up the Connections window with its standard widgets | ||
| 1026 | # | ||
| 1027 | # Expected arguments | ||
| 1028 | # (none besides $self) | ||
| 1029 | # | ||
| 1030 | # Return values | ||
| 1031 | # 'undef' on improper arguments | ||
| 1032 | # 1 otherwise | ||
| 1033 | |||
| 1034 | my ($self, $check) = @_; | ||
| 1035 | |||
| 1036 | # Check for improper arguments | ||
| 1037 | if (defined $check) { | ||
| 1038 | |||
| 1039 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | # Create a packing box | ||
| 1043 | my $packingBox = Gtk3::VBox->new(FALSE, $self->spacingPixels); | ||
| 1044 | $self->winBox->add($packingBox); | ||
| 1045 | $packingBox->set_border_width(0); | ||
| 1046 | |||
| 1047 | # Update IVs immediately, for the benefit of any functions called | ||
| 1048 | $self->ivPoke('packingBox', $packingBox); | ||
| 1049 | |||
| 1050 | # Create a horizontal pane to divide the window in two, with an image/treeview on the | ||
| 1051 | # left, and everything else on the right | ||
| 1052 | my $hPaned = Gtk3::HPaned->new(); | ||
| 1053 | $packingBox->pack_start($hPaned, TRUE, TRUE, 0); | ||
| 1054 | $hPaned->set_wide_handle(TRUE); | ||
| 1055 | |||
| 1056 | # On the left, create a vertical packing box, with an image at the top, a strip of buttons | ||
| 1057 | # in the middle and a treeview at the bottom | ||
| 1058 | my $vBox = Gtk3::VBox->new(FALSE, $self->spacingPixels); | ||
| 1059 | $hPaned->add1($vBox); | ||
| 1060 | |||
| 1061 | # Create a frame containing an image | ||
| 1062 | my $frame = Gtk3::Frame->new(undef); | ||
| 1063 | $vBox->pack_start($frame, FALSE, FALSE, 0); | ||
| 1064 | $frame->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 1065 | |||
| 1066 | my $image = Gtk3::Image->new_from_file($self->defaultIcon); | ||
| 1067 | $frame->add($image); | ||
| 1068 | |||
| 1069 | # Create a strip of buttons | ||
| 1070 | my $hBox = Gtk3::HBox->new(FALSE, FALSE); | ||
| 1071 | $vBox->pack_start($hBox, FALSE, FALSE, 0); | ||
| 1072 | |||
| 1073 | # Create a treeview | ||
| 1074 | my $objModel = Gtk3::TreeStore->new( ['Glib::String', 'Glib::Uint'] ); | ||
| 1075 | my $treeView = Gtk3::TreeView->new($objModel); | ||
| 1076 | $treeView->set_enable_search(FALSE); | ||
| 1077 | $treeView->get_selection->signal_connect('changed' => sub { | ||
| 1078 | |||
| 1079 | if (! $self->updateFlag) { | ||
| 1080 | |||
| 1081 | my ($selection) = @_; | ||
| 1082 | |||
| 1083 | $self->selectWorldCallback($selection); | ||
| 1084 | } | ||
| 1085 | }); | ||
| 1086 | |||
| 1087 | # Append a single column to the treeview | ||
| 1088 | my $treeViewColumn = Gtk3::TreeViewColumn->new_with_attributes( | ||
| 1089 | 'Pre-configured and played worlds', | ||
| 1090 | Gtk3::CellRendererText->new, | ||
| 1091 | markup => 0, | ||
| 1092 | ); | ||
| 1093 | |||
| 1094 | $treeView->append_column($treeViewColumn); | ||
| 1095 | |||
| 1096 | # Make the treeview scrollable | ||
| 1097 | my $frame2 = Gtk3::Frame->new(undef); | ||
| 1098 | $vBox->pack_start($frame2, TRUE, TRUE, 0); | ||
| 1099 | $frame2->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 1100 | |||
| 1101 | my $scroller = Gtk3::ScrolledWindow->new(); | ||
| 1102 | $frame2->add($scroller); | ||
| 1103 | $scroller->add($treeView); | ||
| 1104 | $scroller->set_policy(qw/automatic automatic/); | ||
| 1105 | |||
| 1106 | # Respond to clicks on the treeview | ||
| 1107 | $treeView->get_selection->set_mode('browse'); | ||
| 1108 | |||
| 1109 | # Add a grid on the right of the window, inside a scroller | ||
| 1110 | my $frame3 = Gtk3::Frame->new(undef); | ||
| 1111 | $hPaned->add2($frame3); | ||
| 1112 | $frame3->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 1113 | |||
| 1114 | my $scroller2 = Gtk3::ScrolledWindow->new(); | ||
| 1115 | $frame3->add($scroller2); | ||
| 1116 | $scroller2->set_policy(qw/automatic automatic/); | ||
| 1117 | $scroller2->set_border_width($self->spacingPixels); | ||
| 1118 | |||
| 1119 | my $grid = Gtk3::Grid->new(); | ||
| 1120 | $scroller2->add_with_viewport($grid); | ||
| 1121 | $grid->set_column_spacing($self->spacingPixels); | ||
| 1122 | $grid->set_row_spacing($self->spacingPixels); | ||
| 1123 | |||
| 1124 | # Store the widgets as IVs | ||
| 1125 | $self->ivPoke('packingBox', $packingBox); | ||
| 1126 | $self->ivPoke('hPaned', $hPaned); | ||
| 1127 | $self->ivPoke('vBox', $vBox); | ||
| 1128 | $self->ivPoke('frame', $frame); | ||
| 1129 | $self->ivPoke('image', $image); | ||
| 1130 | $self->ivPoke('hBox', $hBox); | ||
| 1131 | $self->ivPoke('objModel', $objModel); | ||
| 1132 | $self->ivPoke('treeView', $treeView); | ||
| 1133 | $self->ivPoke('treeViewColumn', $treeViewColumn); | ||
| 1134 | $self->ivPoke('frame2', $frame2); | ||
| 1135 | $self->ivPoke('scroller', $scroller); | ||
| 1136 | $self->ivPoke('frame3', $frame3); | ||
| 1137 | $self->ivPoke('scroller2', $scroller2); | ||
| 1138 | $self->ivPoke('grid', $grid); | ||
| 1139 | |||
| 1140 | # Add buttons to the button strip | ||
| 1141 | $self->createStripButtons(); | ||
| 1142 | # Add various widgets to the Gtk3::Grid | ||
| 1143 | $self->createGridWidgets(); | ||
| 1144 | |||
| 1145 | return 1; | ||
| 1146 | } | ||
| 1147 | |||
| 1148 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 1149 | |||
| 1150 | # ->signal_connects | ||
| 1151 | |||
| 1152 | # Other functions | ||
| 1153 | |||
| 1154 | sub createStripButtons { | ||
| 1155 | |||
| 1156 | # Called by $self->drawWidgets | ||
| 1157 | # Draws widgets in the button strip on the left of the window | ||
| 1158 | # | ||
| 1159 | # Expected arguments | ||
| 1160 | # (none besides $self) | ||
| 1161 | # | ||
| 1162 | # Return values | ||
| 1163 | # 'undef' on improper arguments | ||
| 1164 | # 1 otherwise | ||
| 1165 | |||
| 1166 | my ($self, $check) = @_; | ||
| 1167 | |||
| 1168 | # Local variables | ||
| 1169 | my ( | ||
| 1170 | $allString, | ||
| 1171 | @comboList, | ||
| 1172 | %hash, | ||
| 1173 | ); | ||
| 1174 | |||
| 1175 | # Check for improper arguments | ||
| 1176 | if (defined $check) { | ||
| 1177 | |||
| 1178 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createStripButtons', @_); | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | # Compile a list of languages used by all basic world objects. Put 'English' at the top | ||
| 1182 | # because most basic worlds use it | ||
| 1183 | foreach my $basicObj ($axmud::CLIENT->ivValues('constBasicWorldHash')) { | ||
| 1184 | |||
| 1185 | if ($basicObj->language && $basicObj->language ne 'English') { | ||
| 1186 | |||
| 1187 | $hash{$basicObj->language} = undef; | ||
| 1188 | } | ||
| 1189 | } | ||
| 1190 | |||
| 1191 | @comboList = sort {lc($a) cmp lc($b)} (keys %hash); | ||
| 1192 | unshift (@comboList, 'English'); | ||
| 1193 | |||
| 1194 | $allString = '<all languages>'; | ||
| 1195 | unshift (@comboList, $allString); | ||
| 1196 | |||
| 1197 | # Add widgets | ||
| 1198 | my $button = Gtk3::RadioToolButton->new(undef); | ||
| 1199 | $self->hBox->pack_start($button, FALSE, FALSE, 0); | ||
| 1200 | $button->set_active(TRUE); | ||
| 1201 | $button->set_icon_widget( | ||
| 1202 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_config.png') | ||
| 1203 | ); | ||
| 1204 | $button->set_label('PC'); | ||
| 1205 | $button->set_tooltip_text('Pre-configured and played worlds'); | ||
| 1206 | $button->signal_connect('toggled' => sub { | ||
| 1207 | |||
| 1208 | if ($button->get_active()) { | ||
| 1209 | |||
| 1210 | $self->resetTreeView(); | ||
| 1211 | } | ||
| 1212 | }); | ||
| 1213 | |||
| 1214 | my $button2 = Gtk3::RadioToolButton->new_from_widget($button); | ||
| 1215 | $self->hBox->pack_start($button2, FALSE, FALSE, 0); | ||
| 1216 | $button2->set_icon_widget( | ||
| 1217 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_other.png') | ||
| 1218 | ); | ||
| 1219 | $button2->set_label('Other'); | ||
| 1220 | $button2->set_tooltip_text('Other worlds'); | ||
| 1221 | $button2->signal_connect('toggled' => sub { | ||
| 1222 | |||
| 1223 | if ($button2->get_active()) { | ||
| 1224 | |||
| 1225 | $self->resetTreeView(); | ||
| 1226 | } | ||
| 1227 | }); | ||
| 1228 | |||
| 1229 | my $separator = Gtk3::Separator->new('vertical'); | ||
| 1230 | $self->hBox->pack_start($separator, TRUE, FALSE, 0); | ||
| 1231 | |||
| 1232 | my $button3 = Gtk3::RadioToolButton->new(undef); | ||
| 1233 | $self->hBox->pack_start($button3, FALSE, FALSE, 0); | ||
| 1234 | $button3->set_icon_widget( | ||
| 1235 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_sort_a.png') | ||
| 1236 | ); | ||
| 1237 | $button3->set_active(TRUE); | ||
| 1238 | $button3->set_label('az'); | ||
| 1239 | $button3->set_tooltip_text('Sort A-Z'); | ||
| 1240 | $button3->signal_connect('toggled' => sub { | ||
| 1241 | |||
| 1242 | if ($button3->get_active()) { | ||
| 1243 | |||
| 1244 | $self->resetTreeView(); | ||
| 1245 | } | ||
| 1246 | }); | ||
| 1247 | |||
| 1248 | my $button4 = Gtk3::RadioToolButton->new_from_widget($button3); | ||
| 1249 | $self->hBox->pack_start($button4, FALSE, FALSE, 0); | ||
| 1250 | $button4->set_icon_widget( | ||
| 1251 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_sort_z.png') | ||
| 1252 | ); | ||
| 1253 | $button4->set_label('za'); | ||
| 1254 | $button4->set_tooltip_text('Sort Z-A'); | ||
| 1255 | $button4->signal_connect('toggled' => sub { | ||
| 1256 | |||
| 1257 | if ($button4->get_active()) { | ||
| 1258 | |||
| 1259 | $self->resetTreeView(); | ||
| 1260 | } | ||
| 1261 | }); | ||
| 1262 | |||
| 1263 | my $button5 = Gtk3::RadioToolButton->new_from_widget($button4); | ||
| 1264 | $self->hBox->pack_start($button5, FALSE, FALSE, 0); | ||
| 1265 | $button5->set_icon_widget( | ||
| 1266 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_sort_random.png') | ||
| 1267 | ); | ||
| 1268 | $button5->set_label('rnd'); | ||
| 1269 | $button5->set_tooltip_text('Sort randomly'); | ||
| 1270 | $button5->signal_connect('toggled' => sub { | ||
| 1271 | |||
| 1272 | if ($button5->get_active()) { | ||
| 1273 | |||
| 1274 | $self->resetTreeView(); | ||
| 1275 | } | ||
| 1276 | }); | ||
| 1277 | # (Allow multiple re-clicking of the random button) | ||
| 1278 | $button5->signal_connect('clicked' => sub { | ||
| 1279 | |||
| 1280 | if ($button5->get_active()) { | ||
| 1281 | |||
| 1282 | $self->resetTreeView(); | ||
| 1283 | } | ||
| 1284 | }); | ||
| 1285 | |||
| 1286 | my $separator2 = Gtk3::Separator->new('vertical'); | ||
| 1287 | $self->hBox->pack_start($separator2, TRUE, FALSE, 0); | ||
| 1288 | |||
| 1289 | my $button6 = Gtk3::Button->new(); | ||
| 1290 | $self->hBox->pack_start($button6, FALSE, FALSE, 0); | ||
| 1291 | $button6->set_image( | ||
| 1292 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_search.png') | ||
| 1293 | ); | ||
| 1294 | $button6->set_tooltip_text('Search worlds'); | ||
| 1295 | $button6->signal_connect('clicked' => sub { | ||
| 1296 | |||
| 1297 | # Open a dialogue window | ||
| 1298 | my ($regex, $language) = $self->showEntryComboDialogue( | ||
| 1299 | 'Search worlds', | ||
| 1300 | 'Enter a search pattern', | ||
| 1301 | 'Search by language', | ||
| 1302 | \@comboList, | ||
| 1303 | undef, # No maximum characters | ||
| 1304 | undef, # Don't reverse widget order | ||
| 1305 | TRUE, # Close the window early if user presses ENTER key | ||
| 1306 | ); | ||
| 1307 | |||
| 1308 | if (! defined $regex) { | ||
| 1309 | |||
| 1310 | # Cancel search terms | ||
| 1311 | $self->ivUndef('searchRegex'); | ||
| 1312 | $self->ivUndef('searchLanguage'); | ||
| 1313 | |||
| 1314 | } else { | ||
| 1315 | |||
| 1316 | # Apply search terms | ||
| 1317 | if ($regex eq '') { | ||
| 1318 | $self->ivUndef('searchRegex'); | ||
| 1319 | } else { | ||
| 1320 | $self->ivPoke('searchRegex', $regex); | ||
| 1321 | } | ||
| 1322 | |||
| 1323 | if ($language eq $allString) { | ||
| 1324 | $self->ivUndef('searchLanguage'); | ||
| 1325 | } else { | ||
| 1326 | $self->ivPoke('searchLanguage', $language); | ||
| 1327 | } | ||
| 1328 | } | ||
| 1329 | |||
| 1330 | # Update the treeview | ||
| 1331 | $self->resetTreeView(); | ||
| 1332 | |||
| 1333 | # Update the button icon | ||
| 1334 | if (! defined $self->searchRegex && ! defined $self->searchLanguage) { | ||
| 1335 | |||
| 1336 | $button6->set_image( | ||
| 1337 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_search.png') | ||
| 1338 | ); | ||
| 1339 | |||
| 1340 | } else { | ||
| 1341 | |||
| 1342 | $button6->set_image( | ||
| 1343 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_apply.png') | ||
| 1344 | ); | ||
| 1345 | } | ||
| 1346 | }); | ||
| 1347 | |||
| 1348 | my $button7 = Gtk3::Button->new(); | ||
| 1349 | $self->hBox->pack_start($button7, FALSE, FALSE, 0); | ||
| 1350 | $button7->set_image( | ||
| 1351 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_clear.png') | ||
| 1352 | ); | ||
| 1353 | $button7->set_tooltip_text('Cancel search'); | ||
| 1354 | $button7->signal_connect('clicked' => sub { | ||
| 1355 | |||
| 1356 | # Cancel search terms | ||
| 1357 | $self->ivUndef('searchRegex'); | ||
| 1358 | $self->ivUndef('searchLanguage'); | ||
| 1359 | |||
| 1360 | # Update the treeview | ||
| 1361 | $self->resetTreeView(); | ||
| 1362 | |||
| 1363 | # Update the button icon | ||
| 1364 | $button6->set_image( | ||
| 1365 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_search.png') | ||
| 1366 | ); | ||
| 1367 | }); | ||
| 1368 | |||
| 1369 | my $button8 = Gtk3::Button->new(); | ||
| 1370 | $self->hBox->pack_start($button8, FALSE, FALSE, 0); | ||
| 1371 | |||
| 1372 | if (! $axmud::CLIENT->systemMsgList) { | ||
| 1373 | |||
| 1374 | $button8->set_image( | ||
| 1375 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_console.png') | ||
| 1376 | ); | ||
| 1377 | |||
| 1378 | } else { | ||
| 1379 | |||
| 1380 | $button8->set_image( | ||
| 1381 | Gtk3::Image->new_from_file( | ||
| 1382 | $axmud::SHARE_DIR . '/icons/connect/icon_console_alert.png', | ||
| 1383 | ) | ||
| 1384 | ); | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | $button8->set_tooltip_text('Show Client Console window'); | ||
| 1388 | $button8->signal_connect('clicked' => sub { | ||
| 1389 | |||
| 1390 | # Open an Client Console window | ||
| 1391 | $self->createFreeWin( | ||
| 1392 | 'Games::Axmud::OtherWin::ClientConsole', | ||
| 1393 | $self, | ||
| 1394 | undef, # No GA::Session | ||
| 1395 | undef, # Let the window set its own title | ||
| 1396 | ); | ||
| 1397 | }); | ||
| 1398 | |||
| 1399 | # Store the widgets as IVs | ||
| 1400 | $self->ivPoke('preConfigButton', $button); | ||
| 1401 | $self->ivPoke('otherWorldButton', $button2); | ||
| 1402 | $self->ivPoke('sortAzButton', $button3); | ||
| 1403 | $self->ivPoke('sortZaButton', $button4); | ||
| 1404 | $self->ivPoke('sortRandButton', $button5); | ||
| 1405 | $self->ivPoke('searchButton', $button6); | ||
| 1406 | $self->ivPoke('cancelSearchButton', $button7); | ||
| 1407 | $self->ivPoke('consoleButton', $button8); | ||
| 1408 | |||
| 1409 | return 1; | ||
| 1410 | } | ||
| 1411 | |||
| 1412 | sub createGridWidgets { | ||
| 1413 | |||
| 1414 | # Called by $self->drawWidgets | ||
| 1415 | # Draws widgets in the grid on the right of the window | ||
| 1416 | # | ||
| 1417 | # Expected arguments | ||
| 1418 | # (none besides $self) | ||
| 1419 | # | ||
| 1420 | # Return values | ||
| 1421 | # 'undef' on improper arguments | ||
| 1422 | # 1 otherwise | ||
| 1423 | |||
| 1424 | my ($self, $check) = @_; | ||
| 1425 | |||
| 1426 | # Check for improper arguments | ||
| 1427 | if (defined $check) { | ||
| 1428 | |||
| 1429 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createGridWidgets', @_); | ||
| 1430 | } | ||
| 1431 | |||
| 1432 | $self->addLabel($self->grid, '<i><u>Connection settings</u></i>', | ||
| 1433 | 1, 8, 1, 2); | ||
| 1434 | if (@axmud::TEST_MODE_LOGIN_LIST) { | ||
| 1435 | |||
| 1436 | # Button used for Axmud development, and only visible if the user has edited the | ||
| 1437 | # contents of /scripts/axmud.pl or /scripts/baxmud.pl, in order to modify the global | ||
| 1438 | # variable @TEST_MODE_LOGIN_LIST | ||
| 1439 | my $testButton = $self->addButton( | ||
| 1440 | $self->grid, | ||
| 1441 | \&testModeCallback, | ||
| 1442 | 'TEST MODE SETUP', | ||
| 1443 | 'Use @TEST_MODE_LOGIN_LIST values', | ||
| 1444 | 8, 12, 1, 2); | ||
| 1445 | } | ||
| 1446 | |||
| 1447 | # GA::Profile::World ->name | ||
| 1448 | $self->addLabel($self->grid, 'Name', | ||
| 1449 | 1, 4, 2, 3); | ||
| 1450 | |||
| 1451 | my $entry = $self->addEntry($self->grid, undef, undef, TRUE, | ||
| 1452 | 4, 12, 2, 3); | ||
| 1453 | $entry->signal_connect('changed' => sub { | ||
| 1454 | |||
| 1455 | # If the text inside the entry changes, we record that fact by creating (or replacing) a | ||
| 1456 | # key-value pair in $self->miniWorldObj. If the entry is emptied, we record that by | ||
| 1457 | # removing the key-value pair. | ||
| 1458 | # However, when $self->resetGridWidgets and ->updateGridWidgets are changing all the | ||
| 1459 | # grid widgets (after the user selects a world from the treeview), $self->updateFlag | ||
| 1460 | # is set to TRUE, and we don't make any changes to the mini-world object | ||
| 1461 | if (! $self->updateFlag) { | ||
| 1462 | |||
| 1463 | my $text = $axmud::CLIENT->trimWhitespace($entry->get_text()); | ||
| 1464 | |||
| 1465 | if ($text ne '') { | ||
| 1466 | $self->miniWorldObj->ivAdd('propHash', 'name', $text); | ||
| 1467 | } else { | ||
| 1468 | $self->miniWorldObj->ivDelete('propHash', 'name'); | ||
| 1469 | } | ||
| 1470 | } | ||
| 1471 | }); | ||
| 1472 | $entry->set_tooltip_text( | ||
| 1473 | 'World profile name: maximum 16 characters; A-Z, a-z, 0-9 and underlines (not first' | ||
| 1474 | . ' character); must not be ' . $axmud::NAME_ARTICLE . ' reserved word', | ||
| 1475 | ); | ||
| 1476 | |||
| 1477 | # ->dns, ->ipv4 or ->ipv6 | ||
| 1478 | $self->addLabel($self->grid, 'Host', | ||
| 1479 | 1, 4, 3, 4); | ||
| 1480 | my $entry2 = $self->addEntry($self->grid, undef, undef, TRUE, | ||
| 1481 | 4, 12, 3, 4); | ||
| 1482 | $entry2->signal_connect('changed' => sub { | ||
| 1483 | |||
| 1484 | if (! $self->updateFlag) { | ||
| 1485 | |||
| 1486 | my $text = $axmud::CLIENT->trimWhitespace($entry2->get_text()); | ||
| 1487 | |||
| 1488 | if ($text ne '') { | ||
| 1489 | |||
| 1490 | $self->miniWorldObj->ivAdd('propHash', 'host', $text); | ||
| 1491 | $self->addCharButton->set_sensitive(TRUE); | ||
| 1492 | $self->offlineButton->set_sensitive(TRUE); | ||
| 1493 | $self->connectButton->set_sensitive(TRUE); | ||
| 1494 | |||
| 1495 | } else { | ||
| 1496 | |||
| 1497 | $self->miniWorldObj->ivDelete('propHash', 'host'); | ||
| 1498 | $self->addCharButton->set_sensitive(FALSE); | ||
| 1499 | $self->offlineButton->set_sensitive(FALSE); | ||
| 1500 | $self->connectButton->set_sensitive(FALSE); | ||
| 1501 | } | ||
| 1502 | } | ||
| 1503 | }); | ||
| 1504 | $entry2->set_tooltip_text('e.g. \'deathmud.com\'; using IPV4, IPV6 or DNS'); | ||
| 1505 | |||
| 1506 | # ->port | ||
| 1507 | $self->addLabel($self->grid, 'Port', | ||
| 1508 | 1, 4, 4, 5); | ||
| 1509 | my $entry3 = $self->addEntry($self->grid, undef, undef, TRUE, | ||
| 1510 | 4, 6, 4, 5, 5, 5); | ||
| 1511 | $entry3->set_tooltip_text('e.g. 5000'); | ||
| 1512 | $entry3->signal_connect('changed' => sub { | ||
| 1513 | |||
| 1514 | if (! $self->updateFlag) { | ||
| 1515 | |||
| 1516 | my $text = $axmud::CLIENT->trimWhitespace($entry3->get_text()); | ||
| 1517 | |||
| 1518 | if ($text ne '') { | ||
| 1519 | $self->miniWorldObj->ivAdd('propHash', 'port', $text); | ||
| 1520 | } else { | ||
| 1521 | $self->miniWorldObj->ivDelete('propHash', 'port'); | ||
| 1522 | } | ||
| 1523 | } | ||
| 1524 | }); | ||
| 1525 | |||
| 1526 | $self->addLabel($self->grid, 'Protocol', | ||
| 1527 | 1, 4, 5, 6); | ||
| 1528 | my ($group, $radioButton) = $self->addRadioButton( | ||
| 1529 | $self->grid, undef, undef, 'Default', TRUE, TRUE, | ||
| 1530 | 4, 6, 5, 6); | ||
| 1531 | |||
| 1532 | my ($group2, $radioButton2) = $self->addRadioButton( | ||
| 1533 | $self->grid, undef, $group, 'Telnet', FALSE, TRUE, | ||
| 1534 | 6, 7, 5, 6); | ||
| 1535 | |||
| 1536 | my ($group3, $radioButton3) = $self->addRadioButton( | ||
| 1537 | $self->grid, undef, $group2, 'SSH', FALSE, TRUE, | ||
| 1538 | 7, 8, 5, 6); | ||
| 1539 | |||
| 1540 | my ($group4, $radioButton4) = $self->addRadioButton( | ||
| 1541 | $self->grid, undef, $group3, 'SSL', FALSE, TRUE, | ||
| 1542 | 8, 12, 5, 6); | ||
| 1543 | # If SSL is disabled, don't allow that button to be selected | ||
| 1544 | if ($axmud::NO_SSL_FLAG) { | ||
| 1545 | |||
| 1546 | $radioButton4->set_sensitive(FALSE); | ||
| 1547 | $radioButton4->set_label('(SSL unavailable)'); | ||
| 1548 | } | ||
| 1549 | |||
| 1550 | # ->passwordHash, ->accountHash, ->lastConnectChar, ->loginMode (etc) | ||
| 1551 | $self->addLabel($self->grid, '<i><u>Optional settings</u></i>', | ||
| 1552 | 1, 8, 6, 7); | ||
| 1553 | |||
| 1554 | $self->addLabel($self->grid, 'Character', | ||
| 1555 | 1, 4, 7, 8); | ||
| 1556 | my $comboBox = $self->resetComboBox(); | ||
| 1557 | |||
| 1558 | my $checkButton = $self->addCheckButton( | ||
| 1559 | $self->grid, 'No auto-login', undef, FALSE, TRUE, | ||
| 1560 | 8, 12, 7, 8); | ||
| 1561 | $checkButton->signal_connect('toggled' => sub { | ||
| 1562 | |||
| 1563 | if (! $self->updateFlag) { | ||
| 1564 | |||
| 1565 | # (The state of the checkbutton isn't stored as an IV in a world profile, so the | ||
| 1566 | # mini-world object has a separate IV to store it) | ||
| 1567 | $self->miniWorldObj->ivPoke('noAutoLoginFlag', $checkButton->get_active()); | ||
| 1568 | } | ||
| 1569 | }); | ||
| 1570 | |||
| 1571 | my $addCharButton = $self->addButton( | ||
| 1572 | $self->grid, | ||
| 1573 | \&addCharCallback, | ||
| 1574 | 'Add', | ||
| 1575 | 'Add a new character profile', | ||
| 1576 | 4, 6, 8, 9); | ||
| 1577 | |||
| 1578 | my $editPwdButton = $self->addButton( | ||
| 1579 | $self->grid, | ||
| 1580 | \&editPasswordCallback, | ||
| 1581 | 'Set password', | ||
| 1582 | 'Edit the selected character\'s password', | ||
| 1583 | 6, 8, 8, 9); | ||
| 1584 | |||
| 1585 | my $editAccButton = $self->addButton( | ||
| 1586 | $self->grid, | ||
| 1587 | \&editAccountCallback, | ||
| 1588 | 'Set account name', | ||
| 1589 | 'Edit the selected character\'s associated account name', | ||
| 1590 | 8, 12, 8, 9); | ||
| 1591 | |||
| 1592 | $self->addLabel($self->grid, '<i><u>World information</u></i>', | ||
| 1593 | 1, 8, 9, 10); | ||
| 1594 | |||
| 1595 | my $websiteLabel = $self->addLabel($self->grid, $self->noWebsiteString, | ||
| 1596 | 1, 12, 10, 11); | ||
| 1597 | $websiteLabel->signal_connect('activate-link' => sub { | ||
| 1598 | |||
| 1599 | my $link = $websiteLabel->get_current_uri(); | ||
| 1600 | if ($link) { | ||
| 1601 | |||
| 1602 | $axmud::CLIENT->openURL($link); | ||
| 1603 | } | ||
| 1604 | }); | ||
| 1605 | |||
| 1606 | my $connectionLabel = $self->addLabel($self->grid, $self->noConnectString, | ||
| 1607 | 1, 12, 11, 12); | ||
| 1608 | |||
| 1609 | # ->worldDescrip | ||
| 1610 | my $descripTextView = $self->addTextView( | ||
| 1611 | $self->grid, | ||
| 1612 | undef, | ||
| 1613 | undef, | ||
| 1614 | undef, | ||
| 1615 | FALSE, | ||
| 1616 | 1, 12, 12, 13); | ||
| 1617 | $descripTextView->set_vexpand(TRUE); | ||
| 1618 | my $descripBuffer = $descripTextView->get_buffer(); | ||
| 1619 | # Don't want horizontal scrolling | ||
| 1620 | $descripTextView->set_wrap_mode('word-char'); | ||
| 1621 | |||
| 1622 | my $createWorldButton = $self->addButton( | ||
| 1623 | $self->grid, | ||
| 1624 | undef, | ||
| 1625 | 'Create world', | ||
| 1626 | 'Create a world profile', | ||
| 1627 | 1, 7, 13, 14); | ||
| 1628 | $createWorldButton->signal_connect('clicked' => sub { | ||
| 1629 | |||
| 1630 | if (! $self->worldObj || $self->otherWorldButton->get_active()) { | ||
| 1631 | $self->createWorldCallback(); | ||
| 1632 | } else { | ||
| 1633 | $self->applyChangesCallback(); | ||
| 1634 | } | ||
| 1635 | }); | ||
| 1636 | |||
| 1637 | my $resetWorldButton = $self->addButton( | ||
| 1638 | $self->grid, | ||
| 1639 | \&resetWorldCallback, | ||
| 1640 | 'Reset world', | ||
| 1641 | "Reset the values displayed in this window to those\nactually stored by the selected" | ||
| 1642 | . " world profile", | ||
| 1643 | 1, 7, 14, 15); | ||
| 1644 | |||
| 1645 | my $offlineButton = $self->addButton( | ||
| 1646 | $self->grid, | ||
| 1647 | undef, | ||
| 1648 | 'Connect offline', | ||
| 1649 | 'Connect to this world in \'offline\' mode', | ||
| 1650 | 7, 12, 13, 14); | ||
| 1651 | $offlineButton->signal_connect('clicked' => sub { | ||
| 1652 | |||
| 1653 | $self->connectWorldCallback(TRUE); | ||
| 1654 | }); | ||
| 1655 | |||
| 1656 | my $connectButton = $self->addButton( | ||
| 1657 | $self->grid, | ||
| 1658 | undef, | ||
| 1659 | 'Connect', | ||
| 1660 | 'Connect to this world', | ||
| 1661 | 7, 12, 14, 15); | ||
| 1662 | # (Add a bit of padding, so the Connect button isn't much smaller than the other three) | ||
| 1663 | $connectButton->get_child->set_width_chars(10); | ||
| 1664 | $connectButton->signal_connect('clicked' => sub { | ||
| 1665 | |||
| 1666 | $self->connectWorldCallback(FALSE); | ||
| 1667 | }); | ||
| 1668 | |||
| 1669 | # Store the widgets as IVs | ||
| 1670 | $self->ivPoke('entry', $entry); | ||
| 1671 | $self->ivPoke('entry2', $entry2); | ||
| 1672 | $self->ivPoke('entry3', $entry3); | ||
| 1673 | $self->ivPoke('radioButton', $radioButton); | ||
| 1674 | $self->ivPoke('radioButton2', $radioButton2); | ||
| 1675 | $self->ivPoke('radioButton3', $radioButton3); | ||
| 1676 | $self->ivPoke('radioButton4', $radioButton4); | ||
| 1677 | $self->ivPoke('checkButton', $checkButton); | ||
| 1678 | $self->ivPoke('comboBox', $comboBox); | ||
| 1679 | $self->ivPoke('addCharButton', $addCharButton); | ||
| 1680 | $self->ivPoke('editPwdButton', $editPwdButton); | ||
| 1681 | $self->ivPoke('editAccButton', $editAccButton); | ||
| 1682 | $self->ivPoke('websiteLabel', $websiteLabel); | ||
| 1683 | $self->ivPoke('connectionLabel', $connectionLabel); | ||
| 1684 | $self->ivPoke('descripTextView', $descripTextView); | ||
| 1685 | $self->ivPoke('descripBuffer', $descripBuffer); | ||
| 1686 | $self->ivPoke('createWorldButton', $createWorldButton); | ||
| 1687 | $self->ivPoke('resetWorldButton', $resetWorldButton); | ||
| 1688 | $self->ivPoke('offlineButton', $offlineButton); | ||
| 1689 | $self->ivPoke('connectButton', $connectButton); | ||
| 1690 | |||
| 1691 | return 1; | ||
| 1692 | } | ||
| 1693 | |||
| 1694 | sub resetTreeView { | ||
| 1695 | |||
| 1696 | # Called by $self->winEnable, ->createWorldCallback, ->applyChangesCallback and | ||
| 1697 | # ->resetWorldCallback | ||
| 1698 | # Fills the object tree on the left of the window | ||
| 1699 | # | ||
| 1700 | # Expected arguments | ||
| 1701 | # (none besides $self) | ||
| 1702 | # | ||
| 1703 | # Optional arguments | ||
| 1704 | # $treeView - The GTK::TreeView object just created (if 'undef', $self->treeView is | ||
| 1705 | # used) | ||
| 1706 | # $selectWorld - The world to select (if 'undef', this function chooses which world to | ||
| 1707 | # select). Only applied when the list of pre-configured worlds is | ||
| 1708 | # displayed | ||
| 1709 | # | ||
| 1710 | # Return values | ||
| 1711 | # 'undef' on improper arguments | ||
| 1712 | # 1 otherwise | ||
| 1713 | |||
| 1714 | my ($self, $treeView, $selectWorld, $check) = @_; | ||
| 1715 | |||
| 1716 | # Local variables | ||
| 1717 | my ( | ||
| 1718 | $displayFlag, $sortMode, $regex, $model, $matchPointer, $treeSelection, | ||
| 1719 | @faveList, @otherList, @objList, @initList, @displayList, | ||
| 1720 | %worldHash, %nameHash, %checkHash, %displayHash, %miniWorldHash, | ||
| 1721 | ); | ||
| 1722 | |||
| 1723 | # Check for improper arguments | ||
| 1724 | if (defined $check) { | ||
| 1725 | |||
| 1726 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTreeView', @_); | ||
| 1727 | } | ||
| 1728 | |||
| 1729 | # Set the Gtk3::TreeView, if not specified | ||
| 1730 | if (! $treeView) { | ||
| 1731 | |||
| 1732 | $treeView = $self->treeView; | ||
| 1733 | } | ||
| 1734 | |||
| 1735 | # Decide which list should be displayed. Default display mode is 'undef', representing | ||
| 1736 | # a list of world profiles | ||
| 1737 | if ($self->otherWorldButton->get_active()) { | ||
| 1738 | |||
| 1739 | $displayFlag = TRUE; | ||
| 1740 | } | ||
| 1741 | |||
| 1742 | # Update the treeview's title | ||
| 1743 | if (! $displayFlag) { | ||
| 1744 | $self->treeViewColumn->set_title('Pre-configured and played worlds'); | ||
| 1745 | } else { | ||
| 1746 | $self->treeViewColumn->set_title('Other worlds'); | ||
| 1747 | } | ||
| 1748 | |||
| 1749 | # Decide how the worlds should be sorted | ||
| 1750 | if ($self->sortZaButton->get_active()) { | ||
| 1751 | $sortMode = 'za'; | ||
| 1752 | } elsif ($self->sortRandButton->get_active()) { | ||
| 1753 | $sortMode = 'rand'; | ||
| 1754 | } else { | ||
| 1755 | $sortMode = 'az'; | ||
| 1756 | } | ||
| 1757 | |||
| 1758 | if (! $displayFlag) { | ||
| 1759 | |||
| 1760 | # Display list of world profiles | ||
| 1761 | |||
| 1762 | # Import the hash of world profiles. If search terms have been applied, remove any | ||
| 1763 | # worlds that don't match | ||
| 1764 | $regex = $self->searchRegex; | ||
| 1765 | foreach my $worldObj ($axmud::CLIENT->ivValues('worldProfHash')) { | ||
| 1766 | |||
| 1767 | my ($dictObj, $language); | ||
| 1768 | |||
| 1769 | if ($worldObj->dict) { | ||
| 1770 | |||
| 1771 | $dictObj = $axmud::CLIENT->ivShow('dictHash', $worldObj->dict); | ||
| 1772 | if ($dictObj) { | ||
| 1773 | |||
| 1774 | $language = $dictObj->language; | ||
| 1775 | } | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | if ( | ||
| 1779 | ( | ||
| 1780 | ! defined $regex | ||
| 1781 | || $worldObj->name =~ m/$regex/i | ||
| 1782 | || (defined $worldObj->longName && $worldObj->longName =~ m/$regex/i) | ||
| 1783 | ) && ( | ||
| 1784 | ! defined $self->searchLanguage | ||
| 1785 | || ($language && (lc($language) eq lc($self->searchLanguage))) | ||
| 1786 | ) | ||
| 1787 | ) { | ||
| 1788 | $worldHash{$worldObj->name} = $worldObj; | ||
| 1789 | } | ||
| 1790 | } | ||
| 1791 | |||
| 1792 | # For each world, decide which name to use. Create a hash in the form | ||
| 1793 | # $nameHash{profile_name} = displayed_name | ||
| 1794 | # (where 'displayed_name' is the long name, if available, or the profile name, if not) | ||
| 1795 | # At the same time, create a parallel hash to check for duplicate long names, in the | ||
| 1796 | # form | ||
| 1797 | # $checkHash{long_name} = profile_name | ||
| 1798 | # If duplicate long names are found, 'displayed_name' should include both the long name | ||
| 1799 | # and the profile name | ||
| 1800 | foreach my $worldObj (values %worldHash) { | ||
| 1801 | |||
| 1802 | my ($otherWorld, $otherWorldObj); | ||
| 1803 | |||
| 1804 | if ($worldObj->longName) { | ||
| 1805 | |||
| 1806 | if ($worldObj->longName eq $self->newWorldString) { | ||
| 1807 | |||
| 1808 | $nameHash{$worldObj->name} | ||
| 1809 | = $worldObj->longName . ' (' . $worldObj->name . ')'; | ||
| 1810 | $checkHash{$worldObj->longName} = $worldObj->name; | ||
| 1811 | |||
| 1812 | } elsif (exists $checkHash{$worldObj->longName}) { | ||
| 1813 | |||
| 1814 | # Amend both entries to include the long name and the profile name | ||
| 1815 | $otherWorld = $checkHash{$worldObj->longName}; | ||
| 1816 | $otherWorldObj = $worldHash{$otherWorld}; | ||
| 1817 | |||
| 1818 | $nameHash{$worldObj->name} | ||
| 1819 | = $worldObj->longName . ' (' . $worldObj->name . ')'; | ||
| 1820 | # (There's already an entry in $checkHash matching ->longName) | ||
| 1821 | $nameHash{$otherWorld} | ||
| 1822 | = $otherWorldObj->longName . ' (' . $otherWorldObj->name . ')'; | ||
| 1823 | |||
| 1824 | } else { | ||
| 1825 | |||
| 1826 | # Not a duplicate, so just display the long name | ||
| 1827 | $nameHash{$worldObj->name} = $worldObj->longName; | ||
| 1828 | $checkHash{$worldObj->longName} = $worldObj->name; | ||
| 1829 | } | ||
| 1830 | |||
| 1831 | } else { | ||
| 1832 | |||
| 1833 | # Just display the profile name | ||
| 1834 | $nameHash{$worldObj->name} = $worldObj->name; | ||
| 1835 | } | ||
| 1836 | } | ||
| 1837 | |||
| 1838 | # Remove all favourite worlds from %worldHash, so they can be displayed first | ||
| 1839 | foreach my $name ($axmud::CLIENT->favouriteWorldList) { | ||
| 1840 | |||
| 1841 | if (exists $worldHash{$name}) { | ||
| 1842 | |||
| 1843 | push (@faveList, $worldHash{$name}); | ||
| 1844 | delete $worldHash{$name}; | ||
| 1845 | |||
| 1846 | # If $selectWorld was not specified, the first world in the favourite world list | ||
| 1847 | # should be selected | ||
| 1848 | if (! $selectWorld) { | ||
| 1849 | |||
| 1850 | $selectWorld = $name; | ||
| 1851 | } | ||
| 1852 | } | ||
| 1853 | } | ||
| 1854 | |||
| 1855 | # Now sort the remaining world profiles by frequency of usage (and then, alphabetically | ||
| 1856 | # or randomly, depending on which radio buttons are active) | ||
| 1857 | @otherList = sort { | ||
| 1858 | |||
| 1859 | my $aName = lc($nameHash{$a->name}); | ||
| 1860 | my $bName = lc($nameHash{$b->name}); | ||
| 1861 | |||
| 1862 | # Sort, ignoring initial articles. Don't bother ignoring articles in languages other | ||
| 1863 | # than English, because the basic mudlist contains only a couple of items that | ||
| 1864 | # would be affected | ||
| 1865 | $aName =~ s/^(the|a)\s//; | ||
| 1866 | $bName =~ s/^(the|a)\s//; | ||
| 1867 | |||
| 1868 | if ($a->numberConnects > $b->numberConnects) { | ||
| 1869 | -1; | ||
| 1870 | } elsif ($b->numberConnects > $a->numberConnects) { | ||
| 1871 | 1; | ||
| 1872 | } elsif ($sortMode eq 'az') { | ||
| 1873 | $aName cmp $bName; | ||
| 1874 | } elsif ($sortMode eq 'za') { | ||
| 1875 | $bName cmp $aName; | ||
| 1876 | } elsif (int(rand(2))) { | ||
| 1877 | -1; | ||
| 1878 | } else { | ||
| 1879 | 1; | ||
| 1880 | } | ||
| 1881 | |||
| 1882 | } (values %worldHash); | ||
| 1883 | |||
| 1884 | # Combine the two lists, with favourite worlds first, followed by everything else | ||
| 1885 | @objList = (@faveList, @otherList); | ||
| 1886 | |||
| 1887 | # Worlds that have never been connected should be shown in italics | ||
| 1888 | foreach my $worldObj (@objList) { | ||
| 1889 | |||
| 1890 | my $displayName = $nameHash{$worldObj->name}; | ||
| 1891 | |||
| 1892 | if (! $worldObj->numberConnects) { | ||
| 1893 | |||
| 1894 | $displayName = "<i>" . $displayName . "</i>"; | ||
| 1895 | } | ||
| 1896 | |||
| 1897 | push (@displayList, $displayName); | ||
| 1898 | $displayHash{$displayName} = $worldObj; | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | } else { | ||
| 1902 | |||
| 1903 | # Display basic mudlist | ||
| 1904 | |||
| 1905 | # Display basic mudlist, sorted alphabetically or randomly, depending on which radio | ||
| 1906 | # buttons are active) | ||
| 1907 | @initList = sort { | ||
| 1908 | |||
| 1909 | my $aName = lc($a->longName); | ||
| 1910 | my $bName = lc($b->longName); | ||
| 1911 | |||
| 1912 | # Sort, ignoring initial articles. Don't bother ignoring articles in languages other | ||
| 1913 | # than English, because the basic mudlist contains only a couple of items that | ||
| 1914 | # would be affected | ||
| 1915 | $aName =~ s/^(the|a)\s//; | ||
| 1916 | $bName =~ s/^(the|a)\s//; | ||
| 1917 | |||
| 1918 | if ($sortMode eq 'az') { | ||
| 1919 | $aName cmp $bName; | ||
| 1920 | } elsif ($sortMode eq 'za') { | ||
| 1921 | $bName cmp $aName; | ||
| 1922 | } elsif (int(rand(2))) { | ||
| 1923 | -1; | ||
| 1924 | } else { | ||
| 1925 | 1; | ||
| 1926 | } | ||
| 1927 | |||
| 1928 | } ($axmud::CLIENT->ivValues('constBasicWorldHash')); | ||
| 1929 | |||
| 1930 | # Remove any worlds for which a world profile actually exists (the same world shouldn't | ||
| 1931 | # appear in both lists) | ||
| 1932 | # If any search terms have been applied, remove any worlds that don't match | ||
| 1933 | $regex = $self->searchRegex; | ||
| 1934 | foreach my $obj (@initList) { | ||
| 1935 | |||
| 1936 | if ( | ||
| 1937 | ( | ||
| 1938 | ! $axmud::CLIENT->ivExists('worldProfHash', $obj->name) | ||
| 1939 | ) && ( | ||
| 1940 | ! defined $regex | ||
| 1941 | || $obj->name =~ m/$regex/i | ||
| 1942 | || $obj->longName =~ m/$regex/i | ||
| 1943 | ) && ( | ||
| 1944 | ! defined $self->searchLanguage | ||
| 1945 | || lc($obj->language) eq lc($self->searchLanguage) | ||
| 1946 | ) | ||
| 1947 | ) { | ||
| 1948 | push (@objList, $obj); | ||
| 1949 | } | ||
| 1950 | } | ||
| 1951 | |||
| 1952 | # All worlds should be in italics | ||
| 1953 | foreach my $obj (@objList) { | ||
| 1954 | |||
| 1955 | my $displayName = "<i>" . $obj->longName . "</i>"; | ||
| 1956 | |||
| 1957 | push (@displayList, $displayName); | ||
| 1958 | $displayHash{$displayName} = $obj; | ||
| 1959 | } | ||
| 1960 | } | ||
| 1961 | |||
| 1962 | # The first item in the list should be a 'create new world' string | ||
| 1963 | unshift (@displayList, $self->newWorldString); | ||
| 1964 | $displayHash{$self->newWorldString} = undef; # Not linked to a world profile | ||
| 1965 | |||
| 1966 | # If the treeview already exists, stop it from calling $self->selectWorldCallback while | ||
| 1967 | # we're modifying its contents | ||
| 1968 | $self->ivPoke('updateFlag', TRUE); | ||
| 1969 | |||
| 1970 | # Fill a model of the tree, not the tree itself | ||
| 1971 | if (! $treeView) { | ||
| 1972 | $model = $self->treeView->get_model(); | ||
| 1973 | } else { | ||
| 1974 | $model = $treeView->get_model(); | ||
| 1975 | } | ||
| 1976 | |||
| 1977 | # Empty the treeview | ||
| 1978 | $model->clear(); | ||
| 1979 | |||
| 1980 | # Display each world in the treeview | ||
| 1981 | foreach my $displayName (@displayList) { | ||
| 1982 | |||
| 1983 | my ($pointer, $displayObj); | ||
| 1984 | |||
| 1985 | $pointer = $model->append(undef); | ||
| 1986 | $displayObj = $displayHash{$displayName}; | ||
| 1987 | |||
| 1988 | $model->set($pointer, [0], [$displayName]); | ||
| 1989 | |||
| 1990 | if ($selectWorld && $displayObj && $selectWorld eq $displayObj->name) { | ||
| 1991 | |||
| 1992 | # This line must be selected | ||
| 1993 | $matchPointer = $pointer; | ||
| 1994 | } | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | # For each world, create a GA::Obj::MiniWorld, which stores any changes made to the world's | ||
| 1998 | # data in the Connections window, so that they can be copied into the main world | ||
| 1999 | # profile at the right time | ||
| 2000 | # However, don't replace an existing GA::Obj::MiniWorld | ||
| 2001 | foreach my $obj (@objList) { | ||
| 2002 | |||
| 2003 | my ( | ||
| 2004 | $miniWorldObj, | ||
| 2005 | %passwordHash, | ||
| 2006 | %accountHash, | ||
| 2007 | ); | ||
| 2008 | |||
| 2009 | if ($self->ivExists('miniWorldHash', $obj->name)) { | ||
| 2010 | |||
| 2011 | # Use the existing mini-world object | ||
| 2012 | $miniWorldObj = $self->ivShow('miniWorldHash', $obj->name); | ||
| 2013 | |||
| 2014 | } elsif (! $displayFlag) { | ||
| 2015 | |||
| 2016 | # Create a new mini-world object corresponding to an existing world profile | ||
| 2017 | # The object requires a copy of the world profile's ->passwordHash and ->accountHash | ||
| 2018 | %passwordHash = $obj->passwordHash; | ||
| 2019 | %accountHash = $obj->accountHash; | ||
| 2020 | |||
| 2021 | # Create the object | ||
| 2022 | $miniWorldObj = Games::Axmud::Obj::MiniWorld->new( | ||
| 2023 | $obj, | ||
| 2024 | $obj->lastConnectChar, # May be 'undef' | ||
| 2025 | $obj->loginAccountMode, | ||
| 2026 | \%passwordHash, | ||
| 2027 | \%accountHash, | ||
| 2028 | ); | ||
| 2029 | |||
| 2030 | } else { | ||
| 2031 | |||
| 2032 | # Create a new mini-world object NOT corresponding to an existing world profile | ||
| 2033 | $miniWorldObj = Games::Axmud::Obj::MiniWorld->new($obj); | ||
| 2034 | } | ||
| 2035 | |||
| 2036 | if ($miniWorldObj) { | ||
| 2037 | |||
| 2038 | $miniWorldHash{$miniWorldObj->name} = $miniWorldObj; | ||
| 2039 | } | ||
| 2040 | } | ||
| 2041 | |||
| 2042 | # Store the hashes as IVs | ||
| 2043 | $self->ivPoke('worldHash', %displayHash); | ||
| 2044 | $self->ivPoke('miniWorldHash', %miniWorldHash); | ||
| 2045 | |||
| 2046 | # Update complete | ||
| 2047 | $self->ivPoke('updateFlag', FALSE); | ||
| 2048 | |||
| 2049 | # Select a world, if one was specified in the calling functions; otherwise select the | ||
| 2050 | # 'Create new world' line. This automatically causes $self->updateGridWidgets or | ||
| 2051 | # $self->resetGridWidgets to be called | ||
| 2052 | $treeSelection = $self->treeView->get_selection(); | ||
| 2053 | if ($matchPointer) { | ||
| 2054 | $treeSelection->select_iter($matchPointer); | ||
| 2055 | } else { | ||
| 2056 | $treeSelection->select_iter($model->get_iter_first()); | ||
| 2057 | } | ||
| 2058 | |||
| 2059 | return 1; | ||
| 2060 | } | ||
| 2061 | |||
| 2062 | sub resetGridWidgets { | ||
| 2063 | |||
| 2064 | # Called by $self->selectWorldCallback when the user clicks on the 'Create new world' line | ||
| 2065 | # in the treeview | ||
| 2066 | # Resets IVs and resets the widgets in the window's Gtk3::Grid, ready for the user to enter | ||
| 2067 | # details for a new world | ||
| 2068 | # | ||
| 2069 | # Expected arguments | ||
| 2070 | # (none besides $self) | ||
| 2071 | # | ||
| 2072 | # Return values | ||
| 2073 | # 'undef' on improper arguments | ||
| 2074 | # 1 otherwise | ||
| 2075 | |||
| 2076 | my ($self, $check) = @_; | ||
| 2077 | |||
| 2078 | # Check for improper arguments | ||
| 2079 | if (defined $check) { | ||
| 2080 | |||
| 2081 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetGridWidgets', @_); | ||
| 2082 | } | ||
| 2083 | |||
| 2084 | # Reset the IV which stores the currently displayed world | ||
| 2085 | $self->ivUndef('worldObj'); | ||
| 2086 | # Create a temporary GA::Obj::MiniWorld to store the changes | ||
| 2087 | $self->ivPoke('miniWorldObj', Games::Axmud::Obj::MiniWorld->new()); | ||
| 2088 | # Set a flag to TRUE to stop the mini-world object being updated, as we change the values | ||
| 2089 | # displayed in the grid's widgets | ||
| 2090 | $self->ivPoke('updateFlag', TRUE); | ||
| 2091 | |||
| 2092 | # Reset the 'create world' button's label (it gets modified by $self->updateGridWidgets) | ||
| 2093 | $self->createWorldButton->set_label('Create world'); | ||
| 2094 | $self->createWorldButton->set_tooltip_text('Create a world profile'); | ||
| 2095 | |||
| 2096 | # Reset the grid widgets | ||
| 2097 | $self->entry->set_text(''); | ||
| 2098 | $self->entry2->set_text(''); | ||
| 2099 | $self->entry3->set_text(''); | ||
| 2100 | $self->checkButton->set_active(FALSE); | ||
| 2101 | |||
| 2102 | $self->radioButton->set_active(TRUE); | ||
| 2103 | |||
| 2104 | my $comboBox = $self->resetComboBox(TRUE); | ||
| 2105 | $self->ivPoke('comboBox', $comboBox); | ||
| 2106 | |||
| 2107 | $self->websiteLabel->set_text($self->noWebsiteString); | ||
| 2108 | $self->connectionLabel->set_text($self->noConnectString); | ||
| 2109 | $self->descripBuffer->set_text(''); | ||
| 2110 | |||
| 2111 | # (These calls eliminate flashing when the screenshot is updated rapidly, for example when | ||
| 2112 | # the user scrolls through the list of worlds) | ||
| 2113 | $self->winShowAll($self->_objClass . '->resetGridWidgets'); | ||
| 2114 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->resetGridWidgets'); | ||
| 2115 | |||
| 2116 | # Update the world screenshot, using the default logo | ||
| 2117 | # If a logo for this world exists, use it; otherwise use the default logo | ||
| 2118 | my $image = Gtk3::Image->new_from_file($self->defaultIcon); | ||
| 2119 | $axmud::CLIENT->desktopObj->removeWidget($self->frame, $self->image); | ||
| 2120 | $self->frame->add($image); | ||
| 2121 | $self->ivPoke('image', $image); | ||
| 2122 | |||
| 2123 | # (A repeat of those calls eliminates it entirely) | ||
| 2124 | $self->winShowAll($self->_objClass . '->resetGridWidgets'); | ||
| 2125 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->resetGridWidgets'); | ||
| 2126 | |||
| 2127 | # The entry box for the world's name must be made editable | ||
| 2128 | $self->entry->set_editable(TRUE); | ||
| 2129 | # The 'pwd' / 'account' buttons start insensitive, but can be sensitised if the user selects | ||
| 2130 | # a character | ||
| 2131 | $self->editPwdButton->set_sensitive(FALSE); | ||
| 2132 | $self->editAccButton->set_sensitive(FALSE); | ||
| 2133 | # The 'reset world' button must be insensitive when there isn't a corresponding world | ||
| 2134 | # profile | ||
| 2135 | $self->resetWorldButton->set_sensitive(FALSE); | ||
| 2136 | # The 'add', 'connect offline' and 'connect to world' buttons must be insensitive until the | ||
| 2137 | # user at least types something in the 'host address' entry box | ||
| 2138 | $self->addCharButton->set_sensitive(FALSE); | ||
| 2139 | $self->offlineButton->set_sensitive(FALSE); | ||
| 2140 | $self->connectButton->set_sensitive(FALSE); | ||
| 2141 | |||
| 2142 | # Update complete | ||
| 2143 | $self->ivPoke('updateFlag', FALSE); | ||
| 2144 | |||
| 2145 | # The call to ->show_all() causes the image to appear | ||
| 2146 | $self->winShowAll($self->_objClass . '->resetGridWidgets'); | ||
| 2147 | |||
| 2148 | return 1; | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | sub updateGridWidgets { | ||
| 2152 | |||
| 2153 | # Called by $self->selectWorldCallback when the user clicks on a line in the treeview | ||
| 2154 | # corresponding to a world profile | ||
| 2155 | # Also called by $self->testModeLoginCallback | ||
| 2156 | # | ||
| 2157 | # Updates IVs and updates the widgets in the window's Gtk3::Grid, so they show details about | ||
| 2158 | # the world | ||
| 2159 | # | ||
| 2160 | # Expected arguments | ||
| 2161 | # $worldObj - The GA::Profile::World object corresponding to the clicked line | ||
| 2162 | # $line - The text of the treeview line that the user clicked | ||
| 2163 | # | ||
| 2164 | # Return values | ||
| 2165 | # 'undef' on improper arguments | ||
| 2166 | # 1 otherwise | ||
| 2167 | |||
| 2168 | my ($self, $worldObj, $line, $check) = @_; | ||
| 2169 | |||
| 2170 | # Local variables | ||
| 2171 | my ( | ||
| 2172 | $displayFlag, $modName, $host, $port, $website, $connections, $logoPath, | ||
| 2173 | @charList, | ||
| 2174 | ); | ||
| 2175 | |||
| 2176 | # Check for improper arguments | ||
| 2177 | if (! defined $worldObj || ! defined $line || defined $check) { | ||
| 2178 | |||
| 2179 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateGridWidgets', @_); | ||
| 2180 | } | ||
| 2181 | |||
| 2182 | # Decide which list should be displayed. Default display mode is 'undef', representing | ||
| 2183 | # a list of world profiles | ||
| 2184 | if ($self->otherWorldButton->get_active()) { | ||
| 2185 | |||
| 2186 | $displayFlag = TRUE; | ||
| 2187 | } | ||
| 2188 | |||
| 2189 | # Set the IV which stores the currently displayed world | ||
| 2190 | $self->ivPoke('worldObj', $worldObj); | ||
| 2191 | # Get the equivalent GA::Obj::MiniWorld | ||
| 2192 | $self->ivPoke('miniWorldObj', $self->ivShow('miniWorldHash', $worldObj->name)); | ||
| 2193 | # Set a flag to TRUE to stop the mini-world object being updated, as we change the values | ||
| 2194 | # displayed in the grid's widgets | ||
| 2195 | $self->ivPoke('updateFlag', TRUE); | ||
| 2196 | |||
| 2197 | # Modify the 'create world' button's label (it gets reset by $self->resetGridWidgets) | ||
| 2198 | if (! $displayFlag) { | ||
| 2199 | |||
| 2200 | $self->createWorldButton->set_label('Apply changes'); | ||
| 2201 | $self->createWorldButton->set_tooltip_text('Apply changes to this world profile'); | ||
| 2202 | |||
| 2203 | } else { | ||
| 2204 | |||
| 2205 | $self->createWorldButton->set_label('Create world'); | ||
| 2206 | $self->createWorldButton->set_tooltip_text('Create a world profile'); | ||
| 2207 | } | ||
| 2208 | |||
| 2209 | # Display details about the world. For each IV, if there's an entry in the mini-world | ||
| 2210 | # object, then use its value; otherwise use the value stored in the world profile itself | ||
| 2211 | |||
| 2212 | # 'World name' (we don't consult the mini-world object - the world name can't be changed, | ||
| 2213 | # once a world profile is created) | ||
| 2214 | $modName = '<i>' . $worldObj->name . '</i>'; # Matches $line for a world never connected | ||
| 2215 | if ( | ||
| 2216 | $self->preConfigButton->get_active() | ||
| 2217 | && $worldObj->name ne $line | ||
| 2218 | && $worldObj->name ne $modName | ||
| 2219 | && $worldObj->longName | ||
| 2220 | ) { | ||
| 2221 | $self->entry->set_text($worldObj->longName . ' (' . $worldObj->name . ')'); | ||
| 2222 | } else { | ||
| 2223 | $self->entry->set_text($worldObj->name); | ||
| 2224 | } | ||
| 2225 | |||
| 2226 | # 'Host address', 'Port' | ||
| 2227 | if (! $displayFlag) { | ||
| 2228 | |||
| 2229 | ($host, $port) = $worldObj->getConnectDetails(); | ||
| 2230 | |||
| 2231 | } else { | ||
| 2232 | |||
| 2233 | $host = $worldObj->host; | ||
| 2234 | $port = $worldObj->port; | ||
| 2235 | } | ||
| 2236 | |||
| 2237 | if ($self->miniWorldObj->ivExists('propHash', 'host')) { | ||
| 2238 | $self->entry2->set_text($self->miniWorldObj->ivShow('propHash', 'host')); | ||
| 2239 | } else { | ||
| 2240 | $self->entry2->set_text($host); | ||
| 2241 | } | ||
| 2242 | |||
| 2243 | if ($self->miniWorldObj->ivExists('propHash', 'port')) { | ||
| 2244 | $self->entry3->set_text($self->miniWorldObj->ivShow('propHash', 'port')); | ||
| 2245 | } else { | ||
| 2246 | $self->entry3->set_text($port); | ||
| 2247 | } | ||
| 2248 | |||
| 2249 | # 'Auto-login' | ||
| 2250 | if (! $displayFlag && $self->miniWorldObj->noAutoLoginFlag) { | ||
| 2251 | $self->checkButton->set_active(TRUE); | ||
| 2252 | } else { | ||
| 2253 | $self->checkButton->set_active(FALSE); | ||
| 2254 | } | ||
| 2255 | |||
| 2256 | # 'Character' | ||
| 2257 | if (! $displayFlag) { | ||
| 2258 | |||
| 2259 | @charList = sort {lc($a) cmp lc($b)} ($self->miniWorldObj->ivKeys('passwordHash')); | ||
| 2260 | } | ||
| 2261 | |||
| 2262 | my $comboBox = $self->resetComboBox(TRUE, @charList); | ||
| 2263 | $self->ivPoke('comboBox', $comboBox); | ||
| 2264 | |||
| 2265 | # 'Websites' | ||
| 2266 | $website = 'Websites:'; | ||
| 2267 | |||
| 2268 | if (! $displayFlag) { | ||
| 2269 | |||
| 2270 | if (! $worldObj->worldURL && ! $worldObj->referURL) { | ||
| 2271 | |||
| 2272 | $website .= ' (no websites)'; | ||
| 2273 | |||
| 2274 | } else { | ||
| 2275 | |||
| 2276 | if ($worldObj->worldURL) { | ||
| 2277 | |||
| 2278 | $website .= ' <a href="' . $self->escapeHtml($worldObj->worldURL) | ||
| 2279 | . '">Website</a>'; | ||
| 2280 | } | ||
| 2281 | |||
| 2282 | if ($worldObj->referURL) { | ||
| 2283 | |||
| 2284 | $website .= ' <a href="' . $self->escapeHtml($worldObj->referURL) | ||
| 2285 | . '">Referrer</a>'; | ||
| 2286 | } | ||
| 2287 | } | ||
| 2288 | |||
| 2289 | } else { | ||
| 2290 | |||
| 2291 | $website .= ' (n/a)'; | ||
| 2292 | } | ||
| 2293 | |||
| 2294 | $self->websiteLabel->set_markup($website); | ||
| 2295 | |||
| 2296 | # 'Connections' | ||
| 2297 | if (! $displayFlag) { | ||
| 2298 | |||
| 2299 | $connections = 'Connections: ' . $worldObj->numberConnects; | ||
| 2300 | if ($worldObj->lastConnectDate && $worldObj->lastConnectTime) { | ||
| 2301 | |||
| 2302 | $connections .= ', most recent: ' . $worldObj->lastConnectDate . ' at ' | ||
| 2303 | . $worldObj->lastConnectTime; | ||
| 2304 | } | ||
| 2305 | |||
| 2306 | } else { | ||
| 2307 | |||
| 2308 | $connections = 'Connections: (n/a)'; | ||
| 2309 | } | ||
| 2310 | |||
| 2311 | $self->connectionLabel->set_markup($connections); | ||
| 2312 | |||
| 2313 | # (Descrip) | ||
| 2314 | if ($self->miniWorldObj->ivExists('propHash', 'descrip')) { | ||
| 2315 | |||
| 2316 | $self->descripBuffer->set_text($self->miniWorldObj->ivShow('propHash', 'descrip')); | ||
| 2317 | |||
| 2318 | } elsif (! $displayFlag && $worldObj->worldDescrip) { | ||
| 2319 | |||
| 2320 | $self->descripBuffer->set_text($worldObj->worldDescrip); | ||
| 2321 | |||
| 2322 | } elsif (! $displayFlag) { | ||
| 2323 | |||
| 2324 | $self->descripBuffer->set_text(''); | ||
| 2325 | |||
| 2326 | } else { | ||
| 2327 | |||
| 2328 | $self->descripBuffer->set_text( | ||
| 2329 | 'This world profile won\'t be created until you click one of the buttons below', | ||
| 2330 | ) | ||
| 2331 | } | ||
| 2332 | |||
| 2333 | # Move the 'descrip' textview's scrollbar to the top, in case the user has been browsing | ||
| 2334 | # another world's description | ||
| 2335 | $self->descripTextView->scroll_to_iter( | ||
| 2336 | $self->descripBuffer->get_start_iter(), | ||
| 2337 | 0.0, | ||
| 2338 | TRUE, | ||
| 2339 | 0, | ||
| 2340 | 1, | ||
| 2341 | ); | ||
| 2342 | |||
| 2343 | # If a logo for this world exists, use it; otherwise use the default logo | ||
| 2344 | if (! $displayFlag) { | ||
| 2345 | |||
| 2346 | $logoPath = $axmud::DATA_DIR . '/logos/' . $worldObj->name . '.png'; | ||
| 2347 | } | ||
| 2348 | |||
| 2349 | if ($displayFlag || ! (-e $logoPath)) { | ||
| 2350 | |||
| 2351 | $logoPath = $axmud::CLIENT->getClientLogo($worldObj->adultFlag); | ||
| 2352 | } | ||
| 2353 | |||
| 2354 | # (These calls eliminate flashing when the screenshot is updated rapidly, for example when | ||
| 2355 | # the user scrolls through the list of worlds) | ||
| 2356 | $self->winShowAll($self->_objClass . '->updateGridWidgets'); | ||
| 2357 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->updateGridWidgets'); | ||
| 2358 | |||
| 2359 | # Update the world screenshot | ||
| 2360 | my $image = Gtk3::Image->new_from_file($logoPath); | ||
| 2361 | $axmud::CLIENT->desktopObj->removeWidget($self->frame, $self->image); | ||
| 2362 | $self->frame->add($image); | ||
| 2363 | $self->ivPoke('image', $image); | ||
| 2364 | |||
| 2365 | # (A repeat of those calls eliminates it entirely) | ||
| 2366 | $self->winShowAll($self->_objClass . '->updateGridWidgets'); | ||
| 2367 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->updateGridWidgets'); | ||
| 2368 | |||
| 2369 | # The entry box for the world's name must not be changed | ||
| 2370 | $self->entry->set_editable(FALSE); | ||
| 2371 | # The 'add' button must be sensitive | ||
| 2372 | $self->addCharButton->set_sensitive(TRUE); | ||
| 2373 | # The 'pwd'/'account' buttons start sensitised if there's a selected character, but | ||
| 2374 | # desensitised if not | ||
| 2375 | if ($self->miniWorldObj->selectChar) { | ||
| 2376 | |||
| 2377 | $self->editPwdButton->set_sensitive(TRUE); | ||
| 2378 | $self->editAccButton->set_sensitive(TRUE); | ||
| 2379 | |||
| 2380 | } else { | ||
| 2381 | |||
| 2382 | $self->editPwdButton->set_sensitive(FALSE); | ||
| 2383 | $self->editAccButton->set_sensitive(FALSE); | ||
| 2384 | } | ||
| 2385 | |||
| 2386 | # The 'reset world' button must be sensitive | ||
| 2387 | $self->resetWorldButton->set_sensitive(TRUE); | ||
| 2388 | # If the world profile doesn't have a ->dns, ->ipv4 or ->ipv6 value, Axmud obviously won't | ||
| 2389 | # be able to connect to the world. Make the connect buttons desensitised until the user | ||
| 2390 | # types something in the 'host address' entry box | ||
| 2391 | if (! $host) { | ||
| 2392 | |||
| 2393 | $self->offlineButton->set_sensitive(FALSE); | ||
| 2394 | $self->connectButton->set_sensitive(FALSE); | ||
| 2395 | |||
| 2396 | } else { | ||
| 2397 | |||
| 2398 | # Otherwise, these two buttons start sensitised | ||
| 2399 | $self->offlineButton->set_sensitive(TRUE); | ||
| 2400 | $self->connectButton->set_sensitive(TRUE); | ||
| 2401 | } | ||
| 2402 | |||
| 2403 | # Update complete | ||
| 2404 | $self->ivPoke('updateFlag', FALSE); | ||
| 2405 | |||
| 2406 | # The call to ->show_all() causes the image to appear | ||
| 2407 | $self->winShowAll($self->_objClass . '->updateGridWidgets'); | ||
| 2408 | |||
| 2409 | return 1; | ||
| 2410 | } | ||
| 2411 | |||
| 2412 | sub resetComboBox { | ||
| 2413 | |||
| 2414 | # Called by $self->createGridWidgets, ->resetGridWidgets and ->updateGridWidgets | ||
| 2415 | # Not sure how to empty a Gtk3::ComboBox, so we'll just destroy the old one, and replace it | ||
| 2416 | # with a new one | ||
| 2417 | # | ||
| 2418 | # Expected arguments | ||
| 2419 | # (none besides $self) | ||
| 2420 | # | ||
| 2421 | # Optional arguments | ||
| 2422 | # $destroyFlag - If TRUE, a combobox already exists, and must be deleted. If FALSE (or | ||
| 2423 | # 'undef'), the combobox is being drawn for the first time | ||
| 2424 | # @charList - A list of characters to display in the combobpx. If empty, the | ||
| 2425 | # combobox will contain only the '<no character>' string. If not | ||
| 2426 | # empty, the '<no character>' is added to @charList as the first item | ||
| 2427 | # | ||
| 2428 | # Return values | ||
| 2429 | # 'undef' on improper arguments | ||
| 2430 | # Otherwise returns the Gtk3::ComboBox created | ||
| 2431 | |||
| 2432 | my ($self, $destroyFlag, @charList) = @_; | ||
| 2433 | |||
| 2434 | # Local variables | ||
| 2435 | my ($count, $index); | ||
| 2436 | |||
| 2437 | # (No improper arguments to check) | ||
| 2438 | |||
| 2439 | # If a Gtk3::ComboBox already exists, destroy it | ||
| 2440 | if ($destroyFlag) { | ||
| 2441 | |||
| 2442 | $axmud::CLIENT->desktopObj->removeWidget($self->grid, $self->comboBox); | ||
| 2443 | } | ||
| 2444 | |||
| 2445 | # Create a new combobox | ||
| 2446 | unshift (@charList, $self->noCharString); | ||
| 2447 | my $comboBox = $self->addComboBox($self->grid, undef, \@charList, undef, | ||
| 2448 | 4, 8, 7, 8); | ||
| 2449 | |||
| 2450 | # If the current mini-world object specifies a character, make that the combobox's active | ||
| 2451 | # item. Otherwise, make the '<no character>' string the active item | ||
| 2452 | $index = 0; | ||
| 2453 | if ($self->miniWorldObj && $self->miniWorldObj->selectChar) { | ||
| 2454 | |||
| 2455 | $count = -1; | ||
| 2456 | OUTER: foreach my $string (@charList) { | ||
| 2457 | |||
| 2458 | $count++; | ||
| 2459 | |||
| 2460 | if ($string eq $self->miniWorldObj->selectChar) { | ||
| 2461 | |||
| 2462 | $index = $count; | ||
| 2463 | last OUTER; | ||
| 2464 | } | ||
| 2465 | } | ||
| 2466 | } | ||
| 2467 | |||
| 2468 | $comboBox->set_active($index); | ||
| 2469 | # Also, the 'pwd'/'account' buttons should only be sensitised when there's a selected | ||
| 2470 | # character | ||
| 2471 | if ($self->miniWorldObj) { | ||
| 2472 | |||
| 2473 | if ($self->miniWorldObj->selectChar) { | ||
| 2474 | |||
| 2475 | $self->editPwdButton->set_sensitive(TRUE); | ||
| 2476 | $self->editAccButton->set_sensitive(TRUE); | ||
| 2477 | |||
| 2478 | } else { | ||
| 2479 | |||
| 2480 | $self->editPwdButton->set_sensitive(FALSE); | ||
| 2481 | $self->editAccButton->set_sensitive(FALSE); | ||
| 2482 | } | ||
| 2483 | } | ||
| 2484 | |||
| 2485 | # Now we can add the combobox's ->signal_connect, which updates the mini-world object when | ||
| 2486 | # a character is selected | ||
| 2487 | $comboBox->signal_connect('changed' => sub { | ||
| 2488 | |||
| 2489 | my $char = $comboBox->get_active_text(); | ||
| 2490 | |||
| 2491 | if ($char eq $self->noCharString) { | ||
| 2492 | |||
| 2493 | $self->miniWorldObj->ivUndef('selectChar'); | ||
| 2494 | # When no character is selected, the 'pwd'/'account' buttons must be desensitised | ||
| 2495 | $self->editPwdButton->set_sensitive(FALSE); | ||
| 2496 | $self->editAccButton->set_sensitive(FALSE); | ||
| 2497 | |||
| 2498 | } else { | ||
| 2499 | |||
| 2500 | $self->miniWorldObj->ivPoke('selectChar', $char); | ||
| 2501 | # When no character is selected, the 'pwd'/'account' buttons must be desensitised | ||
| 2502 | $self->editPwdButton->set_sensitive(TRUE); | ||
| 2503 | $self->editAccButton->set_sensitive(TRUE); | ||
| 2504 | } | ||
| 2505 | }); | ||
| 2506 | |||
| 2507 | # The call to ->show_all() makes the new combobox visible | ||
| 2508 | $self->winShowAll($self->_objClass . '->resetComboBox'); | ||
| 2509 | |||
| 2510 | return $comboBox; | ||
| 2511 | } | ||
| 2512 | |||
| 2513 | sub updateProfile { | ||
| 2514 | |||
| 2515 | # Called by $self->applyChangesCallback and ->connectWorldCallback | ||
| 2516 | # Copies changes to values, stored in the specified mini-world object, to the corresponding | ||
| 2517 | # world profile (if it exists) | ||
| 2518 | # | ||
| 2519 | # Expected arguments | ||
| 2520 | # $miniWorldObj - A GA::Obj::MiniWorld | ||
| 2521 | # | ||
| 2522 | # Return values | ||
| 2523 | # 'undef' on improper arguments or if there is no world profile to update | ||
| 2524 | # 1 otherwise | ||
| 2525 | |||
| 2526 | my ($self, $miniWorldObj, $check) = @_; | ||
| 2527 | |||
| 2528 | # Local variables | ||
| 2529 | my ( | ||
| 2530 | $worldObj, $profFlag, $host, $port, $descrip, | ||
| 2531 | %newHash, | ||
| 2532 | ); | ||
| 2533 | |||
| 2534 | # Check for improper arguments | ||
| 2535 | if (! defined $miniWorldObj || defined $check) { | ||
| 2536 | |||
| 2537 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateProfile', @_); | ||
| 2538 | } | ||
| 2539 | |||
| 2540 | # Import the equivalent world profile object, for convenience | ||
| 2541 | $worldObj = $miniWorldObj->worldObj; | ||
| 2542 | # Is it actually a world profile, or is it a basic world object (GA::Obj::BasicWorld), which | ||
| 2543 | # has different IVs? | ||
| 2544 | if (! $worldObj->isa('Games::Axmud::Profile::World')) { | ||
| 2545 | |||
| 2546 | # It's a basic world object; nothing for this function to do | ||
| 2547 | return undef; | ||
| 2548 | } | ||
| 2549 | |||
| 2550 | # (We can't change the profile's ->name) | ||
| 2551 | |||
| 2552 | # ->host and ->port | ||
| 2553 | # If the host address is in the form 'deathmud.com:8888', then extract the port. Although | ||
| 2554 | # it technically possible to use ports with only one digit, don't recognise it | ||
| 2555 | # If, at the same time, the port was specified in the other entry box, ignore the other | ||
| 2556 | $host = $miniWorldObj->ivShow('propHash', 'host'); | ||
| 2557 | if ($host && $host =~ m/^(.*)\:(\d{2,5})\s*$/) { | ||
| 2558 | $host = $1; | ||
| 2559 | $port = $2; | ||
| 2560 | } else { | ||
| 2561 | $port = $miniWorldObj->ivShow('propHash', 'port'); | ||
| 2562 | } | ||
| 2563 | |||
| 2564 | if ($host && $host =~ m/\w/) { | ||
| 2565 | |||
| 2566 | $host = $axmud::CLIENT->trimWhitespace($host); | ||
| 2567 | |||
| 2568 | if ($profFlag) { | ||
| 2569 | |||
| 2570 | if ($axmud::CLIENT->ipv6Check($host)) { | ||
| 2571 | $worldObj->ivPoke('ipv6', $host); | ||
| 2572 | } elsif ($axmud::CLIENT->ipv4Check($host)) { | ||
| 2573 | $worldObj->ivPoke('ipv4', $host); | ||
| 2574 | } else { | ||
| 2575 | $worldObj->ivPoke('dns', $host); | ||
| 2576 | } | ||
| 2577 | |||
| 2578 | } else { | ||
| 2579 | |||
| 2580 | $worldObj->ivPoke('dns', $host); | ||
| 2581 | } | ||
| 2582 | } | ||
| 2583 | |||
| 2584 | if ($port && $port =~ m/\w/) { | ||
| 2585 | |||
| 2586 | $port = $axmud::CLIENT->trimWhitespace($port); | ||
| 2587 | $worldObj->ivPoke('port', $port); | ||
| 2588 | } | ||
| 2589 | |||
| 2590 | $descrip = $miniWorldObj->ivShow('propHash', 'descrip'); | ||
| 2591 | if ($descrip) { | ||
| 2592 | |||
| 2593 | $worldObj->ivPoke('worldDescrip', $descrip); | ||
| 2594 | } | ||
| 2595 | |||
| 2596 | # Characters, now. The data stored in the mini-world object's ->newPasswordHash (consisting | ||
| 2597 | # of new characters, and existing characters with new passwords) is copied into the world | ||
| 2598 | # profile's ->newPasswordHash; it's up to GA::Session->setupProfiles to create new | ||
| 2599 | # character profiles, the next time this world is a current world | ||
| 2600 | %newHash = $miniWorldObj->newPasswordHash; | ||
| 2601 | foreach my $char (keys %newHash) { | ||
| 2602 | |||
| 2603 | my $pass = $newHash{$char}; # May be 'undef' | ||
| 2604 | |||
| 2605 | $worldObj->ivAdd('newPasswordHash', $char, $pass); | ||
| 2606 | } | ||
| 2607 | |||
| 2608 | # The same applies to the mini-world object's ->newAccountHash | ||
| 2609 | %newHash = $miniWorldObj->newAccountHash; | ||
| 2610 | foreach my $char (keys %newHash) { | ||
| 2611 | |||
| 2612 | my $account = $newHash{$char}; # May be 'undef' | ||
| 2613 | |||
| 2614 | $worldObj->ivAdd('newAccountHash', $char, $account); | ||
| 2615 | } | ||
| 2616 | |||
| 2617 | # In test mode, set the number of connections to at least one | ||
| 2618 | if ($miniWorldObj->testModeFlag && $worldObj->numberConnects == 0) { | ||
| 2619 | |||
| 2620 | $worldObj->ivPoke('numberConnects', 1); | ||
| 2621 | } | ||
| 2622 | |||
| 2623 | return 1; | ||
| 2624 | } | ||
| 2625 | |||
| 2626 | sub escapeHtml { | ||
| 2627 | |||
| 2628 | # Called by $self->updateGridWidgets | ||
| 2629 | # Before displaying a random URL in a label, escape &, < and > characters by replacing them | ||
| 2630 | # with HTML entities &, > and < | ||
| 2631 | # | ||
| 2632 | # Expected arguments | ||
| 2633 | # $url - A URL to be displayed in a Gtk3::Label | ||
| 2634 | # | ||
| 2635 | # Return values | ||
| 2636 | # 'undef' on impropert arguments | ||
| 2637 | # Otherwise return the $url, with any problematic characters escaped | ||
| 2638 | |||
| 2639 | my ($self, $url, $check) = @_; | ||
| 2640 | |||
| 2641 | # Check for improper arguments | ||
| 2642 | if (! defined $url || defined $check) { | ||
| 2643 | |||
| 2644 | return $axmud::CLIENT->writeImproper($self->_objClass . '->escapeHtml', @_); | ||
| 2645 | } | ||
| 2646 | |||
| 2647 | $url =~ s/\&/&/g; | ||
| 2648 | $url =~ s/\</>/g; | ||
| 2649 | $url =~ s/\>/</g; | ||
| 2650 | |||
| 2651 | return $url; | ||
| 2652 | } | ||
| 2653 | |||
| 2654 | # Response methods | ||
| 2655 | |||
| 2656 | sub selectWorldCallback { | ||
| 2657 | |||
| 2658 | # Callback, called by anonymous subroutine in $self->drawWidgets when the user clicks on | ||
| 2659 | # any world in the treeview | ||
| 2660 | # Copies information from the selected world profile into the grid widgets on the right | ||
| 2661 | # side of the window | ||
| 2662 | # | ||
| 2663 | # Expected arguments | ||
| 2664 | # $selection - A Gtk3::TreeSelection corresponding to the selected item in the treeview | ||
| 2665 | # | ||
| 2666 | # Return values | ||
| 2667 | # 'undef' on improper arguments or if the selection can't be matched to something in | ||
| 2668 | # $self->worldList | ||
| 2669 | # 1 otherwise | ||
| 2670 | |||
| 2671 | my ($self, $selection, $check) = @_; | ||
| 2672 | |||
| 2673 | # Local variables | ||
| 2674 | my ($model, $iter, $line, $worldObj); | ||
| 2675 | |||
| 2676 | # Check for improper arguments | ||
| 2677 | if (! defined $selection || defined $check) { | ||
| 2678 | |||
| 2679 | return $axmud::CLIENT->writeImproper($self->_objClass . '->selectWorldCallback', @_); | ||
| 2680 | } | ||
| 2681 | |||
| 2682 | # Get the text of the selected line | ||
| 2683 | ($model, $iter) = $selection->get_selected(); | ||
| 2684 | if (! $iter) { | ||
| 2685 | |||
| 2686 | return undef; | ||
| 2687 | |||
| 2688 | } else { | ||
| 2689 | |||
| 2690 | $line = $model->get($iter, 0); | ||
| 2691 | if (! $self->ivExists('worldHash', $line)) { | ||
| 2692 | |||
| 2693 | return undef; | ||
| 2694 | |||
| 2695 | } else { | ||
| 2696 | |||
| 2697 | $worldObj = $self->ivShow('worldHash', $line); | ||
| 2698 | if (! $worldObj) { | ||
| 2699 | |||
| 2700 | # The user has clicked on the 'Create new world' line | ||
| 2701 | $self->resetGridWidgets(); | ||
| 2702 | |||
| 2703 | } else { | ||
| 2704 | |||
| 2705 | $self->updateGridWidgets($worldObj, $line); | ||
| 2706 | } | ||
| 2707 | |||
| 2708 | return 1; | ||
| 2709 | } | ||
| 2710 | } | ||
| 2711 | } | ||
| 2712 | |||
| 2713 | sub addCharCallback { | ||
| 2714 | |||
| 2715 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 2716 | # on the 'add' button | ||
| 2717 | # Adds a character (and optionally a password) to ->passwordHash in the GA::Obj::MiniWorld | ||
| 2718 | # corresponding to the current world | ||
| 2719 | # | ||
| 2720 | # Expected arguments | ||
| 2721 | # $widget - The Gtk3::Button clicked | ||
| 2722 | # | ||
| 2723 | # Return values | ||
| 2724 | # 'undef' on improper arguments or if an invalid character name is supplied | ||
| 2725 | # 1 otherwise | ||
| 2726 | |||
| 2727 | my ($self, $widget, $check) = @_; | ||
| 2728 | |||
| 2729 | # Local variables | ||
| 2730 | my ( | ||
| 2731 | $string, $char, $pass, $account, | ||
| 2732 | @charList, | ||
| 2733 | ); | ||
| 2734 | |||
| 2735 | # Check for improper arguments | ||
| 2736 | if (! defined $widget || defined $check) { | ||
| 2737 | |||
| 2738 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addCharCallback', @_); | ||
| 2739 | } | ||
| 2740 | |||
| 2741 | # Prompt the user to enter a username/password/account. The password/account are optional | ||
| 2742 | $string = 'Associated account name'; | ||
| 2743 | if ($self->miniWorldObj->loginAccountMode eq 'unknown') { | ||
| 2744 | $string .= ' (if required)'; | ||
| 2745 | } elsif ($self->miniWorldObj->loginAccountMode eq 'not_required') { | ||
| 2746 | $string .= ' (not required)'; | ||
| 2747 | } elsif ($self->miniWorldObj->loginAccountMode eq 'required') { | ||
| 2748 | $string .= ' (recommended)'; | ||
| 2749 | } | ||
| 2750 | |||
| 2751 | ($char, $pass, $account) = $self->showTripleEntryDialogue( | ||
| 2752 | 'Add character', | ||
| 2753 | 'Enter a username', | ||
| 2754 | 'Enter a password (optional)', | ||
| 2755 | $string, | ||
| 2756 | undef, # No maximum chars | ||
| 2757 | 2, # Obscure password text (only) | ||
| 2758 | ); | ||
| 2759 | |||
| 2760 | if ($char) { | ||
| 2761 | |||
| 2762 | # Trim leading/trailing whitespace from the name, password and account name | ||
| 2763 | $char = $axmud::CLIENT->trimWhitespace($char); | ||
| 2764 | if ($pass) { | ||
| 2765 | |||
| 2766 | $pass = $axmud::CLIENT->trimWhitespace($pass); | ||
| 2767 | } | ||
| 2768 | |||
| 2769 | if ($account) { | ||
| 2770 | |||
| 2771 | $account = $axmud::CLIENT->trimWhitespace($account); | ||
| 2772 | } | ||
| 2773 | |||
| 2774 | # Check that the name is be a valid profile name | ||
| 2775 | if ( | ||
| 2776 | ! $axmud::CLIENT->nameCheck($char, 16) | ||
| 2777 | || $axmud::CLIENT->ivExists('worldProfHash', $char) | ||
| 2778 | ) { | ||
| 2779 | $self->showMsgDialogue( | ||
| 2780 | 'Add character', | ||
| 2781 | 'error', | ||
| 2782 | '\'' . $char . '\' is not a valid character profile name', | ||
| 2783 | 'ok', | ||
| 2784 | ); | ||
| 2785 | |||
| 2786 | return undef; | ||
| 2787 | } | ||
| 2788 | |||
| 2789 | # Update the current mini-world object | ||
| 2790 | if ($pass) { | ||
| 2791 | |||
| 2792 | $self->miniWorldObj->ivAdd('passwordHash', $char, $pass); | ||
| 2793 | $self->miniWorldObj->ivAdd('newPasswordHash', $char, $pass); | ||
| 2794 | |||
| 2795 | } else { | ||
| 2796 | |||
| 2797 | $self->miniWorldObj->ivAdd('passwordHash', $char, undef); | ||
| 2798 | $self->miniWorldObj->ivAdd('newPasswordHash', $char, undef); | ||
| 2799 | } | ||
| 2800 | |||
| 2801 | if ($account) { | ||
| 2802 | |||
| 2803 | $self->miniWorldObj->ivAdd('accountHash', $char, $account); | ||
| 2804 | $self->miniWorldObj->ivAdd('newAccountHash', $char, $account); | ||
| 2805 | |||
| 2806 | } else { | ||
| 2807 | |||
| 2808 | $self->miniWorldObj->ivAdd('accountHash', $char, undef); | ||
| 2809 | $self->miniWorldObj->ivAdd('newAccountHash', $char, undef); | ||
| 2810 | } | ||
| 2811 | |||
| 2812 | $self->miniWorldObj->ivPoke('selectChar', $char); | ||
| 2813 | |||
| 2814 | # Redraw the combobox | ||
| 2815 | @charList = sort {lc($a) cmp lc($b)} ($self->miniWorldObj->ivKeys('passwordHash')); | ||
| 2816 | my $comboBox = $self->resetComboBox(TRUE, @charList); | ||
| 2817 | $self->ivPoke('comboBox', $comboBox); | ||
| 2818 | } | ||
| 2819 | |||
| 2820 | return 1; | ||
| 2821 | } | ||
| 2822 | |||
| 2823 | sub editPasswordCallback { | ||
| 2824 | |||
| 2825 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 2826 | # on the 'pwd' button | ||
| 2827 | # Edits the password of an existing character, storing the changes in the current mini-world | ||
| 2828 | # object's ->passwordHash and ->newPasswordHash | ||
| 2829 | # | ||
| 2830 | # Expected arguments | ||
| 2831 | # $widget - The Gtk3::Button clicked | ||
| 2832 | # | ||
| 2833 | # Return values | ||
| 2834 | # 'undef' on improper arguments or if no character is selected | ||
| 2835 | # 1 otherwise | ||
| 2836 | |||
| 2837 | my ($self, $widget, $check) = @_; | ||
| 2838 | |||
| 2839 | # Local variables | ||
| 2840 | my ($char, $currentPass, $newPass); | ||
| 2841 | |||
| 2842 | # Check for improper arguments | ||
| 2843 | if (! defined $widget || defined $check) { | ||
| 2844 | |||
| 2845 | return $axmud::CLIENT->writeImproper($self->_objClass . '->editPasswordCallback', @_); | ||
| 2846 | } | ||
| 2847 | |||
| 2848 | # Get the character displayed in the combobox | ||
| 2849 | $char = $self->comboBox->get_active_text(); | ||
| 2850 | if (! $char || $char eq $self->noCharString) { | ||
| 2851 | |||
| 2852 | # No character to edit | ||
| 2853 | return undef; | ||
| 2854 | } | ||
| 2855 | |||
| 2856 | # Get the current password for this character (if any) | ||
| 2857 | $currentPass = $self->miniWorldObj->ivShow('passwordHash', $char); | ||
| 2858 | |||
| 2859 | # Prompt the user to enter a new password | ||
| 2860 | $newPass = $self->showEntryDialogue( | ||
| 2861 | 'Edit password', | ||
| 2862 | 'Enter a new password for the \'' . $char . '\' character', | ||
| 2863 | undef, # No maximum chars | ||
| 2864 | $currentPass, | ||
| 2865 | TRUE, # Obscure text in the entry box | ||
| 2866 | ); | ||
| 2867 | |||
| 2868 | # If the user didn't close the window manually... | ||
| 2869 | if (defined $newPass) { | ||
| 2870 | |||
| 2871 | if ($newPass) { | ||
| 2872 | |||
| 2873 | $self->miniWorldObj->ivAdd('passwordHash', $char, $newPass); | ||
| 2874 | $self->miniWorldObj->ivAdd('newPasswordHash', $char, $newPass); | ||
| 2875 | |||
| 2876 | } else { | ||
| 2877 | |||
| 2878 | $self->miniWorldObj->ivAdd('passwordHash', $char, undef); | ||
| 2879 | $self->miniWorldObj->ivAdd('newPasswordHash', $char, undef); | ||
| 2880 | } | ||
| 2881 | } | ||
| 2882 | |||
| 2883 | return 1; | ||
| 2884 | } | ||
| 2885 | |||
| 2886 | sub editAccountCallback { | ||
| 2887 | |||
| 2888 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 2889 | # on the 'account' button | ||
| 2890 | # Edits the associated account for an existing character, storing the changes in the current | ||
| 2891 | # mini-world object's ->accountHash and ->newAccountHash | ||
| 2892 | # | ||
| 2893 | # Expected arguments | ||
| 2894 | # $widget - The Gtk3::Button clicked | ||
| 2895 | # | ||
| 2896 | # Return values | ||
| 2897 | # 'undef' on improper arguments or if no character is selected | ||
| 2898 | # 1 otherwise | ||
| 2899 | |||
| 2900 | my ($self, $widget, $check) = @_; | ||
| 2901 | |||
| 2902 | # Local variables | ||
| 2903 | my ($string, $char, $currentAccount, $newAccount); | ||
| 2904 | |||
| 2905 | # Check for improper arguments | ||
| 2906 | if (! defined $widget || defined $check) { | ||
| 2907 | |||
| 2908 | return $axmud::CLIENT->writeImproper($self->_objClass . '->editAccountCallback', @_); | ||
| 2909 | } | ||
| 2910 | |||
| 2911 | # Get the character displayed in the combobox | ||
| 2912 | $char = $self->comboBox->get_active_text(); | ||
| 2913 | if (! $char || $char eq $self->noCharString) { | ||
| 2914 | |||
| 2915 | # No character to edit | ||
| 2916 | return undef; | ||
| 2917 | } | ||
| 2918 | |||
| 2919 | # Get the current account for this character (if any) | ||
| 2920 | $currentAccount = $self->miniWorldObj->ivShow('accountHash', $char); | ||
| 2921 | |||
| 2922 | # Prompt the user to enter a new password | ||
| 2923 | $string = 'Enter the new account name associated with the \'' . $char . '\' character'; | ||
| 2924 | if ($self->miniWorldObj->loginAccountMode eq 'not_required') { | ||
| 2925 | $string .= ' (not required for this world)'; | ||
| 2926 | } elsif ($self->miniWorldObj->loginAccountMode eq 'required') { | ||
| 2927 | $string .= ' (recommended for this world)'; | ||
| 2928 | } else { | ||
| 2929 | $string .= ' (if required for this world)'; | ||
| 2930 | } | ||
| 2931 | |||
| 2932 | $newAccount = $self->showEntryDialogue( | ||
| 2933 | 'Edit account', | ||
| 2934 | $string, | ||
| 2935 | undef, # No maximum chars | ||
| 2936 | $currentAccount, | ||
| 2937 | ); | ||
| 2938 | |||
| 2939 | # If the user didn't close the window manually... | ||
| 2940 | if (defined $newAccount) { | ||
| 2941 | |||
| 2942 | if ($newAccount) { | ||
| 2943 | |||
| 2944 | $self->miniWorldObj->ivAdd('accountHash', $char, $newAccount); | ||
| 2945 | $self->miniWorldObj->ivAdd('newAccountHash', $char, $newAccount); | ||
| 2946 | |||
| 2947 | } else { | ||
| 2948 | |||
| 2949 | $self->miniWorldObj->ivAdd('accountHash', $char, undef); | ||
| 2950 | $self->miniWorldObj->ivAdd('newAccountHash', $char, undef); | ||
| 2951 | } | ||
| 2952 | } | ||
| 2953 | |||
| 2954 | return 1; | ||
| 2955 | } | ||
| 2956 | |||
| 2957 | sub createWorldCallback { | ||
| 2958 | |||
| 2959 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 2960 | # the 'create world' button (only visible when 'Create new world' is selected in the list | ||
| 2961 | # of worlds) | ||
| 2962 | # When the currently-selected treeview item is 'create new world', creates a new world | ||
| 2963 | # profile, and updates it with the data stored in $self->miniWorldObj | ||
| 2964 | # | ||
| 2965 | # Expected arguments | ||
| 2966 | # (none besides $self) | ||
| 2967 | # | ||
| 2968 | # Return values | ||
| 2969 | # 'undef' on improper arguments or if there is an error | ||
| 2970 | # 1 otherwise | ||
| 2971 | |||
| 2972 | my ($self, $check) = @_; | ||
| 2973 | |||
| 2974 | # Local variables | ||
| 2975 | my ( | ||
| 2976 | $invalidString, $generalString, $name, $host, $port, $worldObj, $fileObj, $dictObj, | ||
| 2977 | $miniObj, | ||
| 2978 | %pwdHash, %accHash, | ||
| 2979 | ); | ||
| 2980 | |||
| 2981 | # Check for improper arguments | ||
| 2982 | if (defined $check) { | ||
| 2983 | |||
| 2984 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createWorldCallback', @_); | ||
| 2985 | } | ||
| 2986 | |||
| 2987 | if ($self->worldObj && $self->preConfigButton->get_active()) { | ||
| 2988 | |||
| 2989 | # This function shouldn't have been called (->applyChangesCallback should have been | ||
| 2990 | # called instead) | ||
| 2991 | return undef; | ||
| 2992 | } | ||
| 2993 | |||
| 2994 | # Set a few strings to use in 'dialogue' windows | ||
| 2995 | $invalidString = ' can contain letters, numbers and underline characters (except the first' | ||
| 2996 | . ' character), but not spaces. Reserved names like \'' . $axmud::SCRIPT | ||
| 2997 | . '\' are not allowed. The maximum length is 16 characters.'; | ||
| 2998 | $generalString = 'Failed to create the new world profile (many apologies)'; | ||
| 2999 | |||
| 3000 | # Check that the name specified by the user is valid | ||
| 3001 | $name = $axmud::CLIENT->trimWhitespace($self->entry->get_text()); | ||
| 3002 | if ($name eq '') { | ||
| 3003 | |||
| 3004 | $self->showMsgDialogue( | ||
| 3005 | 'Missing name', | ||
| 3006 | 'error', | ||
| 3007 | 'You must specify a name for this world. World profile names' . $invalidString, | ||
| 3008 | 'ok', | ||
| 3009 | ); | ||
| 3010 | |||
| 3011 | return undef; | ||
| 3012 | |||
| 3013 | } elsif (! $axmud::CLIENT->nameCheck($name, 16)) { | ||
| 3014 | |||
| 3015 | $self->showMsgDialogue( | ||
| 3016 | 'Invalid name', | ||
| 3017 | 'error', | ||
| 3018 | '\'' . $name . '\' is an invalid world profile name. Names' . $invalidString, | ||
| 3019 | 'ok', | ||
| 3020 | ); | ||
| 3021 | |||
| 3022 | return undef; | ||
| 3023 | } | ||
| 3024 | |||
| 3025 | # Check that the user entered a host address | ||
| 3026 | $host = $axmud::CLIENT->trimWhitespace($self->entry2->get_text()); | ||
| 3027 | if ($host eq '') { | ||
| 3028 | |||
| 3029 | $self->showMsgDialogue( | ||
| 3030 | 'Missing host address', | ||
| 3031 | 'error', | ||
| 3032 | 'You must specify a host address, e.g. \'dead-souls.net\'. IPV4, IPV6 or DNS' | ||
| 3033 | . ' addresses can be used.', | ||
| 3034 | 'ok', | ||
| 3035 | ); | ||
| 3036 | |||
| 3037 | return undef; | ||
| 3038 | } | ||
| 3039 | |||
| 3040 | # If the host address is in the form 'deathmud.com:8888', then extract the port. Although | ||
| 3041 | # it technically possible to use ports with only one digit, don't recognise it | ||
| 3042 | # If, at the same time, the port was specified in the other entry box, ignore the other | ||
| 3043 | # entry box | ||
| 3044 | if ($host && $host =~ m/^(.*)\:(\d{2,5})\s*$/) { | ||
| 3045 | $host = $1; | ||
| 3046 | $port = $2; | ||
| 3047 | } else { | ||
| 3048 | $port = $axmud::CLIENT->trimWhitespace($self->entry3->get_text()); | ||
| 3049 | } | ||
| 3050 | |||
| 3051 | # If the port was specified, check that it is valid. If the port was left empty, the generic | ||
| 3052 | # port will be used anyway | ||
| 3053 | if ($port ne '' && $port =~ m/\S/ && ! $axmud::CLIENT->intCheck($port, 0, 65535)) { | ||
| 3054 | |||
| 3055 | $self->showMsgDialogue( | ||
| 3056 | 'Invalid port', | ||
| 3057 | 'error', | ||
| 3058 | '\'' . $port . '\' is an invalid port. Specify a value in the range 0-65535, or' | ||
| 3059 | . ' leave the box empty to use the default port.', | ||
| 3060 | 'ok', | ||
| 3061 | ); | ||
| 3062 | |||
| 3063 | return undef; | ||
| 3064 | } | ||
| 3065 | |||
| 3066 | # Create the new world profile. Cheat a bit by pretending the GA::Client is a | ||
| 3067 | # GA::Session. (Rest of this function adapted from code in GA::Cmd::AddWorld->do) | ||
| 3068 | $worldObj = Games::Axmud::Profile::World->new($axmud::CLIENT, $name); | ||
| 3069 | if ($worldObj) { | ||
| 3070 | |||
| 3071 | # Create a file object for the world profile | ||
| 3072 | $fileObj = Games::Axmud::Obj::File->new('worldprof', $name); | ||
| 3073 | } | ||
| 3074 | |||
| 3075 | if (! $worldObj || ! $fileObj) { | ||
| 3076 | |||
| 3077 | $self->showMsgDialogue( | ||
| 3078 | 'General error', | ||
| 3079 | 'error', | ||
| 3080 | $generalString, | ||
| 3081 | 'ok', | ||
| 3082 | ); | ||
| 3083 | |||
| 3084 | return undef; | ||
| 3085 | } | ||
| 3086 | |||
| 3087 | # If a dictionary object with the same name as the world doesn't already exist, create it. | ||
| 3088 | # Otherwise use the existing one | ||
| 3089 | if (! $axmud::CLIENT->ivExists('dictHash', $name)) { | ||
| 3090 | |||
| 3091 | # (Again, cheat a bit by pretending the GA::Client is a GA::Session) | ||
| 3092 | $dictObj = Games::Axmud::Obj::Dict->new($axmud::CLIENT, $name); | ||
| 3093 | if (! $dictObj) { | ||
| 3094 | |||
| 3095 | $self->showMsgDialogue( | ||
| 3096 | 'General error', | ||
| 3097 | 'error', | ||
| 3098 | $generalString, | ||
| 3099 | 'ok', | ||
| 3100 | ); | ||
| 3101 | |||
| 3102 | return undef; | ||
| 3103 | |||
| 3104 | } else { | ||
| 3105 | |||
| 3106 | # Update client IVs with the new dictionary | ||
| 3107 | $axmud::CLIENT->add_dict($dictObj); | ||
| 3108 | } | ||
| 3109 | } | ||
| 3110 | |||
| 3111 | # Update client IVs with the new profile and file object | ||
| 3112 | $axmud::CLIENT->add_fileObj($fileObj); | ||
| 3113 | $axmud::CLIENT->add_worldProf($worldObj); | ||
| 3114 | |||
| 3115 | # Update the world profile's IVs using the values stored in the mini-world object | ||
| 3116 | if ($axmud::CLIENT->ipv6Check($host)) { | ||
| 3117 | $worldObj->ivPoke('ipv6', $host); | ||
| 3118 | } elsif ($axmud::CLIENT->ipv4Check($host)) { | ||
| 3119 | $worldObj->ivPoke('ipv4', $host); | ||
| 3120 | } else { | ||
| 3121 | $worldObj->ivPoke('dns', $host); | ||
| 3122 | } | ||
| 3123 | |||
| 3124 | if ($port) { | ||
| 3125 | |||
| 3126 | # (Otherwise the world profile continues using the generic port, 23) | ||
| 3127 | $worldObj->ivPoke('port', $port); | ||
| 3128 | } | ||
| 3129 | |||
| 3130 | # If the basic mudlist is displayed, we can set a couple of other IVs, too | ||
| 3131 | if ($self->worldObj && $self->otherWorldButton->get_active()) { | ||
| 3132 | |||
| 3133 | $worldObj->ivPoke('longName', $self->worldObj->longName); | ||
| 3134 | $worldObj->ivPoke('adultFlag', $self->worldObj->adultFlag); | ||
| 3135 | } | ||
| 3136 | |||
| 3137 | # Create a new mini-world object, replacing the temporary one stored in $self->miniWorldObj, | ||
| 3138 | # and store it in the hash of mini-world objects which have corresponding world | ||
| 3139 | # profiles | ||
| 3140 | %pwdHash = $self->miniWorldObj->passwordHash; | ||
| 3141 | %accHash = $self->miniWorldObj->accountHash; | ||
| 3142 | $miniObj = Games::Axmud::Obj::MiniWorld->new( | ||
| 3143 | $worldObj, | ||
| 3144 | $self->miniWorldObj->selectChar, | ||
| 3145 | $self->miniWorldObj->loginAccountMode, | ||
| 3146 | \%pwdHash, | ||
| 3147 | \%accHash, | ||
| 3148 | ); | ||
| 3149 | |||
| 3150 | if ($miniObj) { | ||
| 3151 | |||
| 3152 | $self->ivAdd('miniWorldHash', $worldObj->name, $miniObj); | ||
| 3153 | } | ||
| 3154 | |||
| 3155 | # Reset the treeview, specifying that the new world profile should be selected (the call to | ||
| 3156 | # ->resetTreeView also creates a new mini-world object corresponding to $worldObj) | ||
| 3157 | if ($self->otherWorldButton->get_active()) { | ||
| 3158 | |||
| 3159 | # Make sure the list of pre-configured worlds is now visible | ||
| 3160 | $self->preConfigButton->set_active(TRUE); | ||
| 3161 | } | ||
| 3162 | |||
| 3163 | $self->resetTreeView(undef, $worldObj->name); | ||
| 3164 | |||
| 3165 | return 1; | ||
| 3166 | } | ||
| 3167 | |||
| 3168 | sub applyChangesCallback { | ||
| 3169 | |||
| 3170 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 3171 | # the 'apply changes' button (only visibile when 'Create new world' is not selected in the | ||
| 3172 | # list of worlds) | ||
| 3173 | # | ||
| 3174 | # When the currently-selected treeview item is not 'create new world', updates the current | ||
| 3175 | # world profile with any user-entered values stored in the current mini-world object | ||
| 3176 | # | ||
| 3177 | # Expected arguments | ||
| 3178 | # (none besides $self) | ||
| 3179 | # | ||
| 3180 | # Return values | ||
| 3181 | # 'undef' on improper arguments or if there is an error | ||
| 3182 | # 1 otherwise | ||
| 3183 | |||
| 3184 | my ($self, $check) = @_; | ||
| 3185 | |||
| 3186 | # Local variables | ||
| 3187 | my $name; | ||
| 3188 | |||
| 3189 | # Check for improper arguments | ||
| 3190 | if (defined $check) { | ||
| 3191 | |||
| 3192 | return $axmud::CLIENT->writeImproper($self->_objClass . '->applyChangesCallback', @_); | ||
| 3193 | } | ||
| 3194 | |||
| 3195 | if (! $self->worldObj) { | ||
| 3196 | |||
| 3197 | # This function shouldn't have been called (->createWorldCallback should have been | ||
| 3198 | # called instead) | ||
| 3199 | return undef; | ||
| 3200 | } | ||
| 3201 | |||
| 3202 | # Copy changes from the current mini-world object into the corresponding world profile | ||
| 3203 | $self->updateProfile($self->miniWorldObj); | ||
| 3204 | |||
| 3205 | # Reset the mini-world object - the empty IVs mean that the world profile stores the | ||
| 3206 | # same data | ||
| 3207 | $self->miniWorldObj->reset(); | ||
| 3208 | |||
| 3209 | # Reset the treeview, specifying that the existing world profile should still be selected | ||
| 3210 | # this updates grid widgets) | ||
| 3211 | $name = $self->worldObj->name; | ||
| 3212 | $self->resetTreeView(undef, $name); | ||
| 3213 | |||
| 3214 | # Display a confirmation | ||
| 3215 | $self->showMsgDialogue( | ||
| 3216 | 'World updated', | ||
| 3217 | 'info', | ||
| 3218 | 'The \'' . $name . '\' world profile has been updated (but data files have not been' | ||
| 3219 | . ' saved - use the \';save\' command when you start a new session)', | ||
| 3220 | 'ok', | ||
| 3221 | ); | ||
| 3222 | |||
| 3223 | return 1; | ||
| 3224 | } | ||
| 3225 | |||
| 3226 | sub resetWorldCallback { | ||
| 3227 | |||
| 3228 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 3229 | # the 'reset world' button | ||
| 3230 | # Creates a new mini-world object to replace the old one, then resets the treeview which | ||
| 3231 | # causes all the grid widgets to display the values actually stored in the world profile | ||
| 3232 | # | ||
| 3233 | # Expected arguments | ||
| 3234 | # $widget - The Gtk3::Button clicked | ||
| 3235 | # | ||
| 3236 | # Return values | ||
| 3237 | # 'undef' on improper arguments or if there is an error | ||
| 3238 | # 1 otherwise | ||
| 3239 | |||
| 3240 | my ($self, $widget, $check) = @_; | ||
| 3241 | |||
| 3242 | # Local variables | ||
| 3243 | my ( | ||
| 3244 | $miniObj, | ||
| 3245 | %pwdHash, %accHash, | ||
| 3246 | ); | ||
| 3247 | |||
| 3248 | # Check for improper arguments | ||
| 3249 | if (! defined $widget || defined $check) { | ||
| 3250 | |||
| 3251 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWorldCallback', @_); | ||
| 3252 | } | ||
| 3253 | |||
| 3254 | if (! $self->worldObj) { | ||
| 3255 | |||
| 3256 | # This function shouldn't have been called (->createWorldCallback should have been | ||
| 3257 | # called instead) | ||
| 3258 | return undef; | ||
| 3259 | } | ||
| 3260 | |||
| 3261 | if ($self->preConfigButton->get_active()) { | ||
| 3262 | |||
| 3263 | # Create a new mini-world object corresponding to an existing world profile | ||
| 3264 | %pwdHash = $self->worldObj->passwordHash; | ||
| 3265 | %accHash = $self->worldObj->accountHash; | ||
| 3266 | $miniObj = Games::Axmud::Obj::MiniWorld->new( | ||
| 3267 | $self->worldObj, | ||
| 3268 | $self->worldObj->lastConnectChar, # May be undef | ||
| 3269 | $self->worldObj->loginAccountMode, | ||
| 3270 | \%pwdHash, | ||
| 3271 | \%accHash, | ||
| 3272 | ); | ||
| 3273 | |||
| 3274 | } else { | ||
| 3275 | |||
| 3276 | # Create a new mini-world object NOT corresponding to an existing world profile | ||
| 3277 | $miniObj = Games::Axmud::Obj::MiniWorld->new($self->worldObj); | ||
| 3278 | } | ||
| 3279 | |||
| 3280 | if ($miniObj) { | ||
| 3281 | |||
| 3282 | $self->ivAdd('miniWorldHash', $self->worldObj->name, $miniObj); | ||
| 3283 | } | ||
| 3284 | |||
| 3285 | # Reset the treeview, specifying that the same world profile should be selected (the call to | ||
| 3286 | # ->resetTreeView also creates a new mini-world object corresponding to $worldObj) | ||
| 3287 | $self->resetTreeView(undef, $self->worldObj->name); | ||
| 3288 | |||
| 3289 | return 1; | ||
| 3290 | } | ||
| 3291 | |||
| 3292 | sub connectWorldCallback { | ||
| 3293 | |||
| 3294 | # Callback, called by anonymous subroutine in $self->createGridWidgets when the user clicks | ||
| 3295 | # the 'connect to world' or 'connect offline' buttons | ||
| 3296 | # Starts a new GA::Session, passing it information from this window (such as the selected | ||
| 3297 | # world and character) | ||
| 3298 | # | ||
| 3299 | # Expected arguments | ||
| 3300 | # $offlineFlag - Set to TRUE if the user clicked on the 'connect offline' button; set | ||
| 3301 | # to FALSE if the user clicked on the 'connect to world' button | ||
| 3302 | # | ||
| 3303 | # Return values | ||
| 3304 | # 'undef' on improper arguments or if there is an error | ||
| 3305 | # 1 otherwise | ||
| 3306 | |||
| 3307 | my ($self, $offlineFlag, $check) = @_; | ||
| 3308 | |||
| 3309 | # Local variables | ||
| 3310 | my ( | ||
| 3311 | $displayFlag, $applyFlag, $msg, $response, $worldName, $tempFlag, $altHost, $altPort, | ||
| 3312 | $altChar, $altPass, $altAccount, $host, $port, $pass, $char, $account, $protocol, | ||
| 3313 | @miniList, | ||
| 3314 | ); | ||
| 3315 | |||
| 3316 | # Check for improper arguments | ||
| 3317 | if (! defined $offlineFlag || defined $check) { | ||
| 3318 | |||
| 3319 | return $axmud::CLIENT->writeImproper($self->_objClass . '->connectWorldCallback', @_); | ||
| 3320 | } | ||
| 3321 | |||
| 3322 | # Remember which list was displayed, as the Connections window is about to be destroyed | ||
| 3323 | if ($self->otherWorldButton->get_active()) { | ||
| 3324 | |||
| 3325 | $displayFlag = TRUE; | ||
| 3326 | } | ||
| 3327 | |||
| 3328 | # Before doing anything, check that the maximum number of sessions hasn't already been | ||
| 3329 | # reached | ||
| 3330 | if ($axmud::CLIENT->ivPairs('sessionHash') >= $axmud::CLIENT->sessionMax) { | ||
| 3331 | |||
| 3332 | if ($axmud::CLIENT->sessionMax == 1) { | ||
| 3333 | |||
| 3334 | $self->showMsgDialogue( | ||
| 3335 | 'Session limit reached', | ||
| 3336 | 'error', | ||
| 3337 | 'Can\'t open a new session (only one session allowed - use the' | ||
| 3338 | . ' \';maxsession\' command to change this)', | ||
| 3339 | 'ok', | ||
| 3340 | ); | ||
| 3341 | |||
| 3342 | } else { | ||
| 3343 | |||
| 3344 | $self->showMsgDialogue( | ||
| 3345 | 'Session limit reached', | ||
| 3346 | 'error', | ||
| 3347 | 'Can\'t open a new session (' . $axmud::SCRIPT . ' has reached its limit of ' | ||
| 3348 | . $self->sessionMax . ' sessions)', | ||
| 3349 | 'ok', | ||
| 3350 | ); | ||
| 3351 | } | ||
| 3352 | |||
| 3353 | return undef; | ||
| 3354 | } | ||
| 3355 | |||
| 3356 | # If the user has made any changes to the values displayed in grid widgets, that would be | ||
| 3357 | # applied to the world profile when the 'store changes' button is clicked, we need to ask | ||
| 3358 | # the user if they want to apply those changes now | ||
| 3359 | |||
| 3360 | # Compile a list of mini-world objects whose values have been modified, but not stored in | ||
| 3361 | # the corresponding world profiles. Also set a flag if the selected mini-world has been | ||
| 3362 | # modified, but not stored | ||
| 3363 | foreach my $miniObj ($self->ivValues('miniWorldHash')) { | ||
| 3364 | |||
| 3365 | if ($miniObj->propHash || $miniObj->newPasswordHash || $miniObj->newAccountHash) { | ||
| 3366 | |||
| 3367 | push (@miniList, $miniObj); | ||
| 3368 | |||
| 3369 | if ($miniObj eq $self->miniWorldObj) { | ||
| 3370 | |||
| 3371 | $applyFlag = TRUE; | ||
| 3372 | } | ||
| 3373 | } | ||
| 3374 | } | ||
| 3375 | |||
| 3376 | if (@miniList) { | ||
| 3377 | |||
| 3378 | # Unstored values; prompt the user to ask if they'd like to apply them before continuing | ||
| 3379 | $msg = 'You haven\'t applied your changes to '; | ||
| 3380 | if (! $applyFlag) { | ||
| 3381 | |||
| 3382 | if (@miniList == 1) { | ||
| 3383 | $msg .= '1 world' | ||
| 3384 | } else { | ||
| 3385 | $msg .= scalar @miniList . ' worlds' | ||
| 3386 | } | ||
| 3387 | |||
| 3388 | } else { | ||
| 3389 | |||
| 3390 | if (@miniList == 1) { | ||
| 3391 | $msg .= 'the selected world'; | ||
| 3392 | } else { | ||
| 3393 | $msg .= scalar @miniList . ' worlds (including the selected one)'; | ||
| 3394 | } | ||
| 3395 | } | ||
| 3396 | |||
| 3397 | $msg .= '. Do you want to apply them now?'; | ||
| 3398 | |||
| 3399 | $response = $self->showMsgDialogue( | ||
| 3400 | 'Apply changes', | ||
| 3401 | 'question', | ||
| 3402 | $msg, | ||
| 3403 | 'yes-no', | ||
| 3404 | 'yes', | ||
| 3405 | ); | ||
| 3406 | |||
| 3407 | if ($response && $response eq 'yes') { | ||
| 3408 | |||
| 3409 | # Apply the changes for each modified mini-world object | ||
| 3410 | foreach my $miniObj (@miniList) { | ||
| 3411 | |||
| 3412 | $self->updateProfile($miniObj); | ||
| 3413 | } | ||
| 3414 | |||
| 3415 | if (! $self->worldObj) { | ||
| 3416 | |||
| 3417 | # Earlier there was no corresponding world profile object, but now there is one. | ||
| 3418 | # Use it | ||
| 3419 | $self->ivPoke( | ||
| 3420 | 'worldObj', | ||
| 3421 | $axmud::CLIENT->ivShow('worldProfHash', $self->miniWorldObj->name), | ||
| 3422 | ); | ||
| 3423 | } | ||
| 3424 | } | ||
| 3425 | } | ||
| 3426 | |||
| 3427 | # Set the chosen $protocol, or leave 'undef' to use the world profile's default protocol | ||
| 3428 | if ($self->radioButton2->get_active()) { | ||
| 3429 | $protocol = 'telnet'; | ||
| 3430 | } elsif ($self->radioButton3->get_active()) { | ||
| 3431 | $protocol = 'ssh'; | ||
| 3432 | } elsif ($self->radioButton4->get_active()) { | ||
| 3433 | $protocol = 'ssl'; | ||
| 3434 | } | ||
| 3435 | |||
| 3436 | if ($self->worldObj) { | ||
| 3437 | |||
| 3438 | if (! $displayFlag) { | ||
| 3439 | |||
| 3440 | # The user has selected a world with an existing world profile | ||
| 3441 | $tempFlag = FALSE; | ||
| 3442 | $worldName = $self->worldObj->name; | ||
| 3443 | |||
| 3444 | # Get the world profile's usual connection details, in case the mini-world object | ||
| 3445 | # doesn't specify them | ||
| 3446 | ($altHost, $altPort, $altChar, $altPass, $altAccount) | ||
| 3447 | = $self->worldObj->getConnectDetails($self->miniWorldObj->selectChar); | ||
| 3448 | |||
| 3449 | # Decide which connection details to use | ||
| 3450 | $host = $self->miniWorldObj->ivShow('propHash', 'host'); | ||
| 3451 | if (! $host) { | ||
| 3452 | |||
| 3453 | $host = $altHost; | ||
| 3454 | } | ||
| 3455 | |||
| 3456 | $port = $self->miniWorldObj->ivShow('propHash', 'port'); | ||
| 3457 | if (! $port) { | ||
| 3458 | |||
| 3459 | $port = $altPort; | ||
| 3460 | } | ||
| 3461 | |||
| 3462 | |||
| 3463 | } else { | ||
| 3464 | |||
| 3465 | # The user has selected a world from the basic mudlist, for which no world profile | ||
| 3466 | # exists yet | ||
| 3467 | $tempFlag = FALSE; | ||
| 3468 | $worldName = $self->worldObj->name; | ||
| 3469 | $host = $self->worldObj->host; | ||
| 3470 | $port = $self->worldObj->port; | ||
| 3471 | } | ||
| 3472 | |||
| 3473 | $char = $self->miniWorldObj->selectChar; # May be 'undef' | ||
| 3474 | if ($char) { | ||
| 3475 | |||
| 3476 | $pass = $self->miniWorldObj->ivShow( | ||
| 3477 | 'passwordHash', | ||
| 3478 | $self->miniWorldObj->selectChar, | ||
| 3479 | ); | ||
| 3480 | |||
| 3481 | $account = $self->miniWorldObj->ivShow( | ||
| 3482 | 'accountHash', | ||
| 3483 | $self->miniWorldObj->selectChar, | ||
| 3484 | ); | ||
| 3485 | } | ||
| 3486 | |||
| 3487 | # If the user selected no auto-login, reset the password and account name (the | ||
| 3488 | # GA::Session won't attempt an auto-login, without knowing the password) | ||
| 3489 | if ($self->miniWorldObj->noAutoLoginFlag) { | ||
| 3490 | |||
| 3491 | $pass = undef; | ||
| 3492 | $account = undef; | ||
| 3493 | } | ||
| 3494 | |||
| 3495 | } else { | ||
| 3496 | |||
| 3497 | # The user has selected a world without an existing world profile, and has declined | ||
| 3498 | # to create a profile in the earlier 'dialogue' window (if one was presented) | ||
| 3499 | $worldName = $self->miniWorldObj->ivShow('propHash', 'name'); | ||
| 3500 | if (defined $worldName && $worldName ne '') { | ||
| 3501 | |||
| 3502 | if (! $axmud::CLIENT->nameCheck($worldName, 16)) { | ||
| 3503 | |||
| 3504 | $self->showMsgDialogue( | ||
| 3505 | 'Invalid name', | ||
| 3506 | 'error', | ||
| 3507 | '\'' . $worldName . '\' is an invalid world profile name. Names can contain' | ||
| 3508 | . ' letters, numbers and underline characters (except the first character),' | ||
| 3509 | . ' but not spaces. Reserved names like \'' . $axmud::SCRIPT | ||
| 3510 | . '\' are not allowed. The maximum length is 16 characters.', | ||
| 3511 | 'ok', | ||
| 3512 | ); | ||
| 3513 | |||
| 3514 | return undef; | ||
| 3515 | |||
| 3516 | } else { | ||
| 3517 | |||
| 3518 | $tempFlag = FALSE; | ||
| 3519 | } | ||
| 3520 | |||
| 3521 | } else { | ||
| 3522 | |||
| 3523 | # The user didn't specify a world name. Ask the GA::Client to supply us with a name | ||
| 3524 | # for a temporary profile | ||
| 3525 | $tempFlag = TRUE; | ||
| 3526 | $worldName = $axmud::CLIENT->getTempProfName(); | ||
| 3527 | if (! $worldName) { | ||
| 3528 | |||
| 3529 | # No available names (an extremely unlikely situation) | ||
| 3530 | $axmud::CLIENT->mainWin->showMsgDialogue( | ||
| 3531 | 'Failed connection', | ||
| 3532 | 'error', | ||
| 3533 | 'General error while connection to the world', | ||
| 3534 | 'ok', | ||
| 3535 | ); | ||
| 3536 | |||
| 3537 | return undef; | ||
| 3538 | } | ||
| 3539 | } | ||
| 3540 | |||
| 3541 | # Decide which connection details to use (the 'host' value is always defined when this | ||
| 3542 | # function is called) | ||
| 3543 | $host = $self->miniWorldObj->ivShow('propHash', 'host'); | ||
| 3544 | # If the host address is in the form 'deathmud.com:8888', then extract the port. | ||
| 3545 | # Although it technically possible to use ports with only one digit, don't recognise | ||
| 3546 | # it | ||
| 3547 | # If, at the same time, the port was specified in the other entry box, ignore the other | ||
| 3548 | # entry box | ||
| 3549 | if ($host =~ m/^(.*)\:(\d{2,5})\s*$/) { | ||
| 3550 | |||
| 3551 | $host = $1; | ||
| 3552 | $port = $2; | ||
| 3553 | |||
| 3554 | } else { | ||
| 3555 | |||
| 3556 | $port = $self->miniWorldObj->ivShow('propHash', 'port'); | ||
| 3557 | if (! defined $port || $port eq '') { | ||
| 3558 | |||
| 3559 | $port = 23; | ||
| 3560 | |||
| 3561 | } elsif (! $axmud::CLIENT->intCheck($port, 0, 65535)) { | ||
| 3562 | |||
| 3563 | $self->showMsgDialogue( | ||
| 3564 | 'Invalid port', | ||
| 3565 | 'error', | ||
| 3566 | '\'' . $port . '\' is an invalid port. Specify a value in the range' | ||
| 3567 | . ' 0-65535, or leave the box empty to use the default port.', | ||
| 3568 | 'ok', | ||
| 3569 | ); | ||
| 3570 | |||
| 3571 | return undef; | ||
| 3572 | } | ||
| 3573 | } | ||
| 3574 | |||
| 3575 | $char = $self->miniWorldObj->selectChar; # May be 'undef' | ||
| 3576 | |||
| 3577 | if ($char) { | ||
| 3578 | |||
| 3579 | $pass = $self->miniWorldObj->ivShow( | ||
| 3580 | 'passwordHash', | ||
| 3581 | $self->miniWorldObj->selectChar, | ||
| 3582 | ); | ||
| 3583 | |||
| 3584 | $account = $self->miniWorldObj->ivShow( | ||
| 3585 | 'accountHash', | ||
| 3586 | $self->miniWorldObj->selectChar, | ||
| 3587 | ); | ||
| 3588 | } | ||
| 3589 | |||
| 3590 | # If the user selected no auto-login, reset the password/account name (the GA::Session | ||
| 3591 | # won't attempt an auto-login, without knowing the password) | ||
| 3592 | if ($self->miniWorldObj->noAutoLoginFlag) { | ||
| 3593 | |||
| 3594 | $pass = undef; | ||
| 3595 | $account = undef; | ||
| 3596 | } | ||
| 3597 | } | ||
| 3598 | |||
| 3599 | # Now we can connect to the world. Close this window, so it doesn't get in the way | ||
| 3600 | $self->winDestroy(); | ||
| 3601 | |||
| 3602 | # Start the session | ||
| 3603 | if ( | ||
| 3604 | ! $axmud::CLIENT->startSession( | ||
| 3605 | $worldName, | ||
| 3606 | $host, | ||
| 3607 | $port, | ||
| 3608 | $char, | ||
| 3609 | $pass, | ||
| 3610 | $account, | ||
| 3611 | $protocol, # If 'undef', default protocol used | ||
| 3612 | undef, # No login mode | ||
| 3613 | $offlineFlag, | ||
| 3614 | $tempFlag, | ||
| 3615 | ) | ||
| 3616 | ) { | ||
| 3617 | # Display a confirmation | ||
| 3618 | $axmud::CLIENT->mainWin->showMsgDialogue( | ||
| 3619 | 'Failed connection', | ||
| 3620 | 'error', | ||
| 3621 | 'General error while connecting to \'' . $worldName . '\'', | ||
| 3622 | 'ok', | ||
| 3623 | ); | ||
| 3624 | |||
| 3625 | return undef; | ||
| 3626 | |||
| 3627 | } else { | ||
| 3628 | |||
| 3629 | # This GA::OtherWin::Connect is now finished | ||
| 3630 | return 1; | ||
| 3631 | } | ||
| 3632 | } | ||
| 3633 | |||
| 3634 | sub testModeCallback { | ||
| 3635 | |||
| 3636 | # Function used for Axmud development | ||
| 3637 | # $self->createGridWidgets creates a button that's only visible if the user has edited the | ||
| 3638 | # contents of /scripts/axmud.pl or /scripts/baxmud.pl, in order to modify the global | ||
| 3639 | # variable @TEST_MODE_LOGIN_LIST | ||
| 3640 | # The button, if visible and if clicked, calls this function, which uses the contents of | ||
| 3641 | # the global variable to set the visible world, address, port, character and password, as | ||
| 3642 | # if the user had entered those values manually | ||
| 3643 | # | ||
| 3644 | # Expected arguments | ||
| 3645 | # $testButton - The Gtk3::Button that was clicked | ||
| 3646 | # | ||
| 3647 | # Return values | ||
| 3648 | # 'undef' on improper arguments or if there is an error | ||
| 3649 | # 1 otherwise | ||
| 3650 | |||
| 3651 | my ($self, $testButton, $check) = @_; | ||
| 3652 | |||
| 3653 | # Local variables | ||
| 3654 | my ( | ||
| 3655 | $worldObj, | ||
| 3656 | @testList, @charList, | ||
| 3657 | ); | ||
| 3658 | |||
| 3659 | # Check for improper arguments | ||
| 3660 | if (! defined $testButton || defined $check) { | ||
| 3661 | |||
| 3662 | return $axmud::CLIENT->writeImproper($self->_objClass . '->testModeCallback', @_); | ||
| 3663 | } | ||
| 3664 | |||
| 3665 | # Import the global variable (for convenience) | ||
| 3666 | @testList = @axmud::TEST_MODE_LOGIN_LIST; | ||
| 3667 | |||
| 3668 | # If the global variable refers to a world, for which a world profile already exists, | ||
| 3669 | # update grid widgets as if the user had entered the global variable's value manually | ||
| 3670 | if (defined $testList[0]) { | ||
| 3671 | |||
| 3672 | $worldObj = $axmud::CLIENT->ivShow('worldProfHash', $testList[0]); | ||
| 3673 | if ($worldObj) { | ||
| 3674 | |||
| 3675 | # Update grid widgets for this world, unless that world is already the visible one | ||
| 3676 | if (! $self->worldObj || $worldObj ne $self->worldObj) { | ||
| 3677 | |||
| 3678 | $self->updateGridWidgets($worldObj, $worldObj->longName); | ||
| 3679 | } | ||
| 3680 | |||
| 3681 | # Update grid widgets again, using the values stored in @TEST_MODE_LOGIN_LIST | ||
| 3682 | |||
| 3683 | # World DNS/IP address | ||
| 3684 | if (defined $testList[1]) { | ||
| 3685 | |||
| 3686 | $self->entry2->set_text($testList[1]); | ||
| 3687 | } | ||
| 3688 | |||
| 3689 | # World port | ||
| 3690 | if (defined $testList[2]) { | ||
| 3691 | |||
| 3692 | $self->entry3->set_text($testList[2]); | ||
| 3693 | } | ||
| 3694 | |||
| 3695 | # Character name and password | ||
| 3696 | if (defined $testList[3] && defined $testList[4]) { | ||
| 3697 | |||
| 3698 | $self->miniWorldObj->ivAdd('passwordHash', $testList[3], $testList[4]); | ||
| 3699 | $self->miniWorldObj->ivAdd('newPasswordHash', $testList[3], $testList[4]); | ||
| 3700 | |||
| 3701 | $self->miniWorldObj->ivPoke('selectChar', $testList[3]); | ||
| 3702 | |||
| 3703 | # Redraw the combobox | ||
| 3704 | @charList | ||
| 3705 | = sort {lc($a) cmp lc($b)} ($self->miniWorldObj->ivKeys('passwordHash')); | ||
| 3706 | |||
| 3707 | my $comboBox = $self->resetComboBox(TRUE, @charList); | ||
| 3708 | $self->ivPoke('comboBox', $comboBox); | ||
| 3709 | } | ||
| 3710 | |||
| 3711 | # Mark the number of connections to be set to at least 1 | ||
| 3712 | $self->miniWorldObj->ivPoke('testModeFlag', TRUE); | ||
| 3713 | } | ||
| 3714 | } | ||
| 3715 | |||
| 3716 | return 1; | ||
| 3717 | } | ||
| 3718 | |||
| 3719 | ################## | ||
| 3720 | # Accessors - set | ||
| 3721 | |||
| 3722 | sub set_consoleButton { | ||
| 3723 | |||
| 3724 | my ($self, $flag, $check) = @_; | ||
| 3725 | |||
| 3726 | # Check for improper arguments | ||
| 3727 | if (defined $check) { | ||
| 3728 | |||
| 3729 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_consoleButton', @_); | ||
| 3730 | } | ||
| 3731 | |||
| 3732 | if (! $flag) { | ||
| 3733 | |||
| 3734 | # No system messages to display in the Client Console window | ||
| 3735 | $self->consoleButton->set_image( | ||
| 3736 | Gtk3::Image->new_from_file($axmud::SHARE_DIR . '/icons/connect/icon_console.png'), | ||
| 3737 | ); | ||
| 3738 | |||
| 3739 | } else { | ||
| 3740 | |||
| 3741 | # At least one system message to display in the Client Console window | ||
| 3742 | $self->consoleButton->set_image( | ||
| 3743 | Gtk3::Image->new_from_file( | ||
| 3744 | $axmud::SHARE_DIR . '/icons/connect/icon_console_alert.png', | ||
| 3745 | ), | ||
| 3746 | ); | ||
| 3747 | } | ||
| 3748 | |||
| 3749 | return 1; | ||
| 3750 | } | ||
| 3751 | |||
| 3752 | ################## | ||
| 3753 | # Accessors - get | ||
| 3754 | |||
| 3755 | sub hPaned | ||
| 3756 | { $_[0]->{hPaned} } | ||
| 3757 | sub vBox | ||
| 3758 | { $_[0]->{vBox} } | ||
| 3759 | sub frame | ||
| 3760 | { $_[0]->{frame} } | ||
| 3761 | sub image | ||
| 3762 | { $_[0]->{image} } | ||
| 3763 | sub hBox | ||
| 3764 | { $_[0]->{hBox} } | ||
| 3765 | sub objModel | ||
| 3766 | { $_[0]->{objModel} } | ||
| 3767 | sub treeView | ||
| 3768 | { $_[0]->{treeView} } | ||
| 3769 | sub treeViewColumn | ||
| 3770 | { $_[0]->{treeViewColumn} } | ||
| 3771 | sub frame2 | ||
| 3772 | { $_[0]->{frame2} } | ||
| 3773 | sub scroller | ||
| 3774 | { $_[0]->{scroller} } | ||
| 3775 | sub frame3 | ||
| 3776 | { $_[0]->{frame3} } | ||
| 3777 | sub scroller2 | ||
| 3778 | { $_[0]->{scroller2} } | ||
| 3779 | sub grid | ||
| 3780 | { $_[0]->{grid} } | ||
| 3781 | sub preConfigButton | ||
| 3782 | { $_[0]->{preConfigButton} } | ||
| 3783 | sub otherWorldButton | ||
| 3784 | { $_[0]->{otherWorldButton} } | ||
| 3785 | sub sortAzButton | ||
| 3786 | { $_[0]->{sortAzButton} } | ||
| 3787 | sub sortZaButton | ||
| 3788 | { $_[0]->{sortZaButton} } | ||
| 3789 | sub sortRandButton | ||
| 3790 | { $_[0]->{sortRandButton} } | ||
| 3791 | sub searchButton | ||
| 3792 | { $_[0]->{searchButton} } | ||
| 3793 | sub cancelSearchButton | ||
| 3794 | { $_[0]->{cancelSearchButton} } | ||
| 3795 | sub consoleButton | ||
| 3796 | { $_[0]->{consoleButton} } | ||
| 3797 | sub entry | ||
| 3798 | { $_[0]->{entry} } | ||
| 3799 | sub entry2 | ||
| 3800 | { $_[0]->{entry2} } | ||
| 3801 | sub entry3 | ||
| 3802 | { $_[0]->{entry3} } | ||
| 3803 | sub checkButton | ||
| 3804 | { $_[0]->{checkButton} } | ||
| 3805 | sub radioButton | ||
| 3806 | { $_[0]->{radioButton} } | ||
| 3807 | sub radioButton2 | ||
| 3808 | { $_[0]->{radioButton2} } | ||
| 3809 | sub radioButton3 | ||
| 3810 | { $_[0]->{radioButton3} } | ||
| 3811 | sub radioButton4 | ||
| 3812 | { $_[0]->{radioButton4} } | ||
| 3813 | sub comboBox | ||
| 3814 | { $_[0]->{comboBox} } | ||
| 3815 | sub addCharButton | ||
| 3816 | { $_[0]->{addCharButton} } | ||
| 3817 | sub editPwdButton | ||
| 3818 | { $_[0]->{editPwdButton} } | ||
| 3819 | sub editAccButton | ||
| 3820 | { $_[0]->{editAccButton} } | ||
| 3821 | sub websiteLabel | ||
| 3822 | { $_[0]->{websiteLabel} } | ||
| 3823 | sub connectionLabel | ||
| 3824 | { $_[0]->{connectionLabel} } | ||
| 3825 | sub descripTextView | ||
| 3826 | { $_[0]->{descripTextView} } | ||
| 3827 | sub descripBuffer | ||
| 3828 | { $_[0]->{descripBuffer} } | ||
| 3829 | sub createWorldButton | ||
| 3830 | { $_[0]->{createWorldButton} } | ||
| 3831 | sub resetWorldButton | ||
| 3832 | { $_[0]->{resetWorldButton} } | ||
| 3833 | sub offlineButton | ||
| 3834 | { $_[0]->{offlineButton} } | ||
| 3835 | sub connectButton | ||
| 3836 | { $_[0]->{connectButton} } | ||
| 3837 | |||
| 3838 | sub defaultIcon | ||
| 3839 | { $_[0]->{defaultIcon} } | ||
| 3840 | sub imageWidth | ||
| 3841 | { $_[0]->{imageWidth} } | ||
| 3842 | sub imageHeight | ||
| 3843 | { $_[0]->{imageHeight} } | ||
| 3844 | sub tableWidth | ||
| 3845 | { $_[0]->{tableWidth} } | ||
| 3846 | sub tableHeight | ||
| 3847 | { $_[0]->{tableHeight} } | ||
| 3848 | |||
| 3849 | sub worldHash | ||
| 3850 | { my $self = shift; return %{$self->{worldHash}}; } | ||
| 3851 | sub miniWorldHash | ||
| 3852 | { my $self = shift; return %{$self->{miniWorldHash}}; } | ||
| 3853 | sub worldObj | ||
| 3854 | { $_[0]->{worldObj} } | ||
| 3855 | sub miniWorldObj | ||
| 3856 | { $_[0]->{miniWorldObj} } | ||
| 3857 | sub updateFlag | ||
| 3858 | { $_[0]->{updateFlag} } | ||
| 3859 | |||
| 3860 | sub newWorldString | ||
| 3861 | { $_[0]->{newWorldString} } | ||
| 3862 | sub noCharString | ||
| 3863 | { $_[0]->{noCharString} } | ||
| 3864 | sub noWebsiteString | ||
| 3865 | { $_[0]->{noWebsiteString} } | ||
| 3866 | sub noConnectString | ||
| 3867 | { $_[0]->{noConnectString} } | ||
| 3868 | |||
| 3869 | sub searchRegex | ||
| 3870 | { $_[0]->{searchRegex} } | ||
| 3871 | sub searchLanguage | ||
| 3872 | { $_[0]->{searchLanguage} } | ||
| 3873 | } | ||
| 3874 | |||
| 3875 | { package Games::Axmud::OtherWin::ClientConsole; | ||
| 3876 | |||
| 3877 | use strict; | ||
| 3878 | use warnings; | ||
| 3879 | # use diagnostics; | ||
| 3880 | |||
| 3881 | use Glib qw(TRUE FALSE); | ||
| 3882 | |||
| 3883 | our @ISA = qw( | ||
| 3884 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 3885 | Games::Axmud | ||
| 3886 | ); | ||
| 3887 | |||
| 3888 | ################## | ||
| 3889 | # Constructors | ||
| 3890 | |||
| 3891 | sub new { | ||
| 3892 | |||
| 3893 | # Called by GA::Generic::Win->createFreeWin | ||
| 3894 | # Creates a new instance of the Client Console window, which can display system messages | ||
| 3895 | # when there is no session running | ||
| 3896 | # | ||
| 3897 | # Expected arguments | ||
| 3898 | # $number - Unique number for this window object | ||
| 3899 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 3900 | # should be created | ||
| 3901 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 3902 | # 'free' window object. When this window opens/closes, the owner is | ||
| 3903 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 3904 | # functions | ||
| 3905 | # | ||
| 3906 | # Optional arguments | ||
| 3907 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 3908 | # calling function didn't specify a session and $owner's ->session IV | ||
| 3909 | # is also 'undef' | ||
| 3910 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 3911 | # $editObj - Ignored if set | ||
| 3912 | # $tempFlag - Ignored if set | ||
| 3913 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 3914 | # particular 'other' window; set to an empty hash if not required | ||
| 3915 | # - This type of window object recognises these initialisation settings: | ||
| 3916 | # | ||
| 3917 | # ... | ||
| 3918 | # | ||
| 3919 | # Return values | ||
| 3920 | # 'undef' on improper arguments | ||
| 3921 | # Blessed reference to the newly-created object on success | ||
| 3922 | |||
| 3923 | my ( | ||
| 3924 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 3925 | %configHash, | ||
| 3926 | ) = @_; | ||
| 3927 | |||
| 3928 | # Check for improper arguments | ||
| 3929 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 3930 | |||
| 3931 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3932 | } | ||
| 3933 | |||
| 3934 | # Only one Client Console window can be open at a time | ||
| 3935 | if ($axmud::CLIENT->consoleWin) { | ||
| 3936 | |||
| 3937 | $axmud::CLIENT->consoleWin->restoreFocus(); | ||
| 3938 | return undef; | ||
| 3939 | } | ||
| 3940 | |||
| 3941 | # Setup | ||
| 3942 | my $self = { | ||
| 3943 | _objName => 'other_win_' . $number, | ||
| 3944 | _objClass => $class, | ||
| 3945 | _parentFile => undef, # No parent file object | ||
| 3946 | _parentWorld => undef, # No parent file object | ||
| 3947 | _privFlag => TRUE, # All IVs are private | ||
| 3948 | |||
| 3949 | # Standard window object IVs | ||
| 3950 | # -------------------------- | ||
| 3951 | |||
| 3952 | # Unique number for this window object | ||
| 3953 | number => $number, | ||
| 3954 | # The window category - 'grid' or 'free' | ||
| 3955 | winCategory => 'free', | ||
| 3956 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 3957 | winType => 'other', | ||
| 3958 | # A name for the window (for some 'free' windows, the same as the window type) | ||
| 3959 | winName => 'console', | ||
| 3960 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 3961 | workspaceObj => $workspaceObj, | ||
| 3962 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 3963 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 3964 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 3965 | owner => $owner, | ||
| 3966 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 3967 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 3968 | session => $session, | ||
| 3969 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 3970 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 3971 | # displayed in a 'dialogue' window) | ||
| 3972 | pseudoCmdMode => 'win_error', | ||
| 3973 | |||
| 3974 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 3975 | # parent 'main' window's Gtk3::Window | ||
| 3976 | # The code should use this IV when it wants to do something to the window itself | ||
| 3977 | # (minimise it, make it active, etc) | ||
| 3978 | winWidget => undef, | ||
| 3979 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 3980 | # the parent GA::Table::PseudoWin table object | ||
| 3981 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 3982 | # window itself | ||
| 3983 | winBox => undef, | ||
| 3984 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 3985 | # FALSE if not | ||
| 3986 | enabledFlag => FALSE, | ||
| 3987 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 3988 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 3989 | visibleFlag => TRUE, | ||
| 3990 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 3991 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 3992 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 3993 | childFreeWinHash => {}, | ||
| 3994 | |||
| 3995 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 3996 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 3997 | # area) | ||
| 3998 | packingBox => undef, # Gtk3::VBox | ||
| 3999 | |||
| 4000 | # Standard IVs for 'free' windows | ||
| 4001 | |||
| 4002 | # The window's default size, in pixels | ||
| 4003 | widthPixels => 600, | ||
| 4004 | heightPixels => 300, | ||
| 4005 | # Default border/item spacing sizes used in the window, in pixels | ||
| 4006 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 4007 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 4008 | |||
| 4009 | # A string to use as the window title. If 'undef', a generic title is used | ||
| 4010 | title => $axmud::SCRIPT . ' client console', | ||
| 4011 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 4012 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 4013 | # name and type. Set to an empty hash if not required | ||
| 4014 | configHash => {%configHash}, | ||
| 4015 | |||
| 4016 | # IVs for this window | ||
| 4017 | textView => undef, # Gtk3::TextView | ||
| 4018 | buffer => undef, # Gtk3::TextBuffer | ||
| 4019 | }; | ||
| 4020 | |||
| 4021 | # Bless the object into existence | ||
| 4022 | bless $self, $class; | ||
| 4023 | |||
| 4024 | return $self; | ||
| 4025 | } | ||
| 4026 | |||
| 4027 | ################## | ||
| 4028 | # Methods | ||
| 4029 | |||
| 4030 | # Standard window object functions | ||
| 4031 | |||
| 4032 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 4033 | |||
| 4034 | sub winEnable { | ||
| 4035 | |||
| 4036 | # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup | ||
| 4037 | # After the Gtk3::Window has been setup and moved into position, makes it visible | ||
| 4038 | # | ||
| 4039 | # Expected arguments | ||
| 4040 | # (none besides $self) | ||
| 4041 | # | ||
| 4042 | # Return values | ||
| 4043 | # 'undef' on improper arguments | ||
| 4044 | # 1 on success | ||
| 4045 | |||
| 4046 | my ($self, $check) = @_; | ||
| 4047 | |||
| 4048 | # Local variables | ||
| 4049 | my @list; | ||
| 4050 | |||
| 4051 | # Check for improper arguments | ||
| 4052 | if (defined $check) { | ||
| 4053 | |||
| 4054 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_); | ||
| 4055 | } | ||
| 4056 | |||
| 4057 | # Make the window appear on the desktop | ||
| 4058 | $self->winShowAll($self->_objClass . '->winEnable'); | ||
| 4059 | $self->ivPoke('enabledFlag', TRUE); | ||
| 4060 | |||
| 4061 | # This type of window is unique (only one can be open at any time); inform the GA::Client | ||
| 4062 | # it has opened | ||
| 4063 | $axmud::CLIENT->set_consoleWin($self); | ||
| 4064 | |||
| 4065 | # If any system messages have been stored, we can display them now | ||
| 4066 | @list = $axmud::CLIENT->systemMsgList; | ||
| 4067 | if (@list) { | ||
| 4068 | |||
| 4069 | do { | ||
| 4070 | |||
| 4071 | my ($type, $msg); | ||
| 4072 | |||
| 4073 | $type = shift @list; | ||
| 4074 | $msg = shift @list; | ||
| 4075 | |||
| 4076 | $self->update($type, $msg); | ||
| 4077 | |||
| 4078 | } until (! @list); | ||
| 4079 | } | ||
| 4080 | |||
| 4081 | # Each system message is displayed here only once | ||
| 4082 | $axmud::CLIENT->reset_systemMsg(); | ||
| 4083 | |||
| 4084 | return 1; | ||
| 4085 | } | ||
| 4086 | |||
| 4087 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 4088 | |||
| 4089 | sub winDestroy { | ||
| 4090 | |||
| 4091 | # Can be called by anything | ||
| 4092 | # Updates IVs | ||
| 4093 | # | ||
| 4094 | # Expected arguments | ||
| 4095 | # (none besides $self) | ||
| 4096 | # | ||
| 4097 | # Return values | ||
| 4098 | # 'undef' on improper arguments, if the window can't be destroyed or if it has already | ||
| 4099 | # been destroyed | ||
| 4100 | # 1 on success | ||
| 4101 | |||
| 4102 | my ($self, $check) = @_; | ||
| 4103 | |||
| 4104 | # Check for improper arguments | ||
| 4105 | if (defined $check) { | ||
| 4106 | |||
| 4107 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_); | ||
| 4108 | } | ||
| 4109 | |||
| 4110 | if (! $self->winBox) { | ||
| 4111 | |||
| 4112 | # Window already destroyed in a previous call to this function | ||
| 4113 | return undef; | ||
| 4114 | } | ||
| 4115 | |||
| 4116 | # Close any 'free' windows for which this window is a parent | ||
| 4117 | foreach my $winObj ($self->ivValues('childFreeWinHash')) { | ||
| 4118 | |||
| 4119 | $winObj->winDestroy(); | ||
| 4120 | } | ||
| 4121 | |||
| 4122 | # Destroy the Gtk3::Window | ||
| 4123 | eval { $self->winBox->destroy(); }; | ||
| 4124 | if ($@) { | ||
| 4125 | |||
| 4126 | # Window can't be destroyed | ||
| 4127 | return undef; | ||
| 4128 | |||
| 4129 | } else { | ||
| 4130 | |||
| 4131 | $self->ivUndef('winWidget'); | ||
| 4132 | $self->ivUndef('winBox'); | ||
| 4133 | } | ||
| 4134 | |||
| 4135 | # Inform the owner and the desktop object of this 'free' window's demise | ||
| 4136 | $axmud::CLIENT->desktopObj->del_freeWin($self); | ||
| 4137 | if ($self->owner) { | ||
| 4138 | |||
| 4139 | $self->owner->del_childFreeWin($self); | ||
| 4140 | } | ||
| 4141 | |||
| 4142 | # This type of window is unique (only one can be open at any time); inform the GA::Client | ||
| 4143 | # it has closed | ||
| 4144 | $axmud::CLIENT->set_consoleWin(); | ||
| 4145 | |||
| 4146 | return 1; | ||
| 4147 | } | ||
| 4148 | |||
| 4149 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 4150 | |||
| 4151 | sub drawWidgets { | ||
| 4152 | |||
| 4153 | # Called by $self->winSetup | ||
| 4154 | # Sets up the Client Console window with its standard widgets | ||
| 4155 | # | ||
| 4156 | # Expected arguments | ||
| 4157 | # (none besides $self) | ||
| 4158 | # | ||
| 4159 | # Return values | ||
| 4160 | # 'undef' on improper arguments | ||
| 4161 | # 1 otherwise | ||
| 4162 | |||
| 4163 | my ($self, $check) = @_; | ||
| 4164 | |||
| 4165 | # Check for improper arguments | ||
| 4166 | if (defined $check) { | ||
| 4167 | |||
| 4168 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 4169 | } | ||
| 4170 | |||
| 4171 | # Create a packing box | ||
| 4172 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 4173 | $self->winBox->add($packingBox); | ||
| 4174 | $packingBox->set_border_width(0); | ||
| 4175 | |||
| 4176 | # Create a textview | ||
| 4177 | my $scroller = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 4178 | $packingBox->pack_start($scroller, TRUE, TRUE, 0); | ||
| 4179 | $scroller->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 4180 | $scroller->set_policy('automatic', 'automatic'); | ||
| 4181 | $scroller->set_border_width(5); | ||
| 4182 | |||
| 4183 | # Use a textview with default colours/fonts | ||
| 4184 | my $textView = Gtk3::TextView->new(); | ||
| 4185 | $scroller->add($textView); | ||
| 4186 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 4187 | $textView->set_buffer($buffer); | ||
| 4188 | $textView->set_editable(FALSE); | ||
| 4189 | $textView->set_cursor_visible(FALSE); | ||
| 4190 | $textView->set_can_focus(FALSE); | ||
| 4191 | $textView->set_wrap_mode('word-char'); # Wrap words if possible, characters if not | ||
| 4192 | $axmud::CLIENT->desktopObj->setTextViewStyle('main', $textView); | ||
| 4193 | |||
| 4194 | # Create a mark at the end of the buffer, with right gravity, so that whenever text is | ||
| 4195 | # inserted, we can scroll to that mark (and the mark stays at the end) | ||
| 4196 | my $endMark = $buffer->create_mark('end', $buffer->get_end_iter(), FALSE); | ||
| 4197 | |||
| 4198 | # Update IVs | ||
| 4199 | $self->ivPoke('packingBox', $packingBox); | ||
| 4200 | $self->ivPoke('textView', $textView); | ||
| 4201 | $self->ivPoke('buffer', $buffer); | ||
| 4202 | |||
| 4203 | # Create some colour tags, so that system messages can be displayed in their usual colours | ||
| 4204 | $self->createColourTags(); | ||
| 4205 | |||
| 4206 | return 1; | ||
| 4207 | } | ||
| 4208 | |||
| 4209 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 4210 | |||
| 4211 | # ->signal_connects | ||
| 4212 | |||
| 4213 | # Other functions | ||
| 4214 | |||
| 4215 | sub createColourTags { | ||
| 4216 | |||
| 4217 | # Called by $self->drawWidgets | ||
| 4218 | # Create some Gtk3::TextTags, so that system messages can be shown in their usual colours | ||
| 4219 | # | ||
| 4220 | # Expected arguments | ||
| 4221 | # (none besides $self) | ||
| 4222 | # | ||
| 4223 | # Return values | ||
| 4224 | # 'undef' on improper arguments | ||
| 4225 | # 1 otherwise | ||
| 4226 | |||
| 4227 | my ($self, $check) = @_; | ||
| 4228 | |||
| 4229 | # Check for improper arguments | ||
| 4230 | if (defined $check) { | ||
| 4231 | |||
| 4232 | return $axmud::CLIENT->writeImproper($self->_objClass . '->update', @_); | ||
| 4233 | } | ||
| 4234 | |||
| 4235 | $self->buffer->create_tag( | ||
| 4236 | 'system', | ||
| 4237 | 'foreground' | ||
| 4238 | => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowSystemTextColour), | ||
| 4239 | ); | ||
| 4240 | |||
| 4241 | $self->buffer->create_tag( | ||
| 4242 | 'error', | ||
| 4243 | 'foreground' | ||
| 4244 | => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowErrorColour), | ||
| 4245 | ); | ||
| 4246 | |||
| 4247 | $self->buffer->create_tag( | ||
| 4248 | 'warning', | ||
| 4249 | 'foreground' | ||
| 4250 | => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowWarningColour), | ||
| 4251 | ); | ||
| 4252 | |||
| 4253 | $self->buffer->create_tag( | ||
| 4254 | 'debug', | ||
| 4255 | 'foreground' | ||
| 4256 | => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowDebugColour), | ||
| 4257 | ); | ||
| 4258 | |||
| 4259 | $self->buffer->create_tag( | ||
| 4260 | 'improper', | ||
| 4261 | 'foreground' | ||
| 4262 | => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowImproperColour), | ||
| 4263 | ); | ||
| 4264 | |||
| 4265 | return 1; | ||
| 4266 | } | ||
| 4267 | |||
| 4268 | sub update { | ||
| 4269 | |||
| 4270 | # Called by $self->winEnable and $axmud::CLIENT->add_systemMsg | ||
| 4271 | # Adds a system message to the window's textview | ||
| 4272 | # | ||
| 4273 | # Expected arguments | ||
| 4274 | # $type - The type of message (which determines the colour in which it's displayed) - | ||
| 4275 | # 'system', 'error', 'warning', 'debug' or 'improper'. If an invalid value or | ||
| 4276 | # 'undef', then the error message colour is used | ||
| 4277 | # $msg - The message to display. If 'undef' (for some reason), nothing is displayed | ||
| 4278 | # | ||
| 4279 | # Return values | ||
| 4280 | # 'undef' on improper arguments | ||
| 4281 | # 1 otherwise | ||
| 4282 | |||
| 4283 | my ($self, $type, $msg, $check) = @_; | ||
| 4284 | |||
| 4285 | # Check for improper arguments | ||
| 4286 | if (defined $check) { | ||
| 4287 | |||
| 4288 | return $axmud::CLIENT->writeImproper($self->_objClass . '->update', @_); | ||
| 4289 | } | ||
| 4290 | |||
| 4291 | if ($self->enabledFlag && defined $msg) { | ||
| 4292 | |||
| 4293 | if ( | ||
| 4294 | ! defined $type | ||
| 4295 | || ( | ||
| 4296 | $type ne 'system' && $type ne 'error' && $type ne 'warning' && $type ne 'debug' | ||
| 4297 | && $type ne 'improper' | ||
| 4298 | ) | ||
| 4299 | ) { | ||
| 4300 | $type = 'error'; | ||
| 4301 | } | ||
| 4302 | |||
| 4303 | # Only one newline character at the end of the message | ||
| 4304 | chomp $msg; | ||
| 4305 | $self->buffer->insert_with_tags_by_name( | ||
| 4306 | $self->buffer->get_end_iter(), | ||
| 4307 | $msg . "\n", | ||
| 4308 | $type, | ||
| 4309 | ); | ||
| 4310 | |||
| 4311 | # Scroll to the bottom | ||
| 4312 | $self->textView->scroll_to_mark($self->buffer->get_mark('end'), 0.0, TRUE, 0, 0); | ||
| 4313 | |||
| 4314 | $self->winShowAll($self->_objClass . '->update'); | ||
| 4315 | } | ||
| 4316 | |||
| 4317 | return 1; | ||
| 4318 | } | ||
| 4319 | |||
| 4320 | ################## | ||
| 4321 | # Accessors - set | ||
| 4322 | |||
| 4323 | ################## | ||
| 4324 | # Accessors - get | ||
| 4325 | |||
| 4326 | sub textView | ||
| 4327 | { $_[0]->{textView} } | ||
| 4328 | sub buffer | ||
| 4329 | { $_[0]->{buffer} } | ||
| 4330 | } | ||
| 4331 | |||
| 4332 | { package Games::Axmud::OtherWin::LabelDelete; | ||
| 4333 | |||
| 4334 | use strict; | ||
| 4335 | use warnings; | ||
| 4336 | # use diagnostics; | ||
| 4337 | |||
| 4338 | use Glib qw(TRUE FALSE); | ||
| 4339 | |||
| 4340 | our @ISA = qw( | ||
| 4341 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 4342 | Games::Axmud | ||
| 4343 | ); | ||
| 4344 | |||
| 4345 | ################## | ||
| 4346 | # Constructors | ||
| 4347 | |||
| 4348 | sub new { | ||
| 4349 | |||
| 4350 | # Called by GA::Generic::Win->createFreeWin | ||
| 4351 | # Creates a new instance of the Label Deletion window (an 'other' window). The window | ||
| 4352 | # contains a simple list in which the user can select labels to delete | ||
| 4353 | # | ||
| 4354 | # Expected arguments | ||
| 4355 | # $number - Unique number for this window object | ||
| 4356 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 4357 | # should be created | ||
| 4358 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 4359 | # 'free' window object. When this window opens/closes, the owner is | ||
| 4360 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 4361 | # functions | ||
| 4362 | # | ||
| 4363 | # Optional arguments | ||
| 4364 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 4365 | # calling function didn't specify a session and $owner's ->session IV | ||
| 4366 | # is also 'undef' | ||
| 4367 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 4368 | # $editObj - Ignored if set | ||
| 4369 | # $tempFlag - Ignored if set | ||
| 4370 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 4371 | # particular 'other' window; set to an empty hash if not required | ||
| 4372 | # - This type of window object recognises these initialisation settings: | ||
| 4373 | # | ||
| 4374 | # ... | ||
| 4375 | # | ||
| 4376 | # Return values | ||
| 4377 | # 'undef' on improper arguments | ||
| 4378 | # Blessed reference to the newly-created object on success | ||
| 4379 | |||
| 4380 | my ( | ||
| 4381 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 4382 | %configHash, | ||
| 4383 | ) = @_; | ||
| 4384 | |||
| 4385 | # Check for improper arguments | ||
| 4386 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 4387 | |||
| 4388 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 4389 | } | ||
| 4390 | |||
| 4391 | # Setup | ||
| 4392 | my $self = { | ||
| 4393 | _objName => 'other_win_' . $number, | ||
| 4394 | _objClass => $class, | ||
| 4395 | _parentFile => undef, # No parent file object | ||
| 4396 | _parentWorld => undef, # No parent file object | ||
| 4397 | _privFlag => TRUE, # All IVs are private | ||
| 4398 | |||
| 4399 | # Standard window object IVs | ||
| 4400 | # -------------------------- | ||
| 4401 | |||
| 4402 | # Unique number for this window object | ||
| 4403 | number => $number, | ||
| 4404 | # The window category - 'grid' or 'free' | ||
| 4405 | winCategory => 'free', | ||
| 4406 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 4407 | winType => 'other', | ||
| 4408 | # A name for the window (can be unique to this type of window object, or can be the | ||
| 4409 | # same as ->winType) | ||
| 4410 | winName => 'quick_label_delete', | ||
| 4411 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 4412 | workspaceObj => $workspaceObj, | ||
| 4413 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 4414 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 4415 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 4416 | owner => $owner, | ||
| 4417 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 4418 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 4419 | session => $session, | ||
| 4420 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 4421 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 4422 | # displayed in a 'dialogue' window) | ||
| 4423 | pseudoCmdMode => 'win_error', | ||
| 4424 | |||
| 4425 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 4426 | # parent 'main' window's Gtk3::Window | ||
| 4427 | # The code should use this IV when it wants to do something to the window itself | ||
| 4428 | # (minimise it, make it active, etc) | ||
| 4429 | winWidget => undef, | ||
| 4430 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 4431 | # the parent GA::Table::PseudoWin table object | ||
| 4432 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 4433 | # window itself | ||
| 4434 | winBox => undef, | ||
| 4435 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 4436 | # FALSE if not | ||
| 4437 | enabledFlag => FALSE, | ||
| 4438 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 4439 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 4440 | visibleFlag => TRUE, | ||
| 4441 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 4442 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 4443 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 4444 | childFreeWinHash => {}, | ||
| 4445 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 4446 | # window is informed via a call to $self->del_childFreeWin | ||
| 4447 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 4448 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 4449 | # this hash; a hash in the form | ||
| 4450 | # $childDestroyHash{unique_number} = list_reference | ||
| 4451 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 4452 | # reference to a list in groups of 2, in the form | ||
| 4453 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 4454 | childDestroyHash => {}, | ||
| 4455 | |||
| 4456 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 4457 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 4458 | # area) | ||
| 4459 | packingBox => undef, | ||
| 4460 | |||
| 4461 | # Standard IVs for 'free' windows | ||
| 4462 | |||
| 4463 | # The window's default size, in pixels | ||
| 4464 | widthPixels => $axmud::CLIENT->constFreeWinWidth, | ||
| 4465 | heightPixels => $axmud::CLIENT->constFreeWinHeight, | ||
| 4466 | # Default border/item spacing sizes used in the window, in pixels | ||
| 4467 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 4468 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 4469 | |||
| 4470 | # A string to use as the window title | ||
| 4471 | title => 'Label deletion window', | ||
| 4472 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 4473 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 4474 | # name and type. Set to an empty hash if not required | ||
| 4475 | configHash => {%configHash}, | ||
| 4476 | |||
| 4477 | # IVs for this type of window | ||
| 4478 | # ... | ||
| 4479 | }; | ||
| 4480 | |||
| 4481 | # Bless the object into existence | ||
| 4482 | bless $self, $class; | ||
| 4483 | |||
| 4484 | return $self; | ||
| 4485 | } | ||
| 4486 | |||
| 4487 | ################## | ||
| 4488 | # Methods | ||
| 4489 | |||
| 4490 | # Standard window object functions | ||
| 4491 | |||
| 4492 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 4493 | |||
| 4494 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 4495 | |||
| 4496 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 4497 | |||
| 4498 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 4499 | |||
| 4500 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 4501 | |||
| 4502 | sub drawWidgets { | ||
| 4503 | |||
| 4504 | # Called by $self->winSetup | ||
| 4505 | # Sets up the Gtk3::Window by drawing the window's widgets | ||
| 4506 | # | ||
| 4507 | # Expected arguments | ||
| 4508 | # (none besides $self) | ||
| 4509 | # | ||
| 4510 | # Return values | ||
| 4511 | # 'undef' on improper arguments | ||
| 4512 | # 1 otherwise | ||
| 4513 | |||
| 4514 | my ($self, $check) = @_; | ||
| 4515 | |||
| 4516 | # Local variables | ||
| 4517 | my @columnList; | ||
| 4518 | |||
| 4519 | # Check for improper arguments | ||
| 4520 | if (defined $check) { | ||
| 4521 | |||
| 4522 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 4523 | } | ||
| 4524 | |||
| 4525 | # Create a packing box | ||
| 4526 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 4527 | $self->winBox->add($packingBox); | ||
| 4528 | $packingBox->set_border_width(0); | ||
| 4529 | |||
| 4530 | # Update IVs immediately, for the benefit of any called functions | ||
| 4531 | $self->ivPoke('packingBox', $packingBox); | ||
| 4532 | |||
| 4533 | # Create an image on the left | ||
| 4534 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 4535 | $packingBox->pack_start($hBox, TRUE, TRUE, 0); | ||
| 4536 | |||
| 4537 | my $vBox = Gtk3::VBox->new(FALSE, 0); | ||
| 4538 | $hBox->pack_start($vBox, FALSE, FALSE, 0); | ||
| 4539 | |||
| 4540 | my $frame = Gtk3::Frame->new(undef); | ||
| 4541 | $vBox->pack_start($frame, FALSE, FALSE, 0); | ||
| 4542 | $frame->set_size_request(64, 64); | ||
| 4543 | $frame->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 4544 | |||
| 4545 | my $image = Gtk3::Image->new_from_file($axmud::CLIENT->getDialogueIcon()); | ||
| 4546 | $frame->add($image); | ||
| 4547 | |||
| 4548 | # Add a simple list and some buttons on the right | ||
| 4549 | my $vBox2 = Gtk3::VBox->new(FALSE, 0); | ||
| 4550 | $hBox->pack_start($vBox2, TRUE, TRUE, $self->spacingPixels); | ||
| 4551 | |||
| 4552 | @columnList = ( | ||
| 4553 | 'Delete', 'bool', | ||
| 4554 | 'Region', 'text', | ||
| 4555 | '#', 'int', | ||
| 4556 | 'Label', 'text', | ||
| 4557 | ); | ||
| 4558 | |||
| 4559 | my $frame2 = Gtk3::Frame->new(undef); | ||
| 4560 | $vBox2->pack_start($frame2, TRUE, TRUE, 0); | ||
| 4561 | $frame2->set_border_width(0); | ||
| 4562 | |||
| 4563 | my $scroller = Gtk3::ScrolledWindow->new(); | ||
| 4564 | $frame2->add($scroller); | ||
| 4565 | $scroller->set_shadow_type('none'); | ||
| 4566 | $scroller->set_policy('automatic', 'automatic'); | ||
| 4567 | $scroller->set_border_width(0); | ||
| 4568 | |||
| 4569 | my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList); | ||
| 4570 | $scroller->add($slWidget); | ||
| 4571 | |||
| 4572 | # Add a horizontal strip with several buttons | ||
| 4573 | # Create an image on the left | ||
| 4574 | my $hBox2 = Gtk3::HBox->new(FALSE, 0); | ||
| 4575 | $vBox2->pack_start($hBox2, FALSE, FALSE, $self->spacingPixels); | ||
| 4576 | |||
| 4577 | my $button = Gtk3::Button->new('Select all'); | ||
| 4578 | $hBox2->pack_start($button, FALSE, FALSE, 0); | ||
| 4579 | $button->get_child->set_width_chars(12); | ||
| 4580 | $button->signal_connect('clicked' => sub { | ||
| 4581 | |||
| 4582 | foreach my $listRef (@{$slWidget->{data}}) { | ||
| 4583 | |||
| 4584 | $$listRef[0] = TRUE; | ||
| 4585 | } | ||
| 4586 | }); | ||
| 4587 | |||
| 4588 | my $button2 = Gtk3::Button->new('Select none'); | ||
| 4589 | $hBox2->pack_start($button2, FALSE, FALSE, $self->borderPixels); | ||
| 4590 | $button2->get_child->set_width_chars(12); | ||
| 4591 | $button2->signal_connect('clicked' => sub { | ||
| 4592 | |||
| 4593 | foreach my $listRef (@{$slWidget->{data}}) { | ||
| 4594 | |||
| 4595 | $$listRef[0] = FALSE; | ||
| 4596 | } | ||
| 4597 | }); | ||
| 4598 | |||
| 4599 | my $button3 = Gtk3::Button->new('Close window'); | ||
| 4600 | $hBox2->pack_end($button3, FALSE, FALSE, 0); | ||
| 4601 | $button3->get_child->set_width_chars(12); | ||
| 4602 | $button3->signal_connect('clicked' => sub { | ||
| 4603 | |||
| 4604 | $self->winDestroy(); | ||
| 4605 | }); | ||
| 4606 | |||
| 4607 | my $button4 = Gtk3::Button->new('Delete selected labels'); | ||
| 4608 | $hBox2->pack_end($button4, FALSE, FALSE, $self->borderPixels); | ||
| 4609 | $button4->get_child->set_width_chars(20); | ||
| 4610 | $button4->signal_connect('clicked' => sub { | ||
| 4611 | |||
| 4612 | my ( | ||
| 4613 | @deleteList, | ||
| 4614 | %regionmapHash, | ||
| 4615 | ); | ||
| 4616 | |||
| 4617 | # Import the hash of regionmaps for quick lookup | ||
| 4618 | %regionmapHash = $self->session->worldModelObj->regionmapHash; | ||
| 4619 | |||
| 4620 | # Compile a list of labels to delete | ||
| 4621 | foreach my $listRef (@{$slWidget->{data}}) { | ||
| 4622 | |||
| 4623 | my ($deleteFlag, $regionName, $labelNum, $regionmapObj, $labelObj); | ||
| 4624 | |||
| 4625 | ($deleteFlag, $regionName, $labelNum) = @$listRef; | ||
| 4626 | $regionmapObj = $regionmapHash{$regionName}; | ||
| 4627 | |||
| 4628 | if ($deleteFlag && $regionmapObj) { | ||
| 4629 | |||
| 4630 | $labelObj = $regionmapObj->ivShow('gridLabelHash', $labelNum); | ||
| 4631 | if ($labelObj) { | ||
| 4632 | |||
| 4633 | push (@deleteList, $labelObj); | ||
| 4634 | } | ||
| 4635 | } | ||
| 4636 | } | ||
| 4637 | |||
| 4638 | # Delete the selected labels. The TRUE argument means to update automapper windows now | ||
| 4639 | $self->session->worldModelObj->deleteLabels(TRUE, @deleteList); | ||
| 4640 | |||
| 4641 | # Refresh the simple list | ||
| 4642 | $self->refreshList($slWidget); | ||
| 4643 | }); | ||
| 4644 | |||
| 4645 | # Popuplate the simple list | ||
| 4646 | $self->refreshList($slWidget); | ||
| 4647 | |||
| 4648 | return 1; | ||
| 4649 | } | ||
| 4650 | |||
| 4651 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 4652 | |||
| 4653 | # ->signal_connects | ||
| 4654 | |||
| 4655 | # Other functions | ||
| 4656 | |||
| 4657 | sub refreshList { | ||
| 4658 | |||
| 4659 | # Called by $self->drawWidgets | ||
| 4660 | # Populates the simple list widget | ||
| 4661 | # | ||
| 4662 | # Expected arguments | ||
| 4663 | # $slWidget - The GA::Obj::SimpleList widget to populate | ||
| 4664 | # | ||
| 4665 | # Return values | ||
| 4666 | # 'undef' on improper arguments | ||
| 4667 | # 1 otherwise | ||
| 4668 | |||
| 4669 | my ($self, $slWidget, $check) = @_; | ||
| 4670 | |||
| 4671 | # Local variables | ||
| 4672 | my @dataList; | ||
| 4673 | |||
| 4674 | # Check for improper arguments | ||
| 4675 | if (! defined $slWidget || defined $check) { | ||
| 4676 | |||
| 4677 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshList', @_); | ||
| 4678 | } | ||
| 4679 | |||
| 4680 | foreach my $regionmapObj ( | ||
| 4681 | sort {lc($a->name) cmp lc($b->name)} | ||
| 4682 | ($self->session->worldModelObj->ivValues('regionmapHash')) | ||
| 4683 | ) { | ||
| 4684 | my (%localHash, %modHash); | ||
| 4685 | |||
| 4686 | # Import the hash for speed | ||
| 4687 | %localHash = $regionmapObj->gridLabelHash; | ||
| 4688 | # When sorting alphabetically, remove non-alphanumeric characters so that '(Shop)' | ||
| 4689 | # doesn't appear in the list before 'Shop' | ||
| 4690 | foreach my $labelObj (values %localHash) { | ||
| 4691 | |||
| 4692 | my $modText = $labelObj->name; | ||
| 4693 | $modText =~ s/[^[:word:]\s]//g; | ||
| 4694 | $modHash{$labelObj->number} = lc($modText); | ||
| 4695 | } | ||
| 4696 | |||
| 4697 | foreach my $labelObj ( | ||
| 4698 | sort {$modHash{$a->number} cmp $modHash{$b->number}} (values %localHash) | ||
| 4699 | ) { | ||
| 4700 | push (@dataList, | ||
| 4701 | [ | ||
| 4702 | FALSE, | ||
| 4703 | $regionmapObj->name, | ||
| 4704 | $labelObj->number, | ||
| 4705 | $labelObj->name, | ||
| 4706 | ], | ||
| 4707 | ); | ||
| 4708 | } | ||
| 4709 | } | ||
| 4710 | |||
| 4711 | # Reset the simple list | ||
| 4712 | if (! @dataList) { | ||
| 4713 | |||
| 4714 | # Replacement data list is empty | ||
| 4715 | @{$slWidget->{data}} = (); | ||
| 4716 | |||
| 4717 | } else { | ||
| 4718 | |||
| 4719 | @{$slWidget->{data}} = @dataList; | ||
| 4720 | } | ||
| 4721 | |||
| 4722 | return 1; | ||
| 4723 | } | ||
| 4724 | |||
| 4725 | ################## | ||
| 4726 | # Accessors - set | ||
| 4727 | |||
| 4728 | ################## | ||
| 4729 | # Accessors - get | ||
| 4730 | } | ||
| 4731 | |||
| 4732 | { package Games::Axmud::OtherWin::McpSimpleEdit; | ||
| 4733 | |||
| 4734 | use strict; | ||
| 4735 | use warnings; | ||
| 4736 | # use diagnostics; | ||
| 4737 | |||
| 4738 | use Glib qw(TRUE FALSE); | ||
| 4739 | |||
| 4740 | our @ISA = qw( | ||
| 4741 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 4742 | Games::Axmud | ||
| 4743 | ); | ||
| 4744 | |||
| 4745 | ################## | ||
| 4746 | # Constructors | ||
| 4747 | |||
| 4748 | sub new { | ||
| 4749 | |||
| 4750 | # Called by GA::Mcp::SimpleEdit->msg | ||
| 4751 | # Creates a new instance of the MCP Simple Edit window (an 'other' window). The window | ||
| 4752 | # contains a textview in which the user can type text, and some widgets that specify what | ||
| 4753 | # should be done with the text | ||
| 4754 | # | ||
| 4755 | # Expected arguments | ||
| 4756 | # $number - Unique number for this window object | ||
| 4757 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 4758 | # should be created | ||
| 4759 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 4760 | # 'free' window object. When this window opens/closes, the owner is | ||
| 4761 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 4762 | # functions | ||
| 4763 | # | ||
| 4764 | # Optional arguments | ||
| 4765 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 4766 | # calling function didn't specify a session and $owner's ->session IV | ||
| 4767 | # is also 'undef' | ||
| 4768 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 4769 | # $editObj - Ignored if set | ||
| 4770 | # $tempFlag - Ignored if set | ||
| 4771 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 4772 | # particular 'other' window; set to an empty hash if not required | ||
| 4773 | # - This type of window object recognises these initialisation settings: | ||
| 4774 | # | ||
| 4775 | # 'mcp_reference' - Supplied by the server's MCP message; a machine- | ||
| 4776 | # readable string that identifies the text to be sent back to the | ||
| 4777 | # server | ||
| 4778 | # 'mcp_name' - Supplied by the server's MCP message; a human-readable | ||
| 4779 | # string to show the user what text is being edited | ||
| 4780 | # 'mcp_content' - Supplied by the server's MCP message; the text to | ||
| 4781 | # edit; a string containing one or more lines joined with single | ||
| 4782 | # newline characters | ||
| 4783 | # 'mcp_type' - The type of text being edited - 'string-list' or | ||
| 4784 | # 'moo-code' for multiple lines (this window isn't called for | ||
| 4785 | # 'string') | ||
| 4786 | # | ||
| 4787 | # Return values | ||
| 4788 | # 'undef' on improper arguments | ||
| 4789 | # Blessed reference to the newly-created object on success | ||
| 4790 | |||
| 4791 | my ( | ||
| 4792 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 4793 | %configHash, | ||
| 4794 | ) = @_; | ||
| 4795 | |||
| 4796 | # Check for improper arguments | ||
| 4797 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 4798 | |||
| 4799 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 4800 | } | ||
| 4801 | |||
| 4802 | # Setup | ||
| 4803 | my $self = { | ||
| 4804 | _objName => 'other_win_' . $number, | ||
| 4805 | _objClass => $class, | ||
| 4806 | _parentFile => undef, # No parent file object | ||
| 4807 | _parentWorld => undef, # No parent file object | ||
| 4808 | _privFlag => TRUE, # All IVs are private | ||
| 4809 | |||
| 4810 | # Standard window object IVs | ||
| 4811 | # -------------------------- | ||
| 4812 | |||
| 4813 | # Unique number for this window object | ||
| 4814 | number => $number, | ||
| 4815 | # The window category - 'grid' or 'free' | ||
| 4816 | winCategory => 'free', | ||
| 4817 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 4818 | winType => 'other', | ||
| 4819 | # A name for the window (can be unique to this type of window object, or can be the | ||
| 4820 | # same as ->winType) | ||
| 4821 | winName => 'mcp_simple_edit', | ||
| 4822 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 4823 | workspaceObj => $workspaceObj, | ||
| 4824 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 4825 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 4826 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 4827 | owner => $owner, | ||
| 4828 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 4829 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 4830 | session => $session, | ||
| 4831 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 4832 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 4833 | # displayed in a 'dialogue' window) | ||
| 4834 | pseudoCmdMode => 'win_error', | ||
| 4835 | |||
| 4836 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 4837 | # parent 'main' window's Gtk3::Window | ||
| 4838 | # The code should use this IV when it wants to do something to the window itself | ||
| 4839 | # (minimise it, make it active, etc) | ||
| 4840 | winWidget => undef, | ||
| 4841 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 4842 | # the parent GA::Table::PseudoWin table object | ||
| 4843 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 4844 | # window itself | ||
| 4845 | winBox => undef, | ||
| 4846 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 4847 | # FALSE if not | ||
| 4848 | enabledFlag => FALSE, | ||
| 4849 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 4850 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 4851 | visibleFlag => TRUE, | ||
| 4852 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 4853 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 4854 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 4855 | childFreeWinHash => {}, | ||
| 4856 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 4857 | # window is informed via a call to $self->del_childFreeWin | ||
| 4858 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 4859 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 4860 | # this hash; a hash in the form | ||
| 4861 | # $childDestroyHash{unique_number} = list_reference | ||
| 4862 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 4863 | # reference to a list in groups of 2, in the form | ||
| 4864 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 4865 | childDestroyHash => {}, | ||
| 4866 | |||
| 4867 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 4868 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 4869 | # area) | ||
| 4870 | packingBox => undef, | ||
| 4871 | |||
| 4872 | # Standard IVs for 'free' windows | ||
| 4873 | |||
| 4874 | # The window's default size, in pixels | ||
| 4875 | widthPixels => int($axmud::CLIENT->constFreeWinWidth * 0.66), | ||
| 4876 | heightPixels => int($axmud::CLIENT->constFreeWinHeight * 0.66), | ||
| 4877 | # Default border/item spacing sizes used in the window, in pixels | ||
| 4878 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 4879 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 4880 | |||
| 4881 | # A string to use as the window title | ||
| 4882 | title => 'MCP edit: ' . $configHash{'mcp_name'}, | ||
| 4883 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 4884 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 4885 | # name and type. Set to an empty hash if not required | ||
| 4886 | configHash => {%configHash}, | ||
| 4887 | }; | ||
| 4888 | |||
| 4889 | # Bless the object into existence | ||
| 4890 | bless $self, $class; | ||
| 4891 | |||
| 4892 | return $self; | ||
| 4893 | } | ||
| 4894 | |||
| 4895 | ################## | ||
| 4896 | # Methods | ||
| 4897 | |||
| 4898 | # Standard window object functions | ||
| 4899 | |||
| 4900 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 4901 | |||
| 4902 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 4903 | |||
| 4904 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 4905 | |||
| 4906 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 4907 | |||
| 4908 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 4909 | |||
| 4910 | sub drawWidgets { | ||
| 4911 | |||
| 4912 | # Called by $self->winSetup | ||
| 4913 | # Sets up the Gtk3::Window by drawing the window's widgets | ||
| 4914 | # | ||
| 4915 | # Expected arguments | ||
| 4916 | # (none besides $self) | ||
| 4917 | # | ||
| 4918 | # Return values | ||
| 4919 | # 'undef' on improper arguments | ||
| 4920 | # 1 otherwise | ||
| 4921 | |||
| 4922 | my ($self, $check) = @_; | ||
| 4923 | |||
| 4924 | # Local variables | ||
| 4925 | my $title; | ||
| 4926 | |||
| 4927 | # Check for improper arguments | ||
| 4928 | if (defined $check) { | ||
| 4929 | |||
| 4930 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 4931 | } | ||
| 4932 | |||
| 4933 | # Create a packing box | ||
| 4934 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 4935 | $self->winBox->add($packingBox); | ||
| 4936 | $packingBox->set_border_width(0); | ||
| 4937 | |||
| 4938 | # At the top, create a textview | ||
| 4939 | my $scroller = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 4940 | $packingBox->pack_start($scroller, TRUE, TRUE, 0); | ||
| 4941 | $scroller->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 4942 | $scroller->set_policy('automatic', 'automatic'); | ||
| 4943 | $scroller->set_border_width(0); | ||
| 4944 | |||
| 4945 | # Create a textview with default colours/fonts | ||
| 4946 | my $textView = Gtk3::TextView->new(); | ||
| 4947 | $scroller->add($textView); | ||
| 4948 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 4949 | $textView->set_buffer($buffer); | ||
| 4950 | $textView->set_editable(TRUE); | ||
| 4951 | $textView->set_cursor_visible(TRUE); | ||
| 4952 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView); | ||
| 4953 | # ->signal_connect appears below | ||
| 4954 | |||
| 4955 | # Set the initial contents of the textview | ||
| 4956 | $buffer->set_text($self->ivShow('configHash', 'mcp_content')); | ||
| 4957 | |||
| 4958 | # At the bottom, create a button strip in a horizontal packing box | ||
| 4959 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 4960 | $packingBox->pack_end($hBox, FALSE, FALSE, $self->spacingPixels); | ||
| 4961 | |||
| 4962 | # Create some buttons | ||
| 4963 | my $cancelButton = Gtk3::Button->new('Cancel'); | ||
| 4964 | $hBox->pack_start($cancelButton, TRUE, TRUE, $self->borderPixels); | ||
| 4965 | $cancelButton->get_child->set_width_chars(10); | ||
| 4966 | $cancelButton->signal_connect('clicked' => sub { | ||
| 4967 | |||
| 4968 | $self->winDestroy(); | ||
| 4969 | }); | ||
| 4970 | $cancelButton->set_sensitive(FALSE); | ||
| 4971 | |||
| 4972 | my $saveButton = Gtk3::Button->new('Save'); | ||
| 4973 | $hBox->pack_start($saveButton, TRUE, TRUE, $self->borderPixels); | ||
| 4974 | $saveButton->get_child->set_width_chars(10); | ||
| 4975 | $saveButton->signal_connect('clicked' => sub { | ||
| 4976 | |||
| 4977 | $self->doSave($buffer); | ||
| 4978 | $cancelButton->set_sensitive(FALSE); | ||
| 4979 | }); | ||
| 4980 | |||
| 4981 | my $saveCloseButton = Gtk3::Button->new('Save and close'); | ||
| 4982 | $hBox->pack_end($saveCloseButton, TRUE, TRUE, $self->borderPixels); | ||
| 4983 | $saveCloseButton->get_child->set_width_chars(15); | ||
| 4984 | $saveCloseButton->signal_connect('clicked' => sub { | ||
| 4985 | |||
| 4986 | $self->doSave($buffer); | ||
| 4987 | $self->winDestroy(); | ||
| 4988 | }); | ||
| 4989 | |||
| 4990 | # ->signal_connect from above | ||
| 4991 | $buffer->signal_connect('changed' => sub { | ||
| 4992 | |||
| 4993 | $cancelButton->set_sensitive(TRUE); | ||
| 4994 | }); | ||
| 4995 | |||
| 4996 | # Update IVs (not worth storing widgets other than the main packing box) | ||
| 4997 | $self->ivPoke('packingBox', $packingBox); | ||
| 4998 | |||
| 4999 | return 1; | ||
| 5000 | } | ||
| 5001 | |||
| 5002 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 5003 | |||
| 5004 | # ->signal_connects | ||
| 5005 | |||
| 5006 | # Other functions | ||
| 5007 | |||
| 5008 | sub doSave { | ||
| 5009 | |||
| 5010 | # Called by $self->drawWidgets | ||
| 5011 | # 'Saves' the contents of the window by sending an MSP message to the world | ||
| 5012 | # | ||
| 5013 | # Expected arguments | ||
| 5014 | # $buffer - The window's Gtk3::Buffer | ||
| 5015 | # | ||
| 5016 | # Return values | ||
| 5017 | # 'undef' on improper arguments | ||
| 5018 | # 1 otherwise | ||
| 5019 | |||
| 5020 | my ($self, $buffer, $check) = @_; | ||
| 5021 | |||
| 5022 | # Local variables | ||
| 5023 | my ( | ||
| 5024 | $text, | ||
| 5025 | @list, | ||
| 5026 | ); | ||
| 5027 | |||
| 5028 | # Check for improper arguments | ||
| 5029 | if (defined $check) { | ||
| 5030 | |||
| 5031 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doSave', @_); | ||
| 5032 | } | ||
| 5033 | |||
| 5034 | $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer); | ||
| 5035 | @list = split(/\n/, $text); | ||
| 5036 | |||
| 5037 | # Send the MCP message (one or more multiline parts) | ||
| 5038 | $self->session->mcpSendMultiLine( | ||
| 5039 | 'dns-org-mud-moo-simpleedit-set', | ||
| 5040 | 'reference', | ||
| 5041 | $self->ivShow('configHash', 'mcp_reference'), | ||
| 5042 | 'content', | ||
| 5043 | \@list, | ||
| 5044 | 'type', | ||
| 5045 | $self->ivShow('configHash', 'mcp_type'), | ||
| 5046 | ); | ||
| 5047 | |||
| 5048 | return 1; | ||
| 5049 | } | ||
| 5050 | |||
| 5051 | ################## | ||
| 5052 | # Accessors - set | ||
| 5053 | |||
| 5054 | ################## | ||
| 5055 | # Accessors - get | ||
| 5056 | } | ||
| 5057 | |||
| 5058 | { package Games::Axmud::OtherWin::PatternTest; | ||
| 5059 | |||
| 5060 | use strict; | ||
| 5061 | use warnings; | ||
| 5062 | # use diagnostics; | ||
| 5063 | |||
| 5064 | use Glib qw(TRUE FALSE); | ||
| 5065 | |||
| 5066 | our @ISA = qw( | ||
| 5067 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 5068 | Games::Axmud | ||
| 5069 | ); | ||
| 5070 | |||
| 5071 | ################## | ||
| 5072 | # Constructors | ||
| 5073 | |||
| 5074 | sub new { | ||
| 5075 | |||
| 5076 | # Called by GA::Generic::Win->createFreeWin | ||
| 5077 | # Creates a new instance of the Pattern Test window, which allows the user to to test | ||
| 5078 | # patterns (regexes) on the fly | ||
| 5079 | # | ||
| 5080 | # Expected arguments | ||
| 5081 | # $number - Unique number for this window object | ||
| 5082 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 5083 | # should be created | ||
| 5084 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 5085 | # 'free' window object. When this window opens/closes, the owner is | ||
| 5086 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 5087 | # functions | ||
| 5088 | # | ||
| 5089 | # Optional arguments | ||
| 5090 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 5091 | # calling function didn't specify a session and $owner's ->session IV | ||
| 5092 | # is also 'undef' | ||
| 5093 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 5094 | # $editObj - Ignored if set | ||
| 5095 | # $tempFlag - Ignored if set | ||
| 5096 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 5097 | # particular 'other' window; set to an empty hash if not required | ||
| 5098 | # - This type of window object recognises these initialisation settings: | ||
| 5099 | # | ||
| 5100 | # ... | ||
| 5101 | # | ||
| 5102 | # Return values | ||
| 5103 | # 'undef' on improper arguments | ||
| 5104 | # Blessed reference to the newly-created object on success | ||
| 5105 | |||
| 5106 | my ( | ||
| 5107 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 5108 | %configHash, | ||
| 5109 | ) = @_; | ||
| 5110 | |||
| 5111 | # Local variables | ||
| 5112 | my ($widthPixels, $heightPixels); | ||
| 5113 | |||
| 5114 | # Check for improper arguments | ||
| 5115 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 5116 | |||
| 5117 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 5118 | } | ||
| 5119 | |||
| 5120 | # Setup | ||
| 5121 | my $self = { | ||
| 5122 | _objName => 'other_win_' . $number, | ||
| 5123 | _objClass => $class, | ||
| 5124 | _parentFile => undef, # No parent file object | ||
| 5125 | _parentWorld => undef, # No parent file object | ||
| 5126 | _privFlag => TRUE, # All IVs are private | ||
| 5127 | |||
| 5128 | # Standard window object IVs | ||
| 5129 | # -------------------------- | ||
| 5130 | |||
| 5131 | # Unique number for this window object | ||
| 5132 | number => $number, | ||
| 5133 | # The window category - 'grid' or 'free' | ||
| 5134 | winCategory => 'free', | ||
| 5135 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 5136 | winType => 'other', | ||
| 5137 | # A name for the window (for some 'free' windows, the same as the window type) | ||
| 5138 | winName => 'pattern_test', | ||
| 5139 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 5140 | workspaceObj => $workspaceObj, | ||
| 5141 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 5142 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 5143 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 5144 | owner => $owner, | ||
| 5145 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 5146 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 5147 | session => $session, | ||
| 5148 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 5149 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 5150 | # displayed in a 'dialogue' window) | ||
| 5151 | pseudoCmdMode => 'win_error', | ||
| 5152 | |||
| 5153 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 5154 | # parent 'main' window's Gtk3::Window | ||
| 5155 | # The code should use this IV when it wants to do something to the window itself | ||
| 5156 | # (minimise it, make it active, etc) | ||
| 5157 | winWidget => undef, | ||
| 5158 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 5159 | # the parent GA::Table::PseudoWin table object | ||
| 5160 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 5161 | # window itself | ||
| 5162 | winBox => undef, | ||
| 5163 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 5164 | # FALSE if not | ||
| 5165 | enabledFlag => FALSE, | ||
| 5166 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 5167 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 5168 | visibleFlag => TRUE, | ||
| 5169 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 5170 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 5171 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 5172 | childFreeWinHash => {}, | ||
| 5173 | |||
| 5174 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 5175 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 5176 | # area) | ||
| 5177 | packingBox => undef, # Gtk3::VBox | ||
| 5178 | |||
| 5179 | # Standard IVs for 'free' windows | ||
| 5180 | |||
| 5181 | # The window's default size, in pixels | ||
| 5182 | widthPixels => $axmud::CLIENT->customFreeWinWidth, | ||
| 5183 | heightPixels => $axmud::CLIENT->customFreeWinHeight, | ||
| 5184 | # Default border/item spacing sizes used in the window, in pixels | ||
| 5185 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 5186 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 5187 | |||
| 5188 | # A string to use as the window title. If 'undef', a generic title is used | ||
| 5189 | title => 'Pattern Test', | ||
| 5190 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 5191 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 5192 | # name and type. Set to an empty hash if not required | ||
| 5193 | configHash => {%configHash}, | ||
| 5194 | |||
| 5195 | # IVs for this type of window | ||
| 5196 | |||
| 5197 | # Standard size of the Gtk3::Grid used (a 12x12 grid, with a spare cell around every | ||
| 5198 | # border) | ||
| 5199 | gridWidth => 13, | ||
| 5200 | gridHeight => 13, | ||
| 5201 | }; | ||
| 5202 | |||
| 5203 | # Bless the object into existence | ||
| 5204 | bless $self, $class; | ||
| 5205 | |||
| 5206 | return $self; | ||
| 5207 | } | ||
| 5208 | |||
| 5209 | ################## | ||
| 5210 | # Methods | ||
| 5211 | |||
| 5212 | # Standard window object functions | ||
| 5213 | |||
| 5214 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 5215 | |||
| 5216 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 5217 | |||
| 5218 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 5219 | |||
| 5220 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 5221 | |||
| 5222 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 5223 | |||
| 5224 | sub drawWidgets { | ||
| 5225 | |||
| 5226 | # Called by $self->winSetup | ||
| 5227 | # Sets up the Pattern Test window with its standard widgets | ||
| 5228 | # | ||
| 5229 | # Expected arguments | ||
| 5230 | # (none besides $self) | ||
| 5231 | # | ||
| 5232 | # Return values | ||
| 5233 | # 'undef' on improper arguments | ||
| 5234 | # 1 otherwise | ||
| 5235 | |||
| 5236 | my ($self, $check) = @_; | ||
| 5237 | |||
| 5238 | # Local variables | ||
| 5239 | my @columnList; | ||
| 5240 | |||
| 5241 | # Check for improper arguments | ||
| 5242 | if (defined $check) { | ||
| 5243 | |||
| 5244 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 5245 | } | ||
| 5246 | |||
| 5247 | # Create a packing box | ||
| 5248 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 5249 | $self->winBox->add($packingBox); | ||
| 5250 | $packingBox->set_border_width(0); | ||
| 5251 | |||
| 5252 | # Update IVs immediately, for the benefit of any called functions | ||
| 5253 | $self->ivPoke('packingBox', $packingBox); | ||
| 5254 | |||
| 5255 | # Create an image on the left | ||
| 5256 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 5257 | $packingBox->pack_start($hBox, TRUE, TRUE, 0); | ||
| 5258 | |||
| 5259 | my $vBox = Gtk3::VBox->new(FALSE, 0); | ||
| 5260 | $hBox->pack_start($vBox, FALSE, FALSE, 0); | ||
| 5261 | |||
| 5262 | my $frame = Gtk3::Frame->new(undef); | ||
| 5263 | $vBox->pack_start($frame, FALSE, FALSE, 0); | ||
| 5264 | $frame->set_size_request(64, 64); | ||
| 5265 | $frame->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 5266 | |||
| 5267 | my $image = Gtk3::Image->new_from_file($axmud::CLIENT->getDialogueIcon()); | ||
| 5268 | $frame->add($image); | ||
| 5269 | |||
| 5270 | # Create a grid inside a scroller on the right | ||
| 5271 | my $frame2 = Gtk3::Frame->new(undef); | ||
| 5272 | $hBox->pack_start($frame2, TRUE, TRUE, $self->spacingPixels); | ||
| 5273 | $frame2->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 5274 | |||
| 5275 | my $scroller = Gtk3::ScrolledWindow->new(); | ||
| 5276 | $frame2->add($scroller); | ||
| 5277 | $scroller->set_policy(qw/automatic automatic/); | ||
| 5278 | $scroller->set_border_width(5); | ||
| 5279 | |||
| 5280 | my $grid = Gtk3::Grid->new(); | ||
| 5281 | $scroller->add_with_viewport($grid); | ||
| 5282 | $grid->set_column_spacing($self->spacingPixels); | ||
| 5283 | $grid->set_row_spacing($self->spacingPixels); | ||
| 5284 | |||
| 5285 | # Create a button at the bottom to close the window | ||
| 5286 | my $hBox2 = Gtk3::HBox->new(FALSE, 0); | ||
| 5287 | $packingBox->pack_end($hBox2, FALSE, FALSE, $self->spacingPixels); | ||
| 5288 | |||
| 5289 | # The button's label includes some extra space characters to make it a little easier to | ||
| 5290 | # click on | ||
| 5291 | my $okButton = Gtk3::Button->new('OK'); | ||
| 5292 | $okButton->get_child->set_width_chars(10); | ||
| 5293 | $hBox2->pack_end($okButton, FALSE, FALSE, 0); | ||
| 5294 | $okButton->signal_connect('clicked' => sub { | ||
| 5295 | |||
| 5296 | $self->winDestroy(); | ||
| 5297 | }); | ||
| 5298 | |||
| 5299 | # Add some editing widgets. The ->signal_connect appear below | ||
| 5300 | $self->addLabel($grid, '<b>Pattern / regular expression / regex tester</b>', | ||
| 5301 | 1, 12, 1, 2); | ||
| 5302 | |||
| 5303 | $self->addLabel($grid, 'Pattern', | ||
| 5304 | 1, 3, 2, 3); | ||
| 5305 | my $entry = $self->addEntry($grid, undef, undef, TRUE, | ||
| 5306 | 3, 12, 2, 3); | ||
| 5307 | $entry->set_icon_from_stock('secondary', 'gtk-no'); | ||
| 5308 | |||
| 5309 | $self->addLabel($grid, 'Line', | ||
| 5310 | 1, 3, 3, 4); | ||
| 5311 | my $entry2 = $self->addEntry($grid, undef, undef, TRUE, | ||
| 5312 | 3, 12, 3, 4); | ||
| 5313 | |||
| 5314 | $self->addLabel($grid, 'Substitution', | ||
| 5315 | 1, 3, 4, 5); | ||
| 5316 | my $entry3 = $self->addEntry($grid, undef, undef, TRUE, | ||
| 5317 | 3, 12, 4, 5); | ||
| 5318 | |||
| 5319 | my $button = $self->addButton( | ||
| 5320 | $grid, | ||
| 5321 | undef, | ||
| 5322 | 'Test the pattern\'s validity', | ||
| 5323 | 'Test the pattern\'s validity', | ||
| 5324 | 1, 6, 5, 6); | ||
| 5325 | |||
| 5326 | my $button2 = $self->addButton( | ||
| 5327 | $grid, | ||
| 5328 | undef, | ||
| 5329 | 'Match the pattern against the line', | ||
| 5330 | 'i.e. $line =~ m/$pattern/', | ||
| 5331 | 6, 12, 5, 6); | ||
| 5332 | $button2->set_sensitive(FALSE); | ||
| 5333 | |||
| 5334 | my $button3 = $self->addButton( | ||
| 5335 | $grid, | ||
| 5336 | undef, | ||
| 5337 | 'Use the pattern to apply the substitution to the line', | ||
| 5338 | 'i.e. $line =~ s/$pattern/$substitution/', | ||
| 5339 | 1, 8, 6, 7); | ||
| 5340 | $button3->set_sensitive(FALSE); | ||
| 5341 | |||
| 5342 | my $button4 = $self->addButton( | ||
| 5343 | $grid, | ||
| 5344 | undef, | ||
| 5345 | 'Clear all', | ||
| 5346 | 'Clear all the entry boxes', | ||
| 5347 | 8, 12, 6, 7); | ||
| 5348 | |||
| 5349 | $self->addLabel($grid, 'Result', | ||
| 5350 | 1, 3, 7, 8); | ||
| 5351 | my $entry4 = $self->addEntry($grid, undef, undef, TRUE, | ||
| 5352 | 3, 12, 7, 8); | ||
| 5353 | $entry4->set_editable(FALSE); | ||
| 5354 | |||
| 5355 | # Add a simple list to show group substrings | ||
| 5356 | @columnList = ( | ||
| 5357 | 'Substring #', 'int', | ||
| 5358 | 'Matching substring', 'text', | ||
| 5359 | ); | ||
| 5360 | |||
| 5361 | my $frame3 = Gtk3::Frame->new(undef); | ||
| 5362 | $grid->attach($frame3, 1, 8, 11, 4); | ||
| 5363 | $frame3->set_border_width(0); | ||
| 5364 | $frame3->set_vexpand(TRUE); | ||
| 5365 | |||
| 5366 | my $scroller2 = Gtk3::ScrolledWindow->new(); | ||
| 5367 | $frame3->add($scroller2); | ||
| 5368 | $scroller2->set_shadow_type('none'); | ||
| 5369 | $scroller2->set_policy('automatic', 'automatic'); | ||
| 5370 | $scroller2->set_border_width(0); | ||
| 5371 | $scroller2->set_size_request(-1, 180); | ||
| 5372 | |||
| 5373 | my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList); | ||
| 5374 | $scroller2->add($slWidget); | ||
| 5375 | |||
| 5376 | # ->signal_connects | ||
| 5377 | $entry->signal_connect('changed' => sub { | ||
| 5378 | |||
| 5379 | my $regex = $entry->get_text(); | ||
| 5380 | |||
| 5381 | # GA::Client->regexCheck returns 'undef' for a valid regex, or an error message for an | ||
| 5382 | # invalid one | ||
| 5383 | if ( | ||
| 5384 | defined $regex | ||
| 5385 | && $regex ne '' | ||
| 5386 | && ! defined $axmud::CLIENT->regexCheck($regex) | ||
| 5387 | ) { | ||
| 5388 | $entry->set_icon_from_stock('secondary', 'gtk-yes'); | ||
| 5389 | |||
| 5390 | if (length $entry2->get_text() > 0) { | ||
| 5391 | $button2->set_sensitive(TRUE); | ||
| 5392 | } else { | ||
| 5393 | $button2->set_sensitive(FALSE); | ||
| 5394 | } | ||
| 5395 | |||
| 5396 | if (length $entry3->get_text() > 0) { | ||
| 5397 | $button3->set_sensitive(TRUE); | ||
| 5398 | } else { | ||
| 5399 | $button3->set_sensitive(FALSE); | ||
| 5400 | } | ||
| 5401 | |||
| 5402 | } else { | ||
| 5403 | |||
| 5404 | $entry->set_icon_from_stock('secondary', 'gtk-no'); | ||
| 5405 | $button2->set_sensitive(FALSE); | ||
| 5406 | $button3->set_sensitive(FALSE); | ||
| 5407 | } | ||
| 5408 | }); | ||
| 5409 | |||
| 5410 | $entry2->signal_connect('changed' => sub { | ||
| 5411 | |||
| 5412 | my ($regex, $line, $substitution); | ||
| 5413 | |||
| 5414 | $regex = $entry->get_text(); | ||
| 5415 | $line = $entry2->get_text(); | ||
| 5416 | $substitution = $entry3->get_text(); | ||
| 5417 | |||
| 5418 | if ( | ||
| 5419 | ! defined $axmud::CLIENT->regexCheck($regex) | ||
| 5420 | && length $line > 0 | ||
| 5421 | ) { | ||
| 5422 | $button2->set_sensitive(TRUE); | ||
| 5423 | if (length $substitution > 0) { | ||
| 5424 | $button3->set_sensitive(TRUE); | ||
| 5425 | } else { | ||
| 5426 | $button3->set_sensitive(FALSE); | ||
| 5427 | } | ||
| 5428 | |||
| 5429 | } else { | ||
| 5430 | |||
| 5431 | $button2->set_sensitive(FALSE); | ||
| 5432 | $button3->set_sensitive(FALSE); | ||
| 5433 | } | ||
| 5434 | }); | ||
| 5435 | |||
| 5436 | $entry3->signal_connect('changed' => sub { | ||
| 5437 | |||
| 5438 | my ($regex, $line, $substitution); | ||
| 5439 | |||
| 5440 | $regex = $entry->get_text(); | ||
| 5441 | $line = $entry2->get_text(); | ||
| 5442 | $substitution = $entry3->get_text(); | ||
| 5443 | |||
| 5444 | if ( | ||
| 5445 | ! defined $axmud::CLIENT->regexCheck($regex) | ||
| 5446 | && length $line > 0 | ||
| 5447 | && length $substitution > 0 | ||
| 5448 | ) { | ||
| 5449 | $button3->set_sensitive(TRUE); | ||
| 5450 | } else { | ||
| 5451 | $button3->set_sensitive(FALSE); | ||
| 5452 | } | ||
| 5453 | }); | ||
| 5454 | |||
| 5455 | $button->signal_connect('clicked' => sub { | ||
| 5456 | |||
| 5457 | my ($regex, $result); | ||
| 5458 | |||
| 5459 | $regex = $entry->get_text(); | ||
| 5460 | |||
| 5461 | if (! defined $regex || $regex eq '') { | ||
| 5462 | |||
| 5463 | $entry4->set_text(''); | ||
| 5464 | |||
| 5465 | } else { | ||
| 5466 | |||
| 5467 | $result = $axmud::CLIENT->regexCheck($regex); | ||
| 5468 | if (! defined $result) { | ||
| 5469 | |||
| 5470 | $entry4->set_text('<Pattern is valid>'); | ||
| 5471 | $entry4->set_icon_from_stock('secondary', 'gtk-yes'); | ||
| 5472 | |||
| 5473 | } else { | ||
| 5474 | |||
| 5475 | # Perl error message | ||
| 5476 | $entry4->set_text($result); | ||
| 5477 | $entry4->set_icon_from_stock('secondary', 'gtk-no'); | ||
| 5478 | } | ||
| 5479 | } | ||
| 5480 | }); | ||
| 5481 | |||
| 5482 | $button2->signal_connect('clicked' => sub { | ||
| 5483 | |||
| 5484 | my ( | ||
| 5485 | $regex, $line, $count, | ||
| 5486 | @grpStringList, @dataList, | ||
| 5487 | ); | ||
| 5488 | |||
| 5489 | $regex = $entry->get_text(); | ||
| 5490 | $line = $entry2->get_text(); | ||
| 5491 | |||
| 5492 | @grpStringList = ($line =~ m/$regex/); | ||
| 5493 | if (@grpStringList) { | ||
| 5494 | |||
| 5495 | if ((scalar @-) > 1) { | ||
| 5496 | |||
| 5497 | $count = 0; | ||
| 5498 | foreach my $grpString (@grpStringList) { | ||
| 5499 | |||
| 5500 | $count++; | ||
| 5501 | push (@dataList, [$count, $grpString]); | ||
| 5502 | } | ||
| 5503 | } | ||
| 5504 | |||
| 5505 | $entry4->set_text('<Pattern matches the line>'); | ||
| 5506 | $entry4->set_icon_from_stock('secondary', 'gtk-yes'); | ||
| 5507 | @{$slWidget->{data}} = @dataList; | ||
| 5508 | |||
| 5509 | } else { | ||
| 5510 | |||
| 5511 | $entry4->set_text('<Pattern does NOT match the line>'); | ||
| 5512 | $entry4->set_icon_from_stock('secondary', 'gtk-no'); | ||
| 5513 | @{$slWidget->{data}} = (); | ||
| 5514 | } | ||
| 5515 | }); | ||
| 5516 | |||
| 5517 | $button3->signal_connect('clicked' => sub { | ||
| 5518 | |||
| 5519 | my ($regex, $line, $substitution); | ||
| 5520 | |||
| 5521 | $regex = $entry->get_text(); | ||
| 5522 | $line = $entry2->get_text(); | ||
| 5523 | $substitution = $entry3->get_text(); | ||
| 5524 | |||
| 5525 | if ($line =~ s/$regex/$substitution/) { | ||
| 5526 | |||
| 5527 | $entry4->set_text($line); | ||
| 5528 | $entry4->set_icon_from_stock('secondary', 'gtk-yes'); | ||
| 5529 | @{$slWidget->{data}} = (); | ||
| 5530 | |||
| 5531 | } else { | ||
| 5532 | |||
| 5533 | $entry4->set_text('<Pattern does NOT match the line>'); | ||
| 5534 | $entry4->set_icon_from_stock('secondary', 'gtk-no'); | ||
| 5535 | @{$slWidget->{data}} = (); | ||
| 5536 | } | ||
| 5537 | }); | ||
| 5538 | |||
| 5539 | $button4->signal_connect('clicked' => sub { | ||
| 5540 | |||
| 5541 | $entry->set_text(''); | ||
| 5542 | $entry->set_icon_from_stock('secondary', undef); | ||
| 5543 | |||
| 5544 | $entry2->set_text(''); | ||
| 5545 | $entry3->set_text(''); | ||
| 5546 | |||
| 5547 | $entry4->set_icon_from_stock('secondary', undef); | ||
| 5548 | $entry4->set_text(''); | ||
| 5549 | |||
| 5550 | @{$slWidget->{data}} = (); | ||
| 5551 | }); | ||
| 5552 | |||
| 5553 | return 1; | ||
| 5554 | } | ||
| 5555 | |||
| 5556 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 5557 | |||
| 5558 | # ->signal_connects | ||
| 5559 | |||
| 5560 | # Other functions | ||
| 5561 | |||
| 5562 | ################## | ||
| 5563 | # Accessors - set | ||
| 5564 | |||
| 5565 | ################## | ||
| 5566 | # Accessors - get | ||
| 5567 | |||
| 5568 | sub gridWidth | ||
| 5569 | { $_[0]->{gridWidth} } | ||
| 5570 | sub gridHeight | ||
| 5571 | { $_[0]->{gridHeight} } | ||
| 5572 | } | ||
| 5573 | |||
| 5574 | { package Games::Axmud::OtherWin::QuickInput; | ||
| 5575 | |||
| 5576 | use strict; | ||
| 5577 | use warnings; | ||
| 5578 | # use diagnostics; | ||
| 5579 | |||
| 5580 | use Glib qw(TRUE FALSE); | ||
| 5581 | |||
| 5582 | our @ISA = qw( | ||
| 5583 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 5584 | Games::Axmud | ||
| 5585 | ); | ||
| 5586 | |||
| 5587 | ################## | ||
| 5588 | # Constructors | ||
| 5589 | |||
| 5590 | sub new { | ||
| 5591 | |||
| 5592 | # Called by GA::Generic::Win->createFreeWin | ||
| 5593 | # Creates a new instance of the Quick Input window (an 'other' window). The window contains | ||
| 5594 | # a textview in which the user can type text, and some widgets that specify what should be | ||
| 5595 | # done with the text | ||
| 5596 | # | ||
| 5597 | # Expected arguments | ||
| 5598 | # $number - Unique number for this window object | ||
| 5599 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 5600 | # should be created | ||
| 5601 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 5602 | # 'free' window object. When this window opens/closes, the owner is | ||
| 5603 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 5604 | # functions | ||
| 5605 | # | ||
| 5606 | # Optional arguments | ||
| 5607 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 5608 | # calling function didn't specify a session and $owner's ->session IV | ||
| 5609 | # is also 'undef' | ||
| 5610 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 5611 | # $editObj - Ignored if set | ||
| 5612 | # $tempFlag - Ignored if set | ||
| 5613 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 5614 | # particular 'other' window; set to an empty hash if not required | ||
| 5615 | # - This type of window object recognises these initialisation settings: | ||
| 5616 | # | ||
| 5617 | # ... | ||
| 5618 | # | ||
| 5619 | # Return values | ||
| 5620 | # 'undef' on improper arguments | ||
| 5621 | # Blessed reference to the newly-created object on success | ||
| 5622 | |||
| 5623 | my ( | ||
| 5624 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 5625 | %configHash, | ||
| 5626 | ) = @_; | ||
| 5627 | |||
| 5628 | # Check for improper arguments | ||
| 5629 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 5630 | |||
| 5631 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 5632 | } | ||
| 5633 | |||
| 5634 | # Setup | ||
| 5635 | my $self = { | ||
| 5636 | _objName => 'other_win_' . $number, | ||
| 5637 | _objClass => $class, | ||
| 5638 | _parentFile => undef, # No parent file object | ||
| 5639 | _parentWorld => undef, # No parent file object | ||
| 5640 | _privFlag => TRUE, # All IVs are private | ||
| 5641 | |||
| 5642 | # Standard window object IVs | ||
| 5643 | # -------------------------- | ||
| 5644 | |||
| 5645 | # Unique number for this window object | ||
| 5646 | number => $number, | ||
| 5647 | # The window category - 'grid' or 'free' | ||
| 5648 | winCategory => 'free', | ||
| 5649 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 5650 | winType => 'other', | ||
| 5651 | # A name for the window (can be unique to this type of window object, or can be the | ||
| 5652 | # same as ->winType) | ||
| 5653 | winName => 'quick_input', | ||
| 5654 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 5655 | workspaceObj => $workspaceObj, | ||
| 5656 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 5657 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 5658 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 5659 | owner => $owner, | ||
| 5660 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 5661 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 5662 | session => $session, | ||
| 5663 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 5664 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 5665 | # displayed in a 'dialogue' window) | ||
| 5666 | pseudoCmdMode => 'win_error', | ||
| 5667 | |||
| 5668 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 5669 | # parent 'main' window's Gtk3::Window | ||
| 5670 | # The code should use this IV when it wants to do something to the window itself | ||
| 5671 | # (minimise it, make it active, etc) | ||
| 5672 | winWidget => undef, | ||
| 5673 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 5674 | # the parent GA::Table::PseudoWin table object | ||
| 5675 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 5676 | # window itself | ||
| 5677 | winBox => undef, | ||
| 5678 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 5679 | # FALSE if not | ||
| 5680 | enabledFlag => FALSE, | ||
| 5681 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 5682 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 5683 | visibleFlag => TRUE, | ||
| 5684 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 5685 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 5686 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 5687 | childFreeWinHash => {}, | ||
| 5688 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 5689 | # window is informed via a call to $self->del_childFreeWin | ||
| 5690 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 5691 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 5692 | # this hash; a hash in the form | ||
| 5693 | # $childDestroyHash{unique_number} = list_reference | ||
| 5694 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 5695 | # reference to a list in groups of 2, in the form | ||
| 5696 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 5697 | childDestroyHash => {}, | ||
| 5698 | |||
| 5699 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 5700 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 5701 | # area) | ||
| 5702 | packingBox => undef, | ||
| 5703 | |||
| 5704 | # Standard IVs for 'free' windows | ||
| 5705 | |||
| 5706 | # The window's default size, in pixels | ||
| 5707 | widthPixels => int($axmud::CLIENT->constFreeWinWidth * 0.66), | ||
| 5708 | heightPixels => int($axmud::CLIENT->constFreeWinHeight * 0.66), | ||
| 5709 | # Default border/item spacing sizes used in the window, in pixels | ||
| 5710 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 5711 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 5712 | |||
| 5713 | # A string to use as the window title | ||
| 5714 | title => 'Quick input window', | ||
| 5715 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 5716 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 5717 | # name and type. Set to an empty hash if not required | ||
| 5718 | configHash => {%configHash}, | ||
| 5719 | }; | ||
| 5720 | |||
| 5721 | # Bless the object into existence | ||
| 5722 | bless $self, $class; | ||
| 5723 | |||
| 5724 | return $self; | ||
| 5725 | } | ||
| 5726 | |||
| 5727 | ################## | ||
| 5728 | # Methods | ||
| 5729 | |||
| 5730 | # Standard window object functions | ||
| 5731 | |||
| 5732 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 5733 | |||
| 5734 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 5735 | |||
| 5736 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 5737 | |||
| 5738 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 5739 | |||
| 5740 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 5741 | |||
| 5742 | sub drawWidgets { | ||
| 5743 | |||
| 5744 | # Called by $self->winSetup | ||
| 5745 | # Sets up the Gtk3::Window by drawing the window's widgets | ||
| 5746 | # | ||
| 5747 | # Expected arguments | ||
| 5748 | # (none besides $self) | ||
| 5749 | # | ||
| 5750 | # Return values | ||
| 5751 | # 'undef' on improper arguments | ||
| 5752 | # 1 otherwise | ||
| 5753 | |||
| 5754 | my ($self, $check) = @_; | ||
| 5755 | |||
| 5756 | # Local variables | ||
| 5757 | my $title; | ||
| 5758 | |||
| 5759 | # Check for improper arguments | ||
| 5760 | if (defined $check) { | ||
| 5761 | |||
| 5762 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 5763 | } | ||
| 5764 | |||
| 5765 | # Create a packing box | ||
| 5766 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 5767 | $self->winBox->add($packingBox); | ||
| 5768 | $packingBox->set_border_width(0); | ||
| 5769 | |||
| 5770 | # At the top, create a textview | ||
| 5771 | my $scroller = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 5772 | $packingBox->pack_start($scroller, TRUE, TRUE, 0); | ||
| 5773 | $scroller->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 5774 | $scroller->set_policy('automatic', 'automatic'); | ||
| 5775 | $scroller->set_border_width(0); | ||
| 5776 | |||
| 5777 | # Create a textview with default colours/fonts | ||
| 5778 | my $textView = Gtk3::TextView->new(); | ||
| 5779 | $scroller->add($textView); | ||
| 5780 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 5781 | $textView->set_buffer($buffer); | ||
| 5782 | $textView->set_editable(TRUE); | ||
| 5783 | $textView->set_cursor_visible(TRUE); | ||
| 5784 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView); | ||
| 5785 | |||
| 5786 | # At the bottom, create several horizontal packing boxes for various widgets | ||
| 5787 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 5788 | $packingBox->pack_start($hBox, FALSE, FALSE, $self->spacingPixels); | ||
| 5789 | |||
| 5790 | my $radioButton = Gtk3::RadioButton->new_with_label(undef, 'Execute instructions'); | ||
| 5791 | $hBox->pack_start($radioButton, TRUE, TRUE, $self->spacingPixels); | ||
| 5792 | |||
| 5793 | my $checkButton = Gtk3::CheckButton->new_with_label('(ignore empty lines)'); | ||
| 5794 | $hBox->pack_start($checkButton, TRUE, TRUE, $self->spacingPixels); | ||
| 5795 | |||
| 5796 | my $radioButton2 = Gtk3::RadioButton->new_with_label( | ||
| 5797 | $radioButton->get_group(), | ||
| 5798 | 'Run as a script', | ||
| 5799 | ); | ||
| 5800 | |||
| 5801 | $hBox->pack_start($radioButton2, TRUE, TRUE, $self->spacingPixels); | ||
| 5802 | |||
| 5803 | # Second strip | ||
| 5804 | my $hBox2 = Gtk3::HBox->new(FALSE, 0); | ||
| 5805 | $packingBox->pack_start($hBox2, FALSE, FALSE, 0); | ||
| 5806 | |||
| 5807 | my $label = Gtk3::Label->new('Prepend:'); | ||
| 5808 | $hBox2->pack_start($label, FALSE, FALSE, $self->spacingPixels); | ||
| 5809 | |||
| 5810 | my $entry = Gtk3::Entry->new(); | ||
| 5811 | $hBox2->pack_start($entry, TRUE, TRUE, 0); | ||
| 5812 | $entry->set_tooltip_text('Prepend this to every world command'); | ||
| 5813 | |||
| 5814 | my $label2 = Gtk3::Label->new('Append:'); | ||
| 5815 | $hBox2->pack_start($label2, FALSE, FALSE, $self->spacingPixels); | ||
| 5816 | |||
| 5817 | my $entry2 = Gtk3::Entry->new(); | ||
| 5818 | $hBox2->pack_start($entry2, TRUE, TRUE, 0); | ||
| 5819 | $entry2->set_tooltip_text('Append this to every world command'); | ||
| 5820 | |||
| 5821 | # Third strip | ||
| 5822 | my $hBox3 = Gtk3::HBox->new(FALSE, 0); | ||
| 5823 | $packingBox->pack_end($hBox3, FALSE, FALSE, $self->spacingPixels); | ||
| 5824 | |||
| 5825 | my $okButton = Gtk3::Button->new('Send'); | ||
| 5826 | $hBox3->pack_start($okButton, TRUE, TRUE, 0); | ||
| 5827 | |||
| 5828 | my $clearButton = Gtk3::Button->new('Send and clear text'); | ||
| 5829 | $hBox3->pack_start($clearButton, FALSE, FALSE, $self->spacingPixels); | ||
| 5830 | $clearButton->get_child->set_width_chars(20); | ||
| 5831 | |||
| 5832 | my $closeButton = Gtk3::Button->new('Close window'); | ||
| 5833 | $hBox3->pack_start($closeButton, FALSE, FALSE, 0); | ||
| 5834 | $closeButton->get_child->set_width_chars(15); | ||
| 5835 | |||
| 5836 | # ->signal_connects for the buttons | ||
| 5837 | $radioButton->signal_connect('toggled' => sub { | ||
| 5838 | |||
| 5839 | if ($radioButton->get_active()) { | ||
| 5840 | |||
| 5841 | $checkButton->set_sensitive(TRUE); | ||
| 5842 | |||
| 5843 | $entry->set_sensitive(TRUE); | ||
| 5844 | $entry2->set_sensitive(TRUE); | ||
| 5845 | |||
| 5846 | $okButton->set_label('Send'); | ||
| 5847 | $clearButton->set_label(' Send and clear text '); | ||
| 5848 | } | ||
| 5849 | }); | ||
| 5850 | |||
| 5851 | $radioButton2->signal_connect('toggled' => sub { | ||
| 5852 | |||
| 5853 | if ($radioButton2->get_active()) { | ||
| 5854 | |||
| 5855 | $checkButton->set_active(FALSE); | ||
| 5856 | $checkButton->set_sensitive(FALSE); | ||
| 5857 | |||
| 5858 | $entry->set_sensitive(FALSE); | ||
| 5859 | $entry->set_text(''); | ||
| 5860 | $entry2->set_sensitive(FALSE); | ||
| 5861 | $entry2->set_text(''); | ||
| 5862 | |||
| 5863 | $okButton->set_label('Run'); | ||
| 5864 | $clearButton->set_label(' Run and clear text '); | ||
| 5865 | } | ||
| 5866 | }); | ||
| 5867 | |||
| 5868 | $okButton->signal_connect('clicked' => sub { | ||
| 5869 | |||
| 5870 | if ($radioButton->get_active()) { | ||
| 5871 | |||
| 5872 | # Execute instructions | ||
| 5873 | $self->executeInstructions( | ||
| 5874 | $axmud::CLIENT->desktopObj->bufferGetText($buffer), | ||
| 5875 | $entry->get_text(), | ||
| 5876 | $entry2->get_text(), | ||
| 5877 | $checkButton->get_active(), | ||
| 5878 | ); | ||
| 5879 | |||
| 5880 | } else { | ||
| 5881 | |||
| 5882 | # Save the script as a temporary file, and execute it | ||
| 5883 | $self->runScript($axmud::CLIENT->desktopObj->bufferGetText($buffer)); | ||
| 5884 | } | ||
| 5885 | }); | ||
| 5886 | |||
| 5887 | $clearButton->signal_connect('clicked' => sub { | ||
| 5888 | |||
| 5889 | if ($radioButton->get_active()) { | ||
| 5890 | |||
| 5891 | # Execute instructions | ||
| 5892 | $self->executeInstructions( | ||
| 5893 | $axmud::CLIENT->desktopObj->bufferGetText($buffer), | ||
| 5894 | $entry->get_text(), | ||
| 5895 | $entry2->get_text(), | ||
| 5896 | $checkButton->get_active(), | ||
| 5897 | ); | ||
| 5898 | |||
| 5899 | } else { | ||
| 5900 | |||
| 5901 | # Save the script as a temporary file, and execute it | ||
| 5902 | $self->runScript($axmud::CLIENT->desktopObj->bufferGetText($buffer)); | ||
| 5903 | } | ||
| 5904 | |||
| 5905 | $buffer->set_text(''); | ||
| 5906 | }); | ||
| 5907 | |||
| 5908 | $closeButton->signal_connect('clicked' => sub { | ||
| 5909 | |||
| 5910 | $self->winDestroy(); | ||
| 5911 | }); | ||
| 5912 | |||
| 5913 | # Update IVs (not worth storing widgets other than the main packing box) | ||
| 5914 | $self->ivPoke('packingBox', $packingBox); | ||
| 5915 | |||
| 5916 | return 1; | ||
| 5917 | } | ||
| 5918 | |||
| 5919 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 5920 | |||
| 5921 | # ->signal_connects | ||
| 5922 | |||
| 5923 | # Other functions | ||
| 5924 | |||
| 5925 | sub executeInstructions { | ||
| 5926 | |||
| 5927 | # Called by $self->drawWidgets when the user clicks the 'Send' button | ||
| 5928 | # Executes the contents of the window as instructions, one line at a time | ||
| 5929 | # | ||
| 5930 | # Expected arguments | ||
| 5931 | # $text - The contents of the Gtk3::TextBuffer | ||
| 5932 | # $preText - Text to prepend to any world commands (or an empty string) | ||
| 5933 | # $postText - Text to append to any world commands (or an empty string) | ||
| 5934 | # $ignoreFlag - TRUE if empty lines should be ignored, FALSE if they should be used (as | ||
| 5935 | # world commands) | ||
| 5936 | # | ||
| 5937 | # Return values | ||
| 5938 | # 'undef' on improper arguments | ||
| 5939 | # 1 otherwise | ||
| 5940 | |||
| 5941 | my ($self, $text, $preText, $postText, $ignoreFlag, $check) = @_; | ||
| 5942 | |||
| 5943 | # Local variables | ||
| 5944 | my (@cmdList, @finalList); | ||
| 5945 | |||
| 5946 | # Check for improper arguments | ||
| 5947 | if ( | ||
| 5948 | ! defined $text || ! defined $preText || ! defined $postText || ! defined $ignoreFlag | ||
| 5949 | || defined $check | ||
| 5950 | ) { | ||
| 5951 | return $axmud::CLIENT->writeImproper($self->_objClass . '->executeInstructions', @_); | ||
| 5952 | } | ||
| 5953 | |||
| 5954 | # Split $text into lines | ||
| 5955 | @cmdList = split(/\n/, $text); | ||
| 5956 | |||
| 5957 | # Ignore empty lines, if required | ||
| 5958 | if (! $ignoreFlag) { | ||
| 5959 | |||
| 5960 | @finalList = @cmdList; | ||
| 5961 | |||
| 5962 | } else { | ||
| 5963 | |||
| 5964 | # Remove empty lines | ||
| 5965 | foreach my $cmd (@cmdList) { | ||
| 5966 | |||
| 5967 | if (! ($cmd =~ m/^\s*$/)) { | ||
| 5968 | |||
| 5969 | push (@finalList, $cmd); | ||
| 5970 | } | ||
| 5971 | } | ||
| 5972 | } | ||
| 5973 | |||
| 5974 | # GA::Session->doInstruct expects 'undef' rather than an empty string | ||
| 5975 | if ($preText eq '') { | ||
| 5976 | |||
| 5977 | $preText = undef; | ||
| 5978 | } | ||
| 5979 | |||
| 5980 | if ($postText eq '') { | ||
| 5981 | |||
| 5982 | $postText = undef; | ||
| 5983 | } | ||
| 5984 | |||
| 5985 | # Execute every line as an instruction | ||
| 5986 | foreach my $instruct (@finalList) { | ||
| 5987 | |||
| 5988 | $self->session->doInstruct($instruct, undef, $preText, $postText); | ||
| 5989 | } | ||
| 5990 | |||
| 5991 | return 1; | ||
| 5992 | } | ||
| 5993 | |||
| 5994 | sub runScript { | ||
| 5995 | |||
| 5996 | # Called by $self->drawWidgets when the user clicks the 'Run' button | ||
| 5997 | # Runs the contents of the textview as an Axbasic script | ||
| 5998 | # | ||
| 5999 | # Expected arguments | ||
| 6000 | # $text - The contents of the Gtk3::TextBuffer | ||
| 6001 | # | ||
| 6002 | # Return values | ||
| 6003 | # 'undef' on improper arguments | ||
| 6004 | # 1 otherwise | ||
| 6005 | |||
| 6006 | my ($self, $text, $check) = @_; | ||
| 6007 | |||
| 6008 | # Local variables | ||
| 6009 | my ( | ||
| 6010 | $path, $fileHandle, | ||
| 6011 | @list, | ||
| 6012 | ); | ||
| 6013 | |||
| 6014 | # Check for improper arguments | ||
| 6015 | if (! defined $text || defined $check) { | ||
| 6016 | |||
| 6017 | return $axmud::CLIENT->writeImproper($self->_objClass . '->runScript', @_); | ||
| 6018 | } | ||
| 6019 | |||
| 6020 | # Split $text into lines | ||
| 6021 | @list = split(/\n/, $text); | ||
| 6022 | |||
| 6023 | # Save the script as a temporary file | ||
| 6024 | $path = $axmud::DATA_DIR . '/data/temp/quick.bas'; | ||
| 6025 | |||
| 6026 | # Open the file for writing, overwriting previous contents | ||
| 6027 | if (! open ($fileHandle, ">$path")) { | ||
| 6028 | |||
| 6029 | return undef; | ||
| 6030 | } | ||
| 6031 | |||
| 6032 | foreach my $line (@list) { | ||
| 6033 | |||
| 6034 | $line .= "\n"; | ||
| 6035 | } | ||
| 6036 | |||
| 6037 | print $fileHandle @list; | ||
| 6038 | |||
| 6039 | if (! close $fileHandle) { | ||
| 6040 | |||
| 6041 | return undef; | ||
| 6042 | } | ||
| 6043 | |||
| 6044 | # Run the script | ||
| 6045 | $self->session->pseudoCmd('runscript -p ' . $path, $self->pseudoCmdMode); | ||
| 6046 | |||
| 6047 | # Delete the temporary file | ||
| 6048 | unlink $path; | ||
| 6049 | |||
| 6050 | return 1; | ||
| 6051 | } | ||
| 6052 | |||
| 6053 | ################## | ||
| 6054 | # Accessors - set | ||
| 6055 | |||
| 6056 | ################## | ||
| 6057 | # Accessors - get | ||
| 6058 | } | ||
| 6059 | |||
| 6060 | { package Games::Axmud::OtherWin::QuickWord; | ||
| 6061 | |||
| 6062 | use strict; | ||
| 6063 | use warnings; | ||
| 6064 | # use diagnostics; | ||
| 6065 | |||
| 6066 | use Glib qw(TRUE FALSE); | ||
| 6067 | |||
| 6068 | our @ISA = qw( | ||
| 6069 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 6070 | Games::Axmud | ||
| 6071 | ); | ||
| 6072 | |||
| 6073 | ################## | ||
| 6074 | # Constructors | ||
| 6075 | |||
| 6076 | sub new { | ||
| 6077 | |||
| 6078 | # Called by GA::Generic::Win->createFreeWin | ||
| 6079 | # Creates a new instance of the Quick Word window (an 'other' window). The window contains | ||
| 6080 | # various widgets for adding words to the current dictionary | ||
| 6081 | # | ||
| 6082 | # Expected arguments | ||
| 6083 | # $number - Unique number for this window object | ||
| 6084 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 6085 | # should be created | ||
| 6086 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 6087 | # 'free' window object. When this window opens/closes, the owner is | ||
| 6088 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 6089 | # functions | ||
| 6090 | # | ||
| 6091 | # Optional arguments | ||
| 6092 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 6093 | # calling function didn't specify a session and $owner's ->session IV | ||
| 6094 | # is also 'undef' | ||
| 6095 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 6096 | # $editObj - Ignored if set | ||
| 6097 | # $tempFlag - Ignored if set | ||
| 6098 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 6099 | # particular 'other' window; set to an empty hash if not required | ||
| 6100 | # - This type of window object recognises these initialisation settings: | ||
| 6101 | # | ||
| 6102 | # ... | ||
| 6103 | # | ||
| 6104 | # Return values | ||
| 6105 | # 'undef' on improper arguments | ||
| 6106 | # Blessed reference to the newly-created object on success | ||
| 6107 | |||
| 6108 | my ( | ||
| 6109 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 6110 | %configHash, | ||
| 6111 | ) = @_; | ||
| 6112 | |||
| 6113 | # Check for improper arguments | ||
| 6114 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 6115 | |||
| 6116 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 6117 | } | ||
| 6118 | |||
| 6119 | # Setup | ||
| 6120 | my $self = { | ||
| 6121 | _objName => 'other_win_' . $number, | ||
| 6122 | _objClass => $class, | ||
| 6123 | _parentFile => undef, # No parent file object | ||
| 6124 | _parentWorld => undef, # No parent file object | ||
| 6125 | _privFlag => TRUE, # All IVs are private | ||
| 6126 | |||
| 6127 | # Standard window object IVs | ||
| 6128 | # -------------------------- | ||
| 6129 | |||
| 6130 | # Unique number for this window object | ||
| 6131 | number => $number, | ||
| 6132 | # The window category - 'grid' or 'free' | ||
| 6133 | winCategory => 'free', | ||
| 6134 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 6135 | winType => 'other', | ||
| 6136 | # A name for the window (can be unique to this type of window object, or can be the | ||
| 6137 | # same as ->winType) | ||
| 6138 | winName => 'quick_word', | ||
| 6139 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 6140 | workspaceObj => $workspaceObj, | ||
| 6141 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 6142 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 6143 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 6144 | owner => $owner, | ||
| 6145 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 6146 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 6147 | session => $session, | ||
| 6148 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 6149 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 6150 | # displayed in a 'dialogue' window) | ||
| 6151 | pseudoCmdMode => 'win_error', | ||
| 6152 | |||
| 6153 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 6154 | # parent 'main' window's Gtk3::Window | ||
| 6155 | # The code should use this IV when it wants to do something to the window itself | ||
| 6156 | # (minimise it, make it active, etc) | ||
| 6157 | winWidget => undef, | ||
| 6158 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 6159 | # the parent GA::Table::PseudoWin table object | ||
| 6160 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 6161 | # window itself | ||
| 6162 | winBox => undef, | ||
| 6163 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 6164 | # FALSE if not | ||
| 6165 | enabledFlag => FALSE, | ||
| 6166 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 6167 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 6168 | visibleFlag => TRUE, | ||
| 6169 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 6170 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 6171 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 6172 | childFreeWinHash => {}, | ||
| 6173 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 6174 | # window is informed via a call to $self->del_childFreeWin | ||
| 6175 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 6176 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 6177 | # this hash; a hash in the form | ||
| 6178 | # $childDestroyHash{unique_number} = list_reference | ||
| 6179 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 6180 | # reference to a list in groups of 2, in the form | ||
| 6181 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 6182 | childDestroyHash => {}, | ||
| 6183 | |||
| 6184 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 6185 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 6186 | # area) | ||
| 6187 | packingBox => undef, # Gtk3::VBox | ||
| 6188 | |||
| 6189 | # Standard IVs for 'free' windows | ||
| 6190 | |||
| 6191 | # The window's default size, in pixels | ||
| 6192 | # (Actual width/height will be more, in order to fit in all the packed widgets) | ||
| 6193 | widthPixels => int($axmud::CLIENT->constFreeWinWidth * 0.33), | ||
| 6194 | heightPixels => int($axmud::CLIENT->constFreeWinHeight * 0.33), | ||
| 6195 | # Default border/item spacing sizes used in the window, in pixels | ||
| 6196 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 6197 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 6198 | |||
| 6199 | # A string to use as the window title | ||
| 6200 | title => $title, | ||
| 6201 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 6202 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 6203 | # name and type. Set to an empty hash if not required | ||
| 6204 | configHash => {%configHash}, | ||
| 6205 | }; | ||
| 6206 | |||
| 6207 | # Bless the object into existence | ||
| 6208 | bless $self, $class; | ||
| 6209 | |||
| 6210 | return $self; | ||
| 6211 | } | ||
| 6212 | |||
| 6213 | ################## | ||
| 6214 | # Methods | ||
| 6215 | |||
| 6216 | # Standard window object functions | ||
| 6217 | |||
| 6218 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 6219 | |||
| 6220 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 6221 | |||
| 6222 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 6223 | |||
| 6224 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 6225 | |||
| 6226 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 6227 | |||
| 6228 | sub drawWidgets { | ||
| 6229 | |||
| 6230 | # Called by $self->winSetup | ||
| 6231 | # Sets up the Gtk3::Window by drawing the window's widgets | ||
| 6232 | # | ||
| 6233 | # Expected arguments | ||
| 6234 | # (none besides $self) | ||
| 6235 | # | ||
| 6236 | # Return values | ||
| 6237 | # 'undef' on improper arguments | ||
| 6238 | # 1 otherwise | ||
| 6239 | |||
| 6240 | my ($self, $check) = @_; | ||
| 6241 | |||
| 6242 | # Local variables | ||
| 6243 | my ( | ||
| 6244 | $spacing, $dictObj, $comboBoxCount, | ||
| 6245 | @currentRoomList, @typeList, | ||
| 6246 | ); | ||
| 6247 | |||
| 6248 | # Check for improper arguments | ||
| 6249 | if (defined $check) { | ||
| 6250 | |||
| 6251 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 6252 | } | ||
| 6253 | |||
| 6254 | # Standard spacing | ||
| 6255 | $spacing = $axmud::CLIENT->constFreeSpacingPixels; | ||
| 6256 | # Import the current Locator task (if any) and current dictionary | ||
| 6257 | $dictObj = $self->session->currentDict; | ||
| 6258 | |||
| 6259 | # A list of word types in the order they'll appear in their combobox | ||
| 6260 | @typeList = ( | ||
| 6261 | 'sentient', | ||
| 6262 | 'creature', | ||
| 6263 | 'portable', | ||
| 6264 | 'decoration', | ||
| 6265 | 'race', | ||
| 6266 | 'guild', | ||
| 6267 | 'weapon', | ||
| 6268 | 'armour', | ||
| 6269 | 'garment', | ||
| 6270 | 'adjective', | ||
| 6271 | 'pseudo-noun', | ||
| 6272 | 'pseudo-adjective', | ||
| 6273 | 'pseudo-object', | ||
| 6274 | ); | ||
| 6275 | |||
| 6276 | # Create a packing box | ||
| 6277 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 6278 | $self->winBox->add($packingBox); | ||
| 6279 | $packingBox->set_border_width(0); | ||
| 6280 | |||
| 6281 | # Create an image on the left | ||
| 6282 | my $hBox = Gtk3::HBox->new(FALSE, $spacing); | ||
| 6283 | $packingBox->pack_start($hBox, FALSE, FALSE, 0); | ||
| 6284 | |||
| 6285 | my $vBox = Gtk3::VBox->new(FALSE, 0); | ||
| 6286 | $hBox->pack_start($vBox, FALSE, FALSE, 0); | ||
| 6287 | |||
| 6288 | my $frame = Gtk3::Frame->new(undef); | ||
| 6289 | $vBox->pack_start($frame, FALSE, FALSE, 0); | ||
| 6290 | $frame->set_size_request(64, 64); | ||
| 6291 | $frame->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 6292 | |||
| 6293 | my $image = Gtk3::Image->new_from_file($axmud::CLIENT->getDialogueIcon()); | ||
| 6294 | $frame->add($image); | ||
| 6295 | |||
| 6296 | # Create a VBox on the right, full of editing widgets | ||
| 6297 | my $vBox2 = Gtk3::VBox->new(FALSE, $spacing); | ||
| 6298 | $hBox->pack_start($vBox2, FALSE, FALSE, 0); | ||
| 6299 | |||
| 6300 | # Add three radio buttons and an entry box/combo for each (->signal_connects follow) | ||
| 6301 | my $radioButton = Gtk3::RadioButton->new_with_label(undef, 'Enter a word...'); | ||
| 6302 | my $radioGroup = $radioButton->get_group(); | ||
| 6303 | $vBox2->pack_start($radioButton, FALSE, FALSE, 0); | ||
| 6304 | |||
| 6305 | my $entry = Gtk3::Entry->new(); | ||
| 6306 | $vBox2->pack_start($entry, FALSE, FALSE, 0); | ||
| 6307 | |||
| 6308 | my $radioButton2 = Gtk3::RadioButton->new_with_label( | ||
| 6309 | $radioGroup, | ||
| 6310 | '...or select a word from the current room...', | ||
| 6311 | ); | ||
| 6312 | $vBox2->pack_start($radioButton2, FALSE, FALSE, 0); | ||
| 6313 | |||
| 6314 | my $comboBox = Gtk3::ComboBoxText->new(); | ||
| 6315 | $vBox2->pack_start($comboBox, FALSE, FALSE, 0); | ||
| 6316 | $comboBox->set_active(0); | ||
| 6317 | # Starts desensitised | ||
| 6318 | $comboBox->set_sensitive(FALSE); | ||
| 6319 | |||
| 6320 | my $radioButton3 = Gtk3::RadioButton->new_with_label( | ||
| 6321 | $radioGroup, | ||
| 6322 | '...or select an unknown word', | ||
| 6323 | ); | ||
| 6324 | $vBox2->pack_start($radioButton3, FALSE, FALSE, 0); | ||
| 6325 | |||
| 6326 | my $comboBox2 = Gtk3::ComboBoxText->new(); | ||
| 6327 | $vBox2->pack_start($comboBox2, FALSE, FALSE, 0); | ||
| 6328 | $comboBox2->set_active(0); | ||
| 6329 | # Starts desensitised | ||
| 6330 | $comboBox2->set_sensitive(FALSE); | ||
| 6331 | |||
| 6332 | my $separator = Gtk3::HSeparator->new(); | ||
| 6333 | $vBox2->pack_start($separator, FALSE, FALSE, 0); | ||
| 6334 | |||
| 6335 | # Add a fourth widget group, comboboxes to select the types of word | ||
| 6336 | my $label = Gtk3::Label->new('What kind of word is this?'); | ||
| 6337 | $vBox2->pack_start($label, FALSE, FALSE, 0); | ||
| 6338 | $label->set_alignment(0, 0.5); | ||
| 6339 | |||
| 6340 | my $hBox2 = Gtk3::HBox->new(FALSE, 0); | ||
| 6341 | $vBox2->pack_start($hBox2, FALSE, FALSE, 5); | ||
| 6342 | |||
| 6343 | my $comboBox3 = Gtk3::ComboBoxText->new(); | ||
| 6344 | $hBox2->pack_start($comboBox3, TRUE, TRUE, 0); | ||
| 6345 | foreach my $type (@typeList) { | ||
| 6346 | |||
| 6347 | $comboBox3->append_text($type); | ||
| 6348 | } | ||
| 6349 | $comboBox3->set_active(0); | ||
| 6350 | |||
| 6351 | my $comboBox4 = Gtk3::ComboBoxText->new(); | ||
| 6352 | $hBox2->pack_end($comboBox4, TRUE, TRUE, 0); | ||
| 6353 | $comboBox4->set_active(0); | ||
| 6354 | $comboBox4->set_sensitive(FALSE); | ||
| 6355 | |||
| 6356 | # And a fifth group to specify replacement strings for pseudo nouns, adjectives and objects | ||
| 6357 | my $label2 = Gtk3::Label->new('Replacement string (if any)'); | ||
| 6358 | $vBox2->pack_start($label2, FALSE, FALSE, 0); | ||
| 6359 | $label2->set_alignment(0, 0.5); | ||
| 6360 | |||
| 6361 | my $entry2 = Gtk3::Entry->new(); | ||
| 6362 | $vBox2->pack_start($entry2, FALSE, FALSE, 0); | ||
| 6363 | # Entry starts insensitive | ||
| 6364 | $entry2->set_sensitive(FALSE); | ||
| 6365 | |||
| 6366 | my $separator2 = Gtk3::HSeparator->new(); | ||
| 6367 | $vBox2->pack_start($separator2, FALSE, FALSE, 0); | ||
| 6368 | |||
| 6369 | # Finally, at buttons at the bottom of the window | ||
| 6370 | my $label3 = Gtk3::Label->new(''); | ||
| 6371 | $vBox2->pack_start($label3, FALSE, FALSE, 0); | ||
| 6372 | $label3->set_alignment(0, 0.5); | ||
| 6373 | |||
| 6374 | my $hBox3 = Gtk3::HBox->new(FALSE, 0); | ||
| 6375 | $vBox2->pack_start($hBox3, FALSE, FALSE, $self->spacingPixels); | ||
| 6376 | |||
| 6377 | my $button = Gtk3::Button->new('Add word'); | ||
| 6378 | $hBox3->pack_start($button, TRUE, TRUE, 0); | ||
| 6379 | $button->set_tooltip_text('Add this word'); | ||
| 6380 | |||
| 6381 | my $button2 = Gtk3::Button->new('Ignore word'); | ||
| 6382 | $hBox3->pack_start($button2, TRUE, TRUE, 0); | ||
| 6383 | $button2->set_sensitive(FALSE); # Starts desensitised | ||
| 6384 | $button2->set_tooltip_text('Ignore (don\'t use) this word'); | ||
| 6385 | |||
| 6386 | my $button3 = Gtk3::Button->new('Refresh'); | ||
| 6387 | $hBox3->pack_start($button3, TRUE, TRUE, 0); | ||
| 6388 | $button3->signal_connect('clicked' => sub { | ||
| 6389 | |||
| 6390 | $self->refreshCombos($dictObj, $comboBox, $comboBox2); | ||
| 6391 | }); | ||
| 6392 | |||
| 6393 | my $button4 = Gtk3::Button->new('Close'); | ||
| 6394 | $hBox3->pack_end($button4, TRUE, TRUE, 0); | ||
| 6395 | $button4->signal_connect('clicked' => sub { | ||
| 6396 | |||
| 6397 | $self->winDestroy(); | ||
| 6398 | }); | ||
| 6399 | $button4->set_tooltip_text('Close the window'); | ||
| 6400 | |||
| 6401 | # Set the initial contents of the first two comboboxes | ||
| 6402 | $self->refreshCombos($dictObj, $comboBox, $comboBox2); | ||
| 6403 | |||
| 6404 | # ->signal_connects | ||
| 6405 | |||
| 6406 | # Radio buttons. Toggling them sensitises/desensitises the first three widgets | ||
| 6407 | $radioButton->signal_connect('toggled' => sub { | ||
| 6408 | |||
| 6409 | if ($radioButton->get_active()) { | ||
| 6410 | |||
| 6411 | $entry->set_sensitive(TRUE); | ||
| 6412 | $comboBox->set_sensitive(FALSE); | ||
| 6413 | $comboBox2->set_sensitive(FALSE); | ||
| 6414 | $button2->set_sensitive(FALSE); | ||
| 6415 | } | ||
| 6416 | }); | ||
| 6417 | |||
| 6418 | $radioButton2->signal_connect('toggled' => sub { | ||
| 6419 | |||
| 6420 | if ($radioButton2->get_active()) { | ||
| 6421 | |||
| 6422 | $entry->set_sensitive(FALSE); | ||
| 6423 | $comboBox->set_sensitive(TRUE); | ||
| 6424 | $comboBox2->set_sensitive(FALSE); | ||
| 6425 | $button2->set_sensitive(FALSE); | ||
| 6426 | } | ||
| 6427 | }); | ||
| 6428 | |||
| 6429 | $radioButton3->signal_connect('toggled' => sub { | ||
| 6430 | |||
| 6431 | if ($radioButton3->get_active()) { | ||
| 6432 | |||
| 6433 | $entry->set_sensitive(FALSE); | ||
| 6434 | $comboBox->set_sensitive(FALSE); | ||
| 6435 | $comboBox2->set_sensitive(TRUE); | ||
| 6436 | $button2->set_sensitive(TRUE); | ||
| 6437 | } | ||
| 6438 | }); | ||
| 6439 | |||
| 6440 | # Fourth group | ||
| 6441 | $comboBox3->signal_connect('changed' => sub { | ||
| 6442 | |||
| 6443 | my $type = $comboBox3->get_active_text(); | ||
| 6444 | if ($type) { | ||
| 6445 | |||
| 6446 | # Empty the 'type of portable/decoration' combobox, in case we need to refill it | ||
| 6447 | if ($comboBoxCount) { | ||
| 6448 | |||
| 6449 | for (my $count = ($comboBoxCount - 1); $count >= 0; $count--) { | ||
| 6450 | |||
| 6451 | $comboBox4->remove_text($count); | ||
| 6452 | } | ||
| 6453 | } | ||
| 6454 | |||
| 6455 | # Refill the lower combobox, if necessary | ||
| 6456 | if ($type eq 'portable') { | ||
| 6457 | |||
| 6458 | foreach my $custom ($dictObj->portableTypeList) { | ||
| 6459 | |||
| 6460 | $comboBox4->append_text($custom); | ||
| 6461 | } | ||
| 6462 | |||
| 6463 | $comboBox4->set_active(0); | ||
| 6464 | $comboBox4->set_sensitive(TRUE); | ||
| 6465 | $comboBoxCount = scalar $dictObj->portableTypeList; | ||
| 6466 | |||
| 6467 | } elsif ($type eq 'decoration') { | ||
| 6468 | |||
| 6469 | foreach my $custom ($dictObj->decorationTypeList) { | ||
| 6470 | |||
| 6471 | $comboBox4->append_text($custom); | ||
| 6472 | } | ||
| 6473 | |||
| 6474 | $comboBox4->set_active(0); | ||
| 6475 | $comboBox4->set_sensitive(TRUE); | ||
| 6476 | $comboBoxCount = scalar $dictObj->decorationTypeList; | ||
| 6477 | |||
| 6478 | } else { | ||
| 6479 | |||
| 6480 | # If it's not a portable or decoration, the lower combobox must be insensitive | ||
| 6481 | $comboBox4->set_sensitive(FALSE); | ||
| 6482 | $comboBoxCount = 0; | ||
| 6483 | } | ||
| 6484 | |||
| 6485 | if ( | ||
| 6486 | $type eq 'pseudo-noun' | ||
| 6487 | || $type eq 'pseudo-adjective' | ||
| 6488 | || $type eq 'pseudo-object' | ||
| 6489 | ) { | ||
| 6490 | # Make the replacement string entry sensitive | ||
| 6491 | $entry2->set_sensitive(TRUE); | ||
| 6492 | |||
| 6493 | } else { | ||
| 6494 | |||
| 6495 | # Empty the box and make it insensitive | ||
| 6496 | $entry2->set_text(''); | ||
| 6497 | $entry2->set_sensitive(FALSE); | ||
| 6498 | } | ||
| 6499 | } | ||
| 6500 | }); | ||
| 6501 | |||
| 6502 | # 'Add word' button | ||
| 6503 | $button->signal_connect('clicked' => sub { | ||
| 6504 | |||
| 6505 | my ( | ||
| 6506 | $word, $wordType, $category, $replace, $cmd, $result, $msg, | ||
| 6507 | @newList, | ||
| 6508 | ); | ||
| 6509 | |||
| 6510 | # Get the word to add | ||
| 6511 | if ($radioButton->get_active()) { | ||
| 6512 | $word = $entry->get_text(); | ||
| 6513 | } elsif ($radioButton2->get_active()) { | ||
| 6514 | $word = $comboBox->get_active_text(); | ||
| 6515 | } elsif ($radioButton3->get_active()) { | ||
| 6516 | $word = $comboBox2->get_active_text(); | ||
| 6517 | } | ||
| 6518 | |||
| 6519 | # Get the type of word, and the category (for portables/decorations) | ||
| 6520 | $wordType = $comboBox3->get_active_text(); | ||
| 6521 | $category = $comboBox4->get_active_text(); | ||
| 6522 | |||
| 6523 | # Get the replacement string for pseudos | ||
| 6524 | $replace = $entry2->get_text(); | ||
| 6525 | |||
| 6526 | if ($word && $wordType) { | ||
| 6527 | |||
| 6528 | # Prepare the client command to use | ||
| 6529 | $cmd = 'addword '; | ||
| 6530 | |||
| 6531 | if ($wordType eq 'sentient') { | ||
| 6532 | $cmd .= '-s <' . $word . '>'; | ||
| 6533 | } elsif ($wordType eq 'creature') { | ||
| 6534 | $cmd .= '-k <' . $word . '>'; | ||
| 6535 | } elsif ($wordType eq 'race') { | ||
| 6536 | $cmd .= '-r <' . $word . '>'; | ||
| 6537 | } elsif ($wordType eq 'guild') { | ||
| 6538 | $cmd .= '-g <' . $word . '>'; | ||
| 6539 | } elsif ($wordType eq 'weapon') { | ||
| 6540 | $cmd .= '-w <' . $word . '>'; | ||
| 6541 | } elsif ($wordType eq 'armour') { | ||
| 6542 | $cmd .= '-a <' . $word . '>'; | ||
| 6543 | } elsif ($wordType eq 'garment') { | ||
| 6544 | $cmd .= '-e <' . $word . '>'; | ||
| 6545 | } elsif ($wordType eq 'adjective') { | ||
| 6546 | $cmd .= '-j <' . $word . '>'; | ||
| 6547 | } elsif ($wordType eq 'portable' && $category) { | ||
| 6548 | $cmd .= '-p <' . $word . '> <' . $category . '>'; | ||
| 6549 | } elsif ($wordType eq 'decoration' && $category) { | ||
| 6550 | $cmd .= '-d <' . $word . '> <' . $category . '>'; | ||
| 6551 | } elsif ($wordType eq 'pseudo-noun' && $replace) { | ||
| 6552 | |||
| 6553 | # Replacement string compulsory for pseudo-nouns | ||
| 6554 | $cmd .= '-x <' . $replace . '> <' . $word . '>'; | ||
| 6555 | |||
| 6556 | } elsif ($wordType eq 'pseudo-adjective') { | ||
| 6557 | |||
| 6558 | # Replacement optional for pseudo-adjectives | ||
| 6559 | $cmd .= '-y <' . $replace . '> <' . $word . '>'; | ||
| 6560 | |||
| 6561 | } elsif ($wordType eq 'pseudo-object') { | ||
| 6562 | |||
| 6563 | # Replacement optional for pseudo-objects | ||
| 6564 | $cmd .= '-v <' . $word . '> <' . $replace . '>'; | ||
| 6565 | } | ||
| 6566 | |||
| 6567 | # Add the word | ||
| 6568 | $result = $self->session->pseudoCmd($cmd, $self->pseudoCmdMode); | ||
| 6569 | |||
| 6570 | # Prepare a confirmation to show in the last Gtk3::Label | ||
| 6571 | if ($result) { | ||
| 6572 | |||
| 6573 | if ($wordType eq 'portable' || $wordType eq 'decoration') { | ||
| 6574 | |||
| 6575 | $msg = '<i>Added ' . $wordType . ' (' . $category . ') \'' . $word | ||
| 6576 | . '\'</i>'; | ||
| 6577 | |||
| 6578 | } else { | ||
| 6579 | |||
| 6580 | $msg = '<i>Added ' . $wordType . ' \'' . $word . '\'</i>'; | ||
| 6581 | } | ||
| 6582 | |||
| 6583 | } else { | ||
| 6584 | |||
| 6585 | $msg = '<i>Failed to add ' . $wordType . ' \'' . $word . '\'</i>'; | ||
| 6586 | } | ||
| 6587 | |||
| 6588 | } else { | ||
| 6589 | |||
| 6590 | # Clear the confirmation label | ||
| 6591 | $msg = ''; | ||
| 6592 | } | ||
| 6593 | |||
| 6594 | # Show the confirmation message | ||
| 6595 | $label3->set_markup($msg); | ||
| 6596 | |||
| 6597 | if ($result) { | ||
| 6598 | |||
| 6599 | # If we've just added a word from the room, it should be removed from the combo | ||
| 6600 | # If we've just added an unknown word, the dictionary's list of unknown words will | ||
| 6601 | # have changed. Update the combo | ||
| 6602 | if ( | ||
| 6603 | $radioButton2->get_active() | ||
| 6604 | || $radioButton3->get_active() | ||
| 6605 | ) { | ||
| 6606 | $self->refreshCombos($dictObj, $comboBox, $comboBox2); | ||
| 6607 | } | ||
| 6608 | } | ||
| 6609 | }); | ||
| 6610 | |||
| 6611 | # 'Ignore word' button | ||
| 6612 | $button2->signal_connect('clicked' => sub { | ||
| 6613 | |||
| 6614 | my $word = $comboBox2->get_active_text(); | ||
| 6615 | if ($word) { | ||
| 6616 | |||
| 6617 | $label3->set_markup('Ignoring \'' . $word . '\''); | ||
| 6618 | |||
| 6619 | # Remove this word from the current dictionary's unknown word collection | ||
| 6620 | $self->session->currentDict->ivDelete('unknownWordHash', $word); | ||
| 6621 | |||
| 6622 | # Update the combos | ||
| 6623 | $self->refreshCombos($dictObj, $comboBox, $comboBox2); | ||
| 6624 | } | ||
| 6625 | }); | ||
| 6626 | |||
| 6627 | # Update IVs (not worth storing widgets other than the main packing box) | ||
| 6628 | $self->ivPoke('packingBox', $packingBox); | ||
| 6629 | |||
| 6630 | return 1; | ||
| 6631 | } | ||
| 6632 | |||
| 6633 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 6634 | |||
| 6635 | # ->signal_connects | ||
| 6636 | |||
| 6637 | # Other functions | ||
| 6638 | |||
| 6639 | sub refreshCombos { | ||
| 6640 | |||
| 6641 | # Called by $self->drawWidgets | ||
| 6642 | # Refreshes the contents of the first two comboboxes | ||
| 6643 | # | ||
| 6644 | # Expected arguments | ||
| 6645 | # $dictObj - The current dictionary | ||
| 6646 | # $comboBox, $comboBox2 | ||
| 6647 | # - The comboboxes to refresh | ||
| 6648 | # | ||
| 6649 | # Return values | ||
| 6650 | # 'undef' on improper arguments | ||
| 6651 | # 1 otherwise | ||
| 6652 | |||
| 6653 | my ($self, $dictObj, $comboBox, $comboBox2, $check) = @_; | ||
| 6654 | |||
| 6655 | # Local variables | ||
| 6656 | my ( | ||
| 6657 | $taskObj, | ||
| 6658 | @unknownList, @collectedList, | ||
| 6659 | %wordHash, | ||
| 6660 | ); | ||
| 6661 | |||
| 6662 | # Check for improper arguments | ||
| 6663 | if (! defined $dictObj || ! defined $comboBox || ! defined $comboBox2 || defined $check) { | ||
| 6664 | |||
| 6665 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshCombos', @_); | ||
| 6666 | } | ||
| 6667 | |||
| 6668 | # Import the current Locator task (if any) | ||
| 6669 | $taskObj = $self->session->locatorTask; | ||
| 6670 | |||
| 6671 | # Compile a list of words (which aren't already in the dictionary) from objects in the | ||
| 6672 | # Locator task's current room | ||
| 6673 | if ( | ||
| 6674 | $taskObj | ||
| 6675 | && $taskObj->roomObj | ||
| 6676 | && $taskObj->roomObj->tempObjList | ||
| 6677 | ) { | ||
| 6678 | OUTER: foreach my $obj ($taskObj->roomObj->tempObjList) { | ||
| 6679 | |||
| 6680 | my @wordList; | ||
| 6681 | |||
| 6682 | push (@wordList, | ||
| 6683 | $obj->noun, | ||
| 6684 | $obj->otherNounList, | ||
| 6685 | $obj->adjList, | ||
| 6686 | $obj->pseudoAdjList, | ||
| 6687 | $obj->unknownWordList, | ||
| 6688 | ); | ||
| 6689 | |||
| 6690 | foreach my $word (@wordList) { | ||
| 6691 | |||
| 6692 | # If the word isn't in the current dictionary, mark it to be added to the | ||
| 6693 | # combobox. Use a hash to eliminate duplicates | ||
| 6694 | if ( | ||
| 6695 | ! $dictObj->ivExists('combNounHash', $word) | ||
| 6696 | && ! $dictObj->ivExists('combAdjHash', $word) | ||
| 6697 | ) { | ||
| 6698 | $wordHash{$word} = undef; | ||
| 6699 | } | ||
| 6700 | } | ||
| 6701 | } | ||
| 6702 | |||
| 6703 | # Convert the hash to a sorted list | ||
| 6704 | @unknownList = sort {lc($a) cmp lc($b)} (keys %wordHash); | ||
| 6705 | } | ||
| 6706 | |||
| 6707 | # Import the list of unknown words collected by the Locator task and stored in the current | ||
| 6708 | # dictionary | ||
| 6709 | @collectedList = sort {lc($a) cmp lc($b)} ($dictObj->ivKeys('unknownWordHash')); | ||
| 6710 | |||
| 6711 | # Refresh the combos | ||
| 6712 | my $treeModel = $comboBox->get_model(); | ||
| 6713 | $treeModel->clear(); | ||
| 6714 | |||
| 6715 | foreach my $item (@unknownList) { | ||
| 6716 | |||
| 6717 | $comboBox->append_text($item); | ||
| 6718 | } | ||
| 6719 | |||
| 6720 | $comboBox->set_active(0); | ||
| 6721 | |||
| 6722 | my $treeModel2 = $comboBox2->get_model(); | ||
| 6723 | $treeModel2->clear(); | ||
| 6724 | |||
| 6725 | foreach my $item (@collectedList) { | ||
| 6726 | |||
| 6727 | $comboBox2->append_text($item); | ||
| 6728 | } | ||
| 6729 | |||
| 6730 | $comboBox2->set_active(0); | ||
| 6731 | |||
| 6732 | return 1; | ||
| 6733 | } | ||
| 6734 | |||
| 6735 | ################## | ||
| 6736 | # Accessors - set | ||
| 6737 | |||
| 6738 | ################## | ||
| 6739 | # Accessors - get | ||
| 6740 | } | ||
| 6741 | |||
| 6742 | { package Games::Axmud::OtherWin::SessionConsole; | ||
| 6743 | |||
| 6744 | use strict; | ||
| 6745 | use warnings; | ||
| 6746 | # use diagnostics; | ||
| 6747 | |||
| 6748 | use Glib qw(TRUE FALSE); | ||
| 6749 | |||
| 6750 | our @ISA = qw( | ||
| 6751 | Games::Axmud::OtherWin::ClientConsole Games::Axmud::Generic::OtherWin | ||
| 6752 | Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud | ||
| 6753 | ); | ||
| 6754 | |||
| 6755 | ################## | ||
| 6756 | # Constructors | ||
| 6757 | |||
| 6758 | sub new { | ||
| 6759 | |||
| 6760 | # Called by GA::Generic::Win->createFreeWin | ||
| 6761 | # Creates a new instance of the Session Console window, which can display system messages | ||
| 6762 | # when it's not possible to display them in the 'main' window | ||
| 6763 | # | ||
| 6764 | # Expected arguments | ||
| 6765 | # $number - Unique number for this window object | ||
| 6766 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 6767 | # should be created | ||
| 6768 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 6769 | # 'free' window object. When this window opens/closes, the owner is | ||
| 6770 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 6771 | # functions | ||
| 6772 | # | ||
| 6773 | # Optional arguments | ||
| 6774 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 6775 | # calling function didn't specify a session and $owner's ->session IV | ||
| 6776 | # is also 'undef' | ||
| 6777 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 6778 | # $editObj - Ignored if set | ||
| 6779 | # $tempFlag - Ignored if set | ||
| 6780 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 6781 | # particular 'other' window; set to an empty hash if not required | ||
| 6782 | # - This type of window object recognises these initialisation settings: | ||
| 6783 | # | ||
| 6784 | # ... | ||
| 6785 | # | ||
| 6786 | # Return values | ||
| 6787 | # 'undef' on improper arguments | ||
| 6788 | # Blessed reference to the newly-created object on success | ||
| 6789 | |||
| 6790 | my ( | ||
| 6791 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 6792 | %configHash, | ||
| 6793 | ) = @_; | ||
| 6794 | |||
| 6795 | # Check for improper arguments | ||
| 6796 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 6797 | |||
| 6798 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 6799 | } | ||
| 6800 | |||
| 6801 | # Only one Session Console window can be open per session | ||
| 6802 | if (! $session) { | ||
| 6803 | |||
| 6804 | return undef; | ||
| 6805 | |||
| 6806 | } elsif ($session->consoleWin) { | ||
| 6807 | |||
| 6808 | $session->consoleWin->restoreFocus(); | ||
| 6809 | return undef; | ||
| 6810 | } | ||
| 6811 | |||
| 6812 | # Setup | ||
| 6813 | my $self = { | ||
| 6814 | _objName => 'other_win_' . $number, | ||
| 6815 | _objClass => $class, | ||
| 6816 | _parentFile => undef, # No parent file object | ||
| 6817 | _parentWorld => undef, # No parent file object | ||
| 6818 | _privFlag => TRUE, # All IVs are private | ||
| 6819 | |||
| 6820 | # Standard window object IVs | ||
| 6821 | # -------------------------- | ||
| 6822 | |||
| 6823 | # Unique number for this window object | ||
| 6824 | number => $number, | ||
| 6825 | # The window category - 'grid' or 'free' | ||
| 6826 | winCategory => 'free', | ||
| 6827 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 6828 | winType => 'other', | ||
| 6829 | # A name for the window (for some 'free' windows, the same as the window type) | ||
| 6830 | winName => 'console', | ||
| 6831 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 6832 | workspaceObj => $workspaceObj, | ||
| 6833 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 6834 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 6835 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 6836 | owner => $owner, | ||
| 6837 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 6838 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 6839 | session => $session, | ||
| 6840 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 6841 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 6842 | # displayed in a 'dialogue' window) | ||
| 6843 | pseudoCmdMode => 'win_error', | ||
| 6844 | |||
| 6845 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 6846 | # parent 'main' window's Gtk3::Window | ||
| 6847 | # The code should use this IV when it wants to do something to the window itself | ||
| 6848 | # (minimise it, make it active, etc) | ||
| 6849 | winWidget => undef, | ||
| 6850 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 6851 | # the parent GA::Table::PseudoWin table object | ||
| 6852 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 6853 | # window itself | ||
| 6854 | winBox => undef, | ||
| 6855 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 6856 | # FALSE if not | ||
| 6857 | enabledFlag => FALSE, | ||
| 6858 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 6859 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 6860 | visibleFlag => TRUE, | ||
| 6861 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 6862 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 6863 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 6864 | childFreeWinHash => {}, | ||
| 6865 | |||
| 6866 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 6867 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 6868 | # area) | ||
| 6869 | packingBox => undef, # Gtk3::VBox | ||
| 6870 | |||
| 6871 | # Standard IVs for 'free' windows | ||
| 6872 | |||
| 6873 | # The window's default size, in pixels | ||
| 6874 | widthPixels => 600, | ||
| 6875 | heightPixels => 300, | ||
| 6876 | # Default border/item spacing sizes used in the window, in pixels | ||
| 6877 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 6878 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 6879 | |||
| 6880 | # A string to use as the window title. If 'undef', a generic title is used | ||
| 6881 | title => $axmud::SCRIPT . ' session console #' . $session->number, | ||
| 6882 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 6883 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 6884 | # name and type. Set to an empty hash if not required | ||
| 6885 | configHash => {%configHash}, | ||
| 6886 | |||
| 6887 | # IVs for this window | ||
| 6888 | textView => undef, # Gtk3::TextView | ||
| 6889 | buffer => undef, # Gtk3::TextBuffer | ||
| 6890 | }; | ||
| 6891 | |||
| 6892 | # Bless the object into existence | ||
| 6893 | bless $self, $class; | ||
| 6894 | |||
| 6895 | return $self; | ||
| 6896 | } | ||
| 6897 | |||
| 6898 | ################## | ||
| 6899 | # Methods | ||
| 6900 | |||
| 6901 | # Standard window object functions | ||
| 6902 | |||
| 6903 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 6904 | |||
| 6905 | sub winEnable { | ||
| 6906 | |||
| 6907 | # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup | ||
| 6908 | # After the Gtk3::Window has been setup and moved into position, makes it visible | ||
| 6909 | # | ||
| 6910 | # Expected arguments | ||
| 6911 | # (none besides $self) | ||
| 6912 | # | ||
| 6913 | # Return values | ||
| 6914 | # 'undef' on improper arguments | ||
| 6915 | # 1 on success | ||
| 6916 | |||
| 6917 | my ($self, $check) = @_; | ||
| 6918 | |||
| 6919 | # Local variables | ||
| 6920 | my @list; | ||
| 6921 | |||
| 6922 | # Check for improper arguments | ||
| 6923 | if (defined $check) { | ||
| 6924 | |||
| 6925 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_); | ||
| 6926 | } | ||
| 6927 | |||
| 6928 | # Make the window appear on the desktop | ||
| 6929 | $self->winShowAll($self->_objClass . '->winEnable'); | ||
| 6930 | $self->ivPoke('enabledFlag', TRUE); | ||
| 6931 | |||
| 6932 | # This type of window is unique (only one can be open per session); inform the GA::Session | ||
| 6933 | # it has opened | ||
| 6934 | $self->session->set_consoleWin($self); | ||
| 6935 | |||
| 6936 | # If any system messages have been stored, we can display them now | ||
| 6937 | @list = $self->session->systemMsgList; | ||
| 6938 | if (@list) { | ||
| 6939 | |||
| 6940 | do { | ||
| 6941 | |||
| 6942 | my ($type, $msg); | ||
| 6943 | |||
| 6944 | $type = shift @list; | ||
| 6945 | $msg = shift @list; | ||
| 6946 | |||
| 6947 | $self->update($type, $msg); | ||
| 6948 | |||
| 6949 | } until (! @list); | ||
| 6950 | } | ||
| 6951 | |||
| 6952 | # Each system message is displayed here only once | ||
| 6953 | $self->session->reset_systemMsg(); | ||
| 6954 | |||
| 6955 | return 1; | ||
| 6956 | } | ||
| 6957 | |||
| 6958 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 6959 | |||
| 6960 | sub winDestroy { | ||
| 6961 | |||
| 6962 | # Can be called by anything | ||
| 6963 | # Updates IVs | ||
| 6964 | # | ||
| 6965 | # Expected arguments | ||
| 6966 | # (none besides $self) | ||
| 6967 | # | ||
| 6968 | # Return values | ||
| 6969 | # 'undef' on improper arguments, if the window can't be destroyed or if it has already | ||
| 6970 | # been destroyed | ||
| 6971 | # 1 on success | ||
| 6972 | |||
| 6973 | my ($self, $check) = @_; | ||
| 6974 | |||
| 6975 | # Check for improper arguments | ||
| 6976 | if (defined $check) { | ||
| 6977 | |||
| 6978 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_); | ||
| 6979 | } | ||
| 6980 | |||
| 6981 | if (! $self->winBox) { | ||
| 6982 | |||
| 6983 | # Window already destroyed in a previous call to this function | ||
| 6984 | return undef; | ||
| 6985 | } | ||
| 6986 | |||
| 6987 | # Close any 'free' windows for which this window is a parent | ||
| 6988 | foreach my $winObj ($self->ivValues('childFreeWinHash')) { | ||
| 6989 | |||
| 6990 | $winObj->winDestroy(); | ||
| 6991 | } | ||
| 6992 | |||
| 6993 | # Destroy the Gtk3::Window | ||
| 6994 | eval { $self->winBox->destroy(); }; | ||
| 6995 | if ($@) { | ||
| 6996 | |||
| 6997 | # Window can't be destroyed | ||
| 6998 | return undef; | ||
| 6999 | |||
| 7000 | } else { | ||
| 7001 | |||
| 7002 | $self->ivUndef('winWidget'); | ||
| 7003 | $self->ivUndef('winBox'); | ||
| 7004 | } | ||
| 7005 | |||
| 7006 | # Inform the owner and the desktop object of this 'free' window's demise | ||
| 7007 | $axmud::CLIENT->desktopObj->del_freeWin($self); | ||
| 7008 | if ($self->owner) { | ||
| 7009 | |||
| 7010 | $self->owner->del_childFreeWin($self); | ||
| 7011 | } | ||
| 7012 | |||
| 7013 | # This type of window is unique (only one can be open per session); inform the GA::Session | ||
| 7014 | # it has closed | ||
| 7015 | $self->session->set_consoleWin(); | ||
| 7016 | |||
| 7017 | return 1; | ||
| 7018 | } | ||
| 7019 | |||
| 7020 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 7021 | |||
| 7022 | # sub drawWidgets {} # Inherited from GA::OtherWin::ClientConsole | ||
| 7023 | |||
| 7024 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 7025 | |||
| 7026 | # ->signal_connects | ||
| 7027 | |||
| 7028 | # Other functions | ||
| 7029 | |||
| 7030 | # sub createColourTags {} # Inherited from GA::OtherWin::ClientConsole | ||
| 7031 | |||
| 7032 | # sub update {} # Inherited from GA::OtherWin::ClientConsole | ||
| 7033 | |||
| 7034 | ################## | ||
| 7035 | # Accessors - set | ||
| 7036 | |||
| 7037 | ################## | ||
| 7038 | # Accessors - get | ||
| 7039 | } | ||
| 7040 | |||
| 7041 | { package Games::Axmud::OtherWin::Simulate; | ||
| 7042 | |||
| 7043 | use strict; | ||
| 7044 | use warnings; | ||
| 7045 | # use diagnostics; | ||
| 7046 | |||
| 7047 | use Glib qw(TRUE FALSE); | ||
| 7048 | |||
| 7049 | our @ISA = qw( | ||
| 7050 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 7051 | Games::Axmud | ||
| 7052 | ); | ||
| 7053 | |||
| 7054 | ################## | ||
| 7055 | # Constructors | ||
| 7056 | |||
| 7057 | sub new { | ||
| 7058 | |||
| 7059 | # Called by GA::Generic::Win->createFreeWin | ||
| 7060 | # Creates a new instance of the Simulate window (an 'other' window). The window contains a | ||
| 7061 | # textview in which the user can type text. When the 'Simulate' button is clicked, the | ||
| 7062 | # contents of the textview (if any) is combined into a single string (with multiple lines | ||
| 7063 | # separated by newline characters). The string is then used in a ';simulateworld' command, | ||
| 7064 | # and appears in the session's default textview, as if it had been received from the world | ||
| 7065 | # | ||
| 7066 | # Expected arguments | ||
| 7067 | # $number - Unique number for this window object | ||
| 7068 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 7069 | # should be created | ||
| 7070 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 7071 | # 'free' window object. When this window opens/closes, the owner is | ||
| 7072 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 7073 | # functions | ||
| 7074 | # | ||
| 7075 | # Optional arguments | ||
| 7076 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 7077 | # calling function didn't specify a session and $owner's ->session IV | ||
| 7078 | # is also 'undef' | ||
| 7079 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 7080 | # $editObj - Ignored if set | ||
| 7081 | # $tempFlag - Ignored if set | ||
| 7082 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 7083 | # particular 'other' window; set to an empty hash if not required | ||
| 7084 | # - This type of window object recognises these initialisation settings: | ||
| 7085 | # | ||
| 7086 | # 'type' => Which client command to use with the contents of the | ||
| 7087 | # textview, when the 'Simulate' button is clicked - 'world' or | ||
| 7088 | # 'prompt'. If not specified, 'world' is used | ||
| 7089 | # | ||
| 7090 | # Return values | ||
| 7091 | # 'undef' on improper arguments | ||
| 7092 | # Blessed reference to the newly-created object on success | ||
| 7093 | |||
| 7094 | my ( | ||
| 7095 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 7096 | %configHash, | ||
| 7097 | ) = @_; | ||
| 7098 | |||
| 7099 | # Check for improper arguments | ||
| 7100 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 7101 | |||
| 7102 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 7103 | } | ||
| 7104 | |||
| 7105 | # Set the values to use for some standard window IVs | ||
| 7106 | if (defined $configHash{'type'} && $configHash{'type'} eq 'prompt') { | ||
| 7107 | $title = 'Simulate prompt'; | ||
| 7108 | } else { | ||
| 7109 | $title = 'Simulate world'; | ||
| 7110 | } | ||
| 7111 | |||
| 7112 | # Setup | ||
| 7113 | my $self = { | ||
| 7114 | _objName => 'other_win_' . $number, | ||
| 7115 | _objClass => $class, | ||
| 7116 | _parentFile => undef, # No parent file object | ||
| 7117 | _parentWorld => undef, # No parent file object | ||
| 7118 | _privFlag => TRUE, # All IVs are private | ||
| 7119 | |||
| 7120 | # Standard window object IVs | ||
| 7121 | # -------------------------- | ||
| 7122 | |||
| 7123 | # Unique number for this window object | ||
| 7124 | number => $number, | ||
| 7125 | # The window category - 'grid' or 'free' | ||
| 7126 | winCategory => 'free', | ||
| 7127 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 7128 | winType => 'other', | ||
| 7129 | # A name for the window (can be unique to this type of window object, or can be the | ||
| 7130 | # same as ->winType) | ||
| 7131 | winName => 'simulate', | ||
| 7132 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 7133 | workspaceObj => $workspaceObj, | ||
| 7134 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 7135 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 7136 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 7137 | owner => $owner, | ||
| 7138 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 7139 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 7140 | session => $session, | ||
| 7141 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 7142 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 7143 | # displayed in a 'dialogue' window) | ||
| 7144 | pseudoCmdMode => 'win_error', | ||
| 7145 | |||
| 7146 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 7147 | # parent 'main' window's Gtk3::Window | ||
| 7148 | # The code should use this IV when it wants to do something to the window itself | ||
| 7149 | # (minimise it, make it active, etc) | ||
| 7150 | winWidget => undef, | ||
| 7151 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 7152 | # the parent GA::Table::PseudoWin table object | ||
| 7153 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 7154 | # window itself | ||
| 7155 | winBox => undef, | ||
| 7156 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 7157 | # FALSE if not | ||
| 7158 | enabledFlag => FALSE, | ||
| 7159 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 7160 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 7161 | visibleFlag => TRUE, | ||
| 7162 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 7163 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 7164 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 7165 | childFreeWinHash => {}, | ||
| 7166 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 7167 | # window is informed via a call to $self->del_childFreeWin | ||
| 7168 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 7169 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 7170 | # this hash; a hash in the form | ||
| 7171 | # $childDestroyHash{unique_number} = list_reference | ||
| 7172 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 7173 | # reference to a list in groups of 2, in the form | ||
| 7174 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 7175 | childDestroyHash => {}, | ||
| 7176 | |||
| 7177 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 7178 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 7179 | # area) | ||
| 7180 | packingBox => undef, | ||
| 7181 | |||
| 7182 | # Standard IVs for 'free' windows | ||
| 7183 | |||
| 7184 | # The window's default size, in pixels | ||
| 7185 | widthPixels => int($axmud::CLIENT->constFreeWinWidth * 0.66), | ||
| 7186 | heightPixels => int($axmud::CLIENT->constFreeWinHeight * 0.66), | ||
| 7187 | # Default border/item spacing sizes used in the window, in pixels | ||
| 7188 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 7189 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 7190 | |||
| 7191 | # A string to use as the window title | ||
| 7192 | title => $title, | ||
| 7193 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 7194 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 7195 | # name and type. Set to an empty hash if not required | ||
| 7196 | configHash => {%configHash}, | ||
| 7197 | }; | ||
| 7198 | |||
| 7199 | # Bless the object into existence | ||
| 7200 | bless $self, $class; | ||
| 7201 | |||
| 7202 | return $self; | ||
| 7203 | } | ||
| 7204 | |||
| 7205 | ################## | ||
| 7206 | # Methods | ||
| 7207 | |||
| 7208 | # Standard window object functions | ||
| 7209 | |||
| 7210 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 7211 | |||
| 7212 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 7213 | |||
| 7214 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 7215 | |||
| 7216 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 7217 | |||
| 7218 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 7219 | |||
| 7220 | sub drawWidgets { | ||
| 7221 | |||
| 7222 | # Called by $self->winSetup | ||
| 7223 | # Sets up the Gtk3::Window by drawing the window's widgets | ||
| 7224 | # | ||
| 7225 | # Expected arguments | ||
| 7226 | # (none besides $self) | ||
| 7227 | # | ||
| 7228 | # Return values | ||
| 7229 | # 'undef' on improper arguments | ||
| 7230 | # 1 otherwise | ||
| 7231 | |||
| 7232 | my ($self, $check) = @_; | ||
| 7233 | |||
| 7234 | # Local variables | ||
| 7235 | my ( | ||
| 7236 | $width, $height, $title, $sampleText, $sampleUnderlay, | ||
| 7237 | @tagList, | ||
| 7238 | %prettyHash, %reversePrettyHash, %ansiHash, | ||
| 7239 | ); | ||
| 7240 | |||
| 7241 | # Check for improper arguments | ||
| 7242 | if (defined $check) { | ||
| 7243 | |||
| 7244 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 7245 | } | ||
| 7246 | |||
| 7247 | # Import the list of Axmud standard colour/style tags (which also includes the dummy tags | ||
| 7248 | # like 'bold', 'reverse_off' and 'attribs_off') | ||
| 7249 | @tagList = $axmud::CLIENT->constColourStyleList; | ||
| 7250 | # (For convenience, add 'attribs_off' to both the beginning and end of the list) | ||
| 7251 | unshift(@tagList, 'attribs_off'); | ||
| 7252 | # Also import the hash of pretty names for each standard tag, in which the keys are the | ||
| 7253 | # items in @tagList | ||
| 7254 | %prettyHash = $axmud::CLIENT->constPrettyTagHash; | ||
| 7255 | # Use a reverse hash too, so we can work out which combobox item was selected | ||
| 7256 | %reversePrettyHash = reverse %prettyHash; | ||
| 7257 | |||
| 7258 | # Prepare a hash of ANSI escape sequences which the user can insert at any place in the | ||
| 7259 | # textview, in the form | ||
| 7260 | # $ansiHash{tag} = number_of_ANSI_escape_sequence | ||
| 7261 | %ansiHash = ( | ||
| 7262 | (reverse $axmud::CLIENT->constANSIColourHash), | ||
| 7263 | (reverse $axmud::CLIENT->constANSIStyleHash), | ||
| 7264 | ); | ||
| 7265 | |||
| 7266 | $ansiHash{'bold'} = 1; | ||
| 7267 | $ansiHash{'bold_off'} = 22; | ||
| 7268 | $ansiHash{'reverse'} = 7; | ||
| 7269 | $ansiHash{'reverse_off'} = 27; | ||
| 7270 | $ansiHash{'conceal'} = 8; | ||
| 7271 | $ansiHash{'conceal_off'} = 28; | ||
| 7272 | $ansiHash{'attribs_off'} = 0; | ||
| 7273 | |||
| 7274 | # Create a packing box | ||
| 7275 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 7276 | $self->winBox->add($packingBox); | ||
| 7277 | $packingBox->set_border_width(0); | ||
| 7278 | |||
| 7279 | # At the top, create a textview | ||
| 7280 | my $scroller = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 7281 | $packingBox->pack_start($scroller, TRUE, TRUE, 0); | ||
| 7282 | $scroller->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 7283 | $scroller->set_policy('automatic', 'automatic'); | ||
| 7284 | $scroller->set_border_width(0); | ||
| 7285 | |||
| 7286 | # Create a textview with default colours/fonts | ||
| 7287 | my $textView = Gtk3::TextView->new(); | ||
| 7288 | $scroller->add($textView); | ||
| 7289 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 7290 | $textView->set_buffer($buffer); | ||
| 7291 | $textView->set_editable(TRUE); | ||
| 7292 | $textView->set_cursor_visible(TRUE); | ||
| 7293 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView); | ||
| 7294 | |||
| 7295 | # At the bottom, create a button strip in a horizontal packing box | ||
| 7296 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 7297 | $packingBox->pack_end($hBox, FALSE, FALSE, $self->spacingPixels); | ||
| 7298 | |||
| 7299 | # Create a combo | ||
| 7300 | my $comboBox = Gtk3::ComboBoxText->new(); | ||
| 7301 | $hBox->pack_start($comboBox, FALSE, FALSE, $self->borderPixels); | ||
| 7302 | $title = 'Add an ANSI escape sequence:'; | ||
| 7303 | $sampleText = 'Sample xterm-256 text colour'; | ||
| 7304 | $sampleUnderlay = 'Sample xterm-256 underlay colour'; | ||
| 7305 | $comboBox->append_text($title); | ||
| 7306 | foreach my $tag (@tagList) { | ||
| 7307 | |||
| 7308 | $comboBox->append_text($prettyHash{$tag}); | ||
| 7309 | |||
| 7310 | # GA::Client->constColourStyleList doesn't include xterm colour tags, so we'll insert | ||
| 7311 | # a sample text and a sample underlay colour right just before the style tags | ||
| 7312 | if ($tag eq 'ul_white') { | ||
| 7313 | |||
| 7314 | $comboBox->append_text($sampleText); | ||
| 7315 | $comboBox->append_text($sampleUnderlay); | ||
| 7316 | } | ||
| 7317 | } | ||
| 7318 | |||
| 7319 | $comboBox->set_active(0); | ||
| 7320 | |||
| 7321 | # Create the 'Apply' button | ||
| 7322 | my $addButton = Gtk3::Button->new('Apply'); | ||
| 7323 | $hBox->pack_start($addButton, FALSE, FALSE, 0); | ||
| 7324 | $addButton->get_child->set_width_chars(8); | ||
| 7325 | $addButton->signal_connect('clicked' => sub { | ||
| 7326 | |||
| 7327 | my ($prettyTag, $tag, $ansi); | ||
| 7328 | |||
| 7329 | $prettyTag = $comboBox->get_active_text(); | ||
| 7330 | if ($prettyTag) { | ||
| 7331 | |||
| 7332 | if ($prettyTag eq $sampleText) { | ||
| 7333 | |||
| 7334 | # Use an example xterm-256 text colour (dark grey) | ||
| 7335 | $ansi = chr(27) . '[38;5;234m'; | ||
| 7336 | |||
| 7337 | } elsif ($prettyTag eq $sampleUnderlay) { | ||
| 7338 | |||
| 7339 | # Use an example xterm-256 underlay colour (light orange) | ||
| 7340 | $ansi = chr(27) . '[48;5;214m'; | ||
| 7341 | |||
| 7342 | } elsif ($prettyTag ne $title) { | ||
| 7343 | |||
| 7344 | # Get an Axmud colour/style tag (or one of the dummy tags like 'bold', | ||
| 7345 | # 'reverse_off' and 'attribs_off') | ||
| 7346 | $tag = $reversePrettyHash{$prettyTag}; | ||
| 7347 | # Convert it to an ANSI escape sequence | ||
| 7348 | $ansi = chr(27) . '[' . $ansiHash{$tag} . 'm'; | ||
| 7349 | } | ||
| 7350 | |||
| 7351 | if ($ansi) { | ||
| 7352 | |||
| 7353 | $buffer->insert_at_cursor($ansi); | ||
| 7354 | } | ||
| 7355 | } | ||
| 7356 | }); | ||
| 7357 | |||
| 7358 | # Create the 'Simulate' button | ||
| 7359 | my $okButton = Gtk3::Button->new('Simulate'); | ||
| 7360 | $hBox->pack_end($okButton, FALSE, FALSE, 0); | ||
| 7361 | $okButton->get_child->set_width_chars(8); | ||
| 7362 | $okButton->signal_connect('clicked' => sub { | ||
| 7363 | |||
| 7364 | my ($text, $type); | ||
| 7365 | |||
| 7366 | $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer); | ||
| 7367 | $type = $self->ivShow('configHash', 'type'); | ||
| 7368 | |||
| 7369 | # If the textview contains some text, and if the calling GA::Session still exists... | ||
| 7370 | if ($text && $axmud::CLIENT->ivExists('sessionHash', $self->session->number)) { | ||
| 7371 | |||
| 7372 | if ($type eq 'prompt') { | ||
| 7373 | |||
| 7374 | # Simulate a prompt received from the world. The TRUE argument means that the | ||
| 7375 | # 'main' window's blinker shouldn't be turned on. | ||
| 7376 | chomp $text; | ||
| 7377 | $self->session->processIncomingData($text, TRUE); | ||
| 7378 | |||
| 7379 | } else { | ||
| 7380 | |||
| 7381 | # Simulate text received from the world. The TRUE argument means that the main | ||
| 7382 | # window's blinker shouldn't be turned on. | ||
| 7383 | $self->session->processIncomingData($text, TRUE); | ||
| 7384 | } | ||
| 7385 | } | ||
| 7386 | }); | ||
| 7387 | |||
| 7388 | # Create the 'Close' button | ||
| 7389 | my $cancelButton = Gtk3::Button->new('Close'); | ||
| 7390 | $hBox->pack_end($cancelButton, FALSE, FALSE, $self->spacingPixels); | ||
| 7391 | $cancelButton->get_child->set_width_chars(8); | ||
| 7392 | $cancelButton->signal_connect('clicked' => sub { | ||
| 7393 | |||
| 7394 | $self->winDestroy(); | ||
| 7395 | }); | ||
| 7396 | |||
| 7397 | # Update IVs (not worth storing widgets other than the main packing box) | ||
| 7398 | $self->ivPoke('packingBox', $packingBox); | ||
| 7399 | |||
| 7400 | return 1; | ||
| 7401 | } | ||
| 7402 | |||
| 7403 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 7404 | |||
| 7405 | # ->signal_connects | ||
| 7406 | |||
| 7407 | # Other functions | ||
| 7408 | |||
| 7409 | ################## | ||
| 7410 | # Accessors - set | ||
| 7411 | |||
| 7412 | ################## | ||
| 7413 | # Accessors - get | ||
| 7414 | } | ||
| 7415 | |||
| 7416 | { package Games::Axmud::OtherWin::SourceCode; | ||
| 7417 | |||
| 7418 | use strict; | ||
| 7419 | use warnings; | ||
| 7420 | # use diagnostics; | ||
| 7421 | |||
| 7422 | use Glib qw(TRUE FALSE); | ||
| 7423 | |||
| 7424 | our @ISA = qw( | ||
| 7425 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 7426 | Games::Axmud | ||
| 7427 | ); | ||
| 7428 | |||
| 7429 | ################## | ||
| 7430 | # Constructors | ||
| 7431 | |||
| 7432 | sub new { | ||
| 7433 | |||
| 7434 | # Called by GA::Generic::Win->createFreeWin | ||
| 7435 | # Creates a new instance of the Source Code Viewer (an 'other' window). The window contains | ||
| 7436 | # a textview in which the source code for a world model object can be displayed (but not | ||
| 7437 | # edited) | ||
| 7438 | # | ||
| 7439 | # Expected arguments | ||
| 7440 | # $number - Unique number for this window object | ||
| 7441 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 7442 | # should be created | ||
| 7443 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 7444 | # 'free' window object. When this window opens/closes, the owner is | ||
| 7445 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 7446 | # functions | ||
| 7447 | # | ||
| 7448 | # Optional arguments | ||
| 7449 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 7450 | # calling function didn't specify a session and $owner's ->session IV | ||
| 7451 | # is also 'undef' | ||
| 7452 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 7453 | # $editObj - Ignored if set | ||
| 7454 | # $tempFlag - Ignored if set | ||
| 7455 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 7456 | # particular 'other' window; set to an empty hash if not required | ||
| 7457 | # - This type of window object recognises these initialisation settings: | ||
| 7458 | # | ||
| 7459 | # 'model_obj' => Blessed reference to the model object whose source | ||
| 7460 | # code should be shown (GA::ModelObj::Room, etc). If not | ||
| 7461 | # specified, the window doesn't open | ||
| 7462 | # 'virtual_flag' => If TRUE, the model is a room object, and we need | ||
| 7463 | # to view the file stored in the object's ->virtualAreaPath IV. | ||
| 7464 | # If not specified, FALSE (or 'undef'), we need to view the file | ||
| 7465 | # stored in the object's ->sourceCodePath IV | ||
| 7466 | # 'path' => If defined, the filepath to use (which may be different to | ||
| 7467 | # the one stored in the object's ->virtualAreaPath). If not | ||
| 7468 | # specified, an empty string or 'undef', the object's | ||
| 7469 | # ->sourceCodePath is used. Ignored if 'virtual_flag' is TRUE | ||
| 7470 | # | ||
| 7471 | # Return values | ||
| 7472 | # 'undef' on improper arguments | ||
| 7473 | # Blessed reference to the newly-created object on success | ||
| 7474 | |||
| 7475 | my ( | ||
| 7476 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 7477 | %configHash, | ||
| 7478 | ) = @_; | ||
| 7479 | |||
| 7480 | # Check for improper arguments | ||
| 7481 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 7482 | |||
| 7483 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 7484 | } | ||
| 7485 | |||
| 7486 | # Setup | ||
| 7487 | my $self = { | ||
| 7488 | _objName => 'other_win_' . $number, | ||
| 7489 | _objClass => $class, | ||
| 7490 | _parentFile => undef, # No parent file object | ||
| 7491 | _parentWorld => undef, # No parent file object | ||
| 7492 | _privFlag => TRUE, # All IVs are private | ||
| 7493 | |||
| 7494 | # Standard window object IVs | ||
| 7495 | # -------------------------- | ||
| 7496 | |||
| 7497 | # Unique number for this window object | ||
| 7498 | number => $number, | ||
| 7499 | # The window category - 'grid' or 'free' | ||
| 7500 | winCategory => 'free', | ||
| 7501 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 7502 | winType => 'other', | ||
| 7503 | # A name for the window (can be unique to this type of window object, or can be the | ||
| 7504 | # same as ->winType) | ||
| 7505 | winName => 'source_code', | ||
| 7506 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 7507 | workspaceObj => $workspaceObj, | ||
| 7508 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 7509 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 7510 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 7511 | owner => $owner, | ||
| 7512 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 7513 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 7514 | session => $session, | ||
| 7515 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 7516 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 7517 | # displayed in a 'dialogue' window) | ||
| 7518 | pseudoCmdMode => 'win_error', | ||
| 7519 | |||
| 7520 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 7521 | # parent 'main' window's Gtk3::Window | ||
| 7522 | # The code should use this IV when it wants to do something to the window itself | ||
| 7523 | # (minimise it, make it active, etc) | ||
| 7524 | winWidget => undef, | ||
| 7525 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 7526 | # the parent GA::Table::PseudoWin table object | ||
| 7527 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 7528 | # window itself | ||
| 7529 | winBox => undef, | ||
| 7530 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 7531 | # FALSE if not | ||
| 7532 | enabledFlag => FALSE, | ||
| 7533 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 7534 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 7535 | visibleFlag => TRUE, | ||
| 7536 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 7537 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 7538 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 7539 | childFreeWinHash => {}, | ||
| 7540 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 7541 | # window is informed via a call to $self->del_childFreeWin | ||
| 7542 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 7543 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 7544 | # this hash; a hash in the form | ||
| 7545 | # $childDestroyHash{unique_number} = list_reference | ||
| 7546 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 7547 | # reference to a list in groups of 2, in the form | ||
| 7548 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 7549 | childDestroyHash => {}, | ||
| 7550 | |||
| 7551 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 7552 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 7553 | # area) | ||
| 7554 | packingBox => undef, | ||
| 7555 | |||
| 7556 | # Standard IVs for 'free' windows | ||
| 7557 | |||
| 7558 | # The window's default size, in pixels | ||
| 7559 | widthPixels => $axmud::CLIENT->customFreeWinWidth, | ||
| 7560 | heightPixels => $axmud::CLIENT->customFreeWinHeight, | ||
| 7561 | # Default border/item spacing sizes used in the window, in pixels | ||
| 7562 | borderPixels => $axmud::CLIENT->constFreeBorderPixels, | ||
| 7563 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 7564 | |||
| 7565 | # A string to use as the window title | ||
| 7566 | title => 'Source code viewer', | ||
| 7567 | # Hash containing any number of key-value pairs needed for this particular 'config' | ||
| 7568 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 7569 | # name and type. Set to an empty hash if not required | ||
| 7570 | configHash => {%configHash}, | ||
| 7571 | |||
| 7572 | # IVs for this window | ||
| 7573 | |||
| 7574 | # Full path to the file loaded | ||
| 7575 | file => undef, | ||
| 7576 | # The model object whose corresponding source code should be displayed | ||
| 7577 | modelObj => undef, | ||
| 7578 | # The contents of the source code file, once read by $self->readFile | ||
| 7579 | lineList => [], | ||
| 7580 | }; | ||
| 7581 | |||
| 7582 | # Bless the object into existence | ||
| 7583 | bless $self, $class; | ||
| 7584 | |||
| 7585 | return $self; | ||
| 7586 | } | ||
| 7587 | |||
| 7588 | ################## | ||
| 7589 | # Methods | ||
| 7590 | |||
| 7591 | # Standard window object functions | ||
| 7592 | |||
| 7593 | sub winSetup { | ||
| 7594 | |||
| 7595 | # Called by GA::Generic::Win->createFreeWin, after the call to $self->new | ||
| 7596 | # Creates the Gtk3::Window itself | ||
| 7597 | # | ||
| 7598 | # Expected arguments | ||
| 7599 | # (none besides $self) | ||
| 7600 | # | ||
| 7601 | # Return values | ||
| 7602 | # 'undef' on improper arguments or if the window can't be opened | ||
| 7603 | # 1 on success | ||
| 7604 | |||
| 7605 | my ($self, $check) = @_; | ||
| 7606 | |||
| 7607 | # Local variables | ||
| 7608 | my $iv; | ||
| 7609 | |||
| 7610 | # Check for improper arguments | ||
| 7611 | if (defined $check) { | ||
| 7612 | |||
| 7613 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_); | ||
| 7614 | } | ||
| 7615 | |||
| 7616 | # Before doing anything, try to read the file (and don't open this window if it can't be | ||
| 7617 | # done) | ||
| 7618 | if (! $self->readFile()) { | ||
| 7619 | |||
| 7620 | return undef; | ||
| 7621 | } | ||
| 7622 | |||
| 7623 | # Create the Gtk3::Window | ||
| 7624 | my $winWidget = Gtk3::Window->new('toplevel'); | ||
| 7625 | if (! $winWidget) { | ||
| 7626 | |||
| 7627 | return undef; | ||
| 7628 | |||
| 7629 | } else { | ||
| 7630 | |||
| 7631 | # Store the IV now, as subsequent code needs it | ||
| 7632 | $self->ivPoke('winWidget', $winWidget); | ||
| 7633 | $self->ivPoke('winBox', $winWidget); | ||
| 7634 | } | ||
| 7635 | |||
| 7636 | # Set up ->signal_connects | ||
| 7637 | $self->setDeleteEvent(); # 'delete-event' | ||
| 7638 | |||
| 7639 | # Set the window title | ||
| 7640 | $winWidget->set_title($self->title); | ||
| 7641 | |||
| 7642 | # Set the window's default size and position | ||
| 7643 | $winWidget->set_default_size($self->widthPixels, $self->heightPixels); | ||
| 7644 | $winWidget->set_border_width($self->borderPixels); | ||
| 7645 | $winWidget->set_position('center'); | ||
| 7646 | |||
| 7647 | # Set the icon list for this window | ||
| 7648 | $iv = $self->winType . 'WinIconList'; | ||
| 7649 | $winWidget->set_icon_list($axmud::CLIENT->desktopObj->{$iv}); | ||
| 7650 | |||
| 7651 | # Draw the widgets used by this window | ||
| 7652 | if (! $self->drawWidgets()) { | ||
| 7653 | |||
| 7654 | return undef; | ||
| 7655 | } | ||
| 7656 | |||
| 7657 | # The calling function can now call $self->winEnable to make the window visible | ||
| 7658 | return 1; | ||
| 7659 | } | ||
| 7660 | |||
| 7661 | # sub winEnable {} # Inherited from GA::Generic::FreeWin | ||
| 7662 | |||
| 7663 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 7664 | |||
| 7665 | # sub winDestroy {} # Inherited from GA::Generic::FreeWin | ||
| 7666 | |||
| 7667 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 7668 | |||
| 7669 | sub drawWidgets { | ||
| 7670 | |||
| 7671 | # Called by $self->winSetup | ||
| 7672 | # Sets up the Gtk3::Window by drawing the window's widgets | ||
| 7673 | # | ||
| 7674 | # Expected arguments | ||
| 7675 | # (none besides $self) | ||
| 7676 | # | ||
| 7677 | # Return values | ||
| 7678 | # 'undef' on improper arguments | ||
| 7679 | # 1 otherwise | ||
| 7680 | |||
| 7681 | my ($self, $check) = @_; | ||
| 7682 | |||
| 7683 | # Check for improper arguments | ||
| 7684 | if (defined $check) { | ||
| 7685 | |||
| 7686 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 7687 | } | ||
| 7688 | |||
| 7689 | # Create a packing box | ||
| 7690 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 7691 | $self->winBox->add($packingBox); | ||
| 7692 | $packingBox->set_border_width(0); | ||
| 7693 | |||
| 7694 | # At the top, create a textview | ||
| 7695 | my $frame = Gtk3::Frame->new($self->title); | ||
| 7696 | $packingBox->pack_start($frame, TRUE, TRUE, 0); | ||
| 7697 | # Update the frame label | ||
| 7698 | $frame->set_label( | ||
| 7699 | 'World model room #' . $self->modelObj->number . ' (' . $self->file . ')', | ||
| 7700 | ); | ||
| 7701 | $frame->set_border_width(0); | ||
| 7702 | |||
| 7703 | my $scroller = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 7704 | $frame->add($scroller); | ||
| 7705 | $scroller->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 7706 | $scroller->set_policy('automatic', 'automatic'); | ||
| 7707 | $scroller->set_border_width(5); | ||
| 7708 | |||
| 7709 | # Create a textview with default colours/fonts | ||
| 7710 | my $textView = Gtk3::TextView->new(); | ||
| 7711 | $scroller->add($textView); | ||
| 7712 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 7713 | $textView->set_buffer($buffer); | ||
| 7714 | $textView->set_editable(FALSE); | ||
| 7715 | $textView->set_cursor_visible(FALSE); | ||
| 7716 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView); | ||
| 7717 | |||
| 7718 | # Copy the contents of the file to the textview | ||
| 7719 | $buffer->set_text(join("\n", $self->lineList)); | ||
| 7720 | |||
| 7721 | # At the bottom, create a button strip in a horizontal packing box | ||
| 7722 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 7723 | $packingBox->pack_end($hBox, FALSE, FALSE, $self->spacingPixels); | ||
| 7724 | |||
| 7725 | # Add a single button | ||
| 7726 | my $button = Gtk3::Button->new(' Close '); | ||
| 7727 | $hBox->pack_end($button, FALSE, FALSE, $self->borderPixels); | ||
| 7728 | $button->get_child->set_width_chars(10); | ||
| 7729 | $button->signal_connect('clicked' => sub { | ||
| 7730 | |||
| 7731 | $self->winDestroy(); | ||
| 7732 | }); | ||
| 7733 | |||
| 7734 | # Update IVs (not worth storing widgets other than the main packing box) | ||
| 7735 | $self->ivPoke('packingBox', $packingBox); | ||
| 7736 | |||
| 7737 | return 1; | ||
| 7738 | } | ||
| 7739 | |||
| 7740 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 7741 | |||
| 7742 | # ->signal_connects | ||
| 7743 | |||
| 7744 | # Other functions | ||
| 7745 | |||
| 7746 | sub readFile { | ||
| 7747 | |||
| 7748 | # Called by $self->winSetup before creating the Gtk3::Window | ||
| 7749 | # Performs a few checks, displaying a 'dialogue' window if the source code viewer window | ||
| 7750 | # can't be opened for one reason or another | ||
| 7751 | # | ||
| 7752 | # Expected arguments | ||
| 7753 | # (none besides $self) | ||
| 7754 | # | ||
| 7755 | # Return values | ||
| 7756 | # 'undef' on improper arguments or if the window should not be opened | ||
| 7757 | # 1 otherwise | ||
| 7758 | |||
| 7759 | my ($self, $check) = @_; | ||
| 7760 | |||
| 7761 | # Local variables | ||
| 7762 | my ( | ||
| 7763 | $worldModelObj, $obj, $virtualFlag, $sourcePath, $errorMsg, $file, $fileName, | ||
| 7764 | $fileHandle, | ||
| 7765 | @lineList, | ||
| 7766 | ); | ||
| 7767 | |||
| 7768 | # Check for improper arguments | ||
| 7769 | if (defined $check) { | ||
| 7770 | |||
| 7771 | return $axmud::CLIENT->writeImproper($self->_objClass . '->readFile', @_); | ||
| 7772 | } | ||
| 7773 | |||
| 7774 | # Import the world model (for convenience) | ||
| 7775 | $worldModelObj = $self->session->worldModelObj; | ||
| 7776 | # Import some values from $self->configHash (for convenience) | ||
| 7777 | $obj = $self->ivShow('configHash', 'model_obj'); | ||
| 7778 | $virtualFlag = $self->ivShow('configHash', 'virtual_flag'); | ||
| 7779 | $sourcePath = $self->ivShow('configHash', 'path'); | ||
| 7780 | |||
| 7781 | # Check that the model object knows the source code of the equivalent mudlib object | ||
| 7782 | if (! $obj->sourceCodePath && ! $sourcePath) { | ||
| 7783 | |||
| 7784 | $errorMsg = 'World model object #' . $obj->number . ' has no source code file set'; | ||
| 7785 | |||
| 7786 | } elsif ($virtualFlag) { | ||
| 7787 | |||
| 7788 | if ($obj->category ne 'room') { | ||
| 7789 | |||
| 7790 | $errorMsg = 'World model object #' . $obj->number . ' is not a room'; | ||
| 7791 | |||
| 7792 | } elsif (! $obj->virtualAreaPath) { | ||
| 7793 | |||
| 7794 | $errorMsg = 'World model object #' . $obj->number . ' has no virtual area file set'; | ||
| 7795 | } | ||
| 7796 | } | ||
| 7797 | |||
| 7798 | if ($errorMsg) { | ||
| 7799 | |||
| 7800 | $self->showMsgDialogue( | ||
| 7801 | 'View source code', | ||
| 7802 | 'error', | ||
| 7803 | $errorMsg, | ||
| 7804 | 'ok', | ||
| 7805 | ); | ||
| 7806 | |||
| 7807 | return undef; | ||
| 7808 | } | ||
| 7809 | |||
| 7810 | # Set the file to be displayed. If the current world model defines a mudlib directory, | ||
| 7811 | # the object's ->mudlibPath is relative to that; otherwise it's an absolute path | ||
| 7812 | if ($worldModelObj->mudlibPath) { | ||
| 7813 | $file = $worldModelObj->mudlibPath; | ||
| 7814 | } else { | ||
| 7815 | $file = ''; | ||
| 7816 | } | ||
| 7817 | |||
| 7818 | if ($sourcePath && ! $virtualFlag) { | ||
| 7819 | |||
| 7820 | # Use a different file than the one stored in the room object | ||
| 7821 | $fileName = $sourcePath; | ||
| 7822 | |||
| 7823 | } elsif ($virtualFlag && $obj->category eq 'room') { | ||
| 7824 | |||
| 7825 | # This is a room in a virtual area | ||
| 7826 | $fileName = $obj->virtualAreaPath; | ||
| 7827 | |||
| 7828 | } else { | ||
| 7829 | |||
| 7830 | # Any other kind of model object | ||
| 7831 | $fileName = $obj->sourceCodePath; | ||
| 7832 | } | ||
| 7833 | |||
| 7834 | $file .= $fileName; | ||
| 7835 | |||
| 7836 | # Add the file extension, if set | ||
| 7837 | if ($worldModelObj->mudlibExtension) { | ||
| 7838 | |||
| 7839 | $file .= $worldModelObj->mudlibExtension; | ||
| 7840 | } | ||
| 7841 | |||
| 7842 | # Check the file exists | ||
| 7843 | if (! (-e $file)) { | ||
| 7844 | |||
| 7845 | $self->showMsgDialogue( | ||
| 7846 | 'View source code', | ||
| 7847 | 'error', | ||
| 7848 | 'Can\'t find the file \'' . $file . '\'', | ||
| 7849 | 'ok', | ||
| 7850 | ); | ||
| 7851 | |||
| 7852 | return undef; | ||
| 7853 | } | ||
| 7854 | |||
| 7855 | # Open the file for reading | ||
| 7856 | if (! open ($fileHandle, "<$file")) { | ||
| 7857 | |||
| 7858 | $self->showMessageDialogue( | ||
| 7859 | 'View source code', | ||
| 7860 | 'error', | ||
| 7861 | 'Couldn\'t open the file ' . $file, | ||
| 7862 | 'ok', | ||
| 7863 | ); | ||
| 7864 | |||
| 7865 | return undef; | ||
| 7866 | } | ||
| 7867 | |||
| 7868 | # Read the file | ||
| 7869 | while (defined (my $line = <$fileHandle>)) { | ||
| 7870 | |||
| 7871 | chomp $line; | ||
| 7872 | push (@lineList, $line); | ||
| 7873 | } | ||
| 7874 | |||
| 7875 | # Close the file | ||
| 7876 | if (! close $fileHandle) { | ||
| 7877 | |||
| 7878 | $self->showMsgDialogue( | ||
| 7879 | 'View source code', | ||
| 7880 | 'error', | ||
| 7881 | 'Couldn\'t read the file ' . $file, | ||
| 7882 | 'ok', | ||
| 7883 | ); | ||
| 7884 | |||
| 7885 | return undef; | ||
| 7886 | } | ||
| 7887 | |||
| 7888 | # File read successfully. Update IVs | ||
| 7889 | $self->ivPoke('file', $file); | ||
| 7890 | $self->ivPoke('modelObj', $obj); | ||
| 7891 | $self->ivPoke('lineList', @lineList); | ||
| 7892 | |||
| 7893 | return 1; | ||
| 7894 | } | ||
| 7895 | |||
| 7896 | ################## | ||
| 7897 | # Accessors - set | ||
| 7898 | |||
| 7899 | ################## | ||
| 7900 | # Accessors - get | ||
| 7901 | |||
| 7902 | sub file | ||
| 7903 | { $_[0]->{file} } | ||
| 7904 | sub modelObj | ||
| 7905 | { $_[0]->{modelObj} } | ||
| 7906 | sub lineList | ||
| 7907 | { my $self = shift; return @{$self->{lineList}}; } | ||
| 7908 | } | ||
| 7909 | |||
| 7910 | { package Games::Axmud::OtherWin::Viewer; | ||
| 7911 | |||
| 7912 | use strict; | ||
| 7913 | use warnings; | ||
| 7914 | # use diagnostics; | ||
| 7915 | |||
| 7916 | use Glib qw(TRUE FALSE); | ||
| 7917 | |||
| 7918 | our @ISA = qw( | ||
| 7919 | Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win | ||
| 7920 | Games::Axmud | ||
| 7921 | ); | ||
| 7922 | |||
| 7923 | ################## | ||
| 7924 | # Constructors | ||
| 7925 | |||
| 7926 | sub new { | ||
| 7927 | |||
| 7928 | # Called by GA::Generic::Win->createFreeWin | ||
| 7929 | # Creates a new instance of the data viewer window, which provides easy access to Axmud's | ||
| 7930 | # stored data | ||
| 7931 | # | ||
| 7932 | # Expected arguments | ||
| 7933 | # $number - Unique number for this window object | ||
| 7934 | # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window | ||
| 7935 | # should be created | ||
| 7936 | # $owner - The owner; a 'grid' window object (but not an 'external' window) or a | ||
| 7937 | # 'free' window object. When this window opens/closes, the owner is | ||
| 7938 | # informed via calls to its ->add_childFreeWin / ->del_childFreeWin | ||
| 7939 | # functions | ||
| 7940 | # | ||
| 7941 | # Optional arguments | ||
| 7942 | # $session - The GA::Session from which this function was called. 'undef' if the | ||
| 7943 | # calling function didn't specify a session and $owner's ->session IV | ||
| 7944 | # is also 'undef' | ||
| 7945 | # $title - Ignored if set (all 'other' windows define their own title) | ||
| 7946 | # $editObj - Ignored if set | ||
| 7947 | # $tempFlag - Ignored if set | ||
| 7948 | # %configHash - Hash containing any number of key-value pairs needed for this | ||
| 7949 | # particular 'other' window; set to an empty hash if not required | ||
| 7950 | # - This type of window object recognises these initialisation settings: | ||
| 7951 | # | ||
| 7952 | # ... | ||
| 7953 | # | ||
| 7954 | # Return values | ||
| 7955 | # 'undef' on improper arguments or if no $session was specified | ||
| 7956 | # Blessed reference to the newly-created object on success | ||
| 7957 | |||
| 7958 | my ( | ||
| 7959 | $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag, | ||
| 7960 | %configHash, | ||
| 7961 | ) = @_; | ||
| 7962 | |||
| 7963 | # Check for improper arguments | ||
| 7964 | if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) { | ||
| 7965 | |||
| 7966 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 7967 | } | ||
| 7968 | |||
| 7969 | # Data viewer windows are unique to their session. If no $session is specified, refuse to | ||
| 7970 | # create a window object | ||
| 7971 | if (! $session) { | ||
| 7972 | |||
| 7973 | return undef; | ||
| 7974 | } | ||
| 7975 | |||
| 7976 | # Setup | ||
| 7977 | my $self = { | ||
| 7978 | _objName => 'other_win_' . $number, | ||
| 7979 | _objClass => $class, | ||
| 7980 | _parentFile => undef, # No parent file object | ||
| 7981 | _parentWorld => undef, # No parent file object | ||
| 7982 | _privFlag => TRUE, # All IVs are private | ||
| 7983 | |||
| 7984 | # Standard window object IVs | ||
| 7985 | # -------------------------- | ||
| 7986 | |||
| 7987 | # Unique number for this window object | ||
| 7988 | number => $number, | ||
| 7989 | # The window category - 'grid' or 'free' | ||
| 7990 | winCategory => 'free', | ||
| 7991 | # The window type, any of the keys in GA::Client->constFreeWinTypeHash | ||
| 7992 | winType => 'viewer', | ||
| 7993 | # A name for the window (for some 'free' windows, the same as the window type) | ||
| 7994 | winName => 'viewer', | ||
| 7995 | # The GA::Obj::Workspace object for the workspace in which this window is created | ||
| 7996 | workspaceObj => $workspaceObj, | ||
| 7997 | # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window | ||
| 7998 | # object. When this window opens/closes, the owner is informed via calls to its | ||
| 7999 | # ->add_childFreeWin / ->del_childFreeWin functions | ||
| 8000 | owner => $owner, | ||
| 8001 | # The GA::Session from which this function was called. 'undef' if the calling function | ||
| 8002 | # didn't specify a session and $owner's ->session IV is also 'undef' | ||
| 8003 | session => $session, | ||
| 8004 | # When GA::Session->pseudoCmd is called to execute a client command, the mode in which | ||
| 8005 | # it should be called (usually 'win_error' or 'win_only', which causes errors to be | ||
| 8006 | # displayed in a 'dialogue' window) | ||
| 8007 | pseudoCmdMode => 'win_error', | ||
| 8008 | |||
| 8009 | # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the | ||
| 8010 | # parent 'main' window's Gtk3::Window | ||
| 8011 | # The code should use this IV when it wants to do something to the window itself | ||
| 8012 | # (minimise it, make it active, etc) | ||
| 8013 | winWidget => undef, | ||
| 8014 | # The window container. For most window objects, the Gtk3::Window. For pseudo-windows, | ||
| 8015 | # the parent GA::Table::PseudoWin table object | ||
| 8016 | # The code should use this IV when it wants to add, modify or remove widgets inside the | ||
| 8017 | # window itself | ||
| 8018 | winBox => undef, | ||
| 8019 | # Flag set to TRUE if the window actually exists (after a call to $self->winEnable), | ||
| 8020 | # FALSE if not | ||
| 8021 | enabledFlag => FALSE, | ||
| 8022 | # Flag set to TRUE if the Gtk3 window itself is visible (after a call to | ||
| 8023 | # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible) | ||
| 8024 | visibleFlag => TRUE, | ||
| 8025 | # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window | ||
| 8026 | # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form | ||
| 8027 | # $childFreeWinHash{unique_number} = blessed_reference_to_window_object | ||
| 8028 | childFreeWinHash => {}, | ||
| 8029 | # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent | ||
| 8030 | # window is informed via a call to $self->del_childFreeWin | ||
| 8031 | # When the child is destroyed, this window might want to call some of its own functions | ||
| 8032 | # to update various widgets and/or IVs, in which case this window adds an entry to | ||
| 8033 | # this hash; a hash in the form | ||
| 8034 | # $childDestroyHash{unique_number} = list_reference | ||
| 8035 | # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a | ||
| 8036 | # reference to a list in groups of 2, in the form | ||
| 8037 | # (sub_name, argument_list_ref, sub_name, argument_list_ref...) | ||
| 8038 | childDestroyHash => {}, | ||
| 8039 | |||
| 8040 | # The container widget into which all other widgets are packed (usually a Gtk3::VBox or | ||
| 8041 | # Gtk3::HBox, but any container widget can be used; takes up the whole window client | ||
| 8042 | # area) | ||
| 8043 | packingBox => undef, | ||
| 8044 | |||
| 8045 | # Standard IVs for 'free' windows | ||
| 8046 | |||
| 8047 | # The window's default size, in pixels | ||
| 8048 | widthPixels => $axmud::CLIENT->customFreeWinWidth, | ||
| 8049 | heightPixels => $axmud::CLIENT->customFreeWinHeight, | ||
| 8050 | # Default border/item spacing sizes used in the window, in pixels | ||
| 8051 | # (A border width of 1 pixel or more would leave the background photo exposed) | ||
| 8052 | borderPixels => 0, | ||
| 8053 | spacingPixels => $axmud::CLIENT->constFreeSpacingPixels, | ||
| 8054 | |||
| 8055 | # A string to use as the window title. If 'undef', a generic title is used | ||
| 8056 | title => $axmud::SCRIPT . ' data viewer', | ||
| 8057 | # Hash containing any number of key-value pairs needed for this particular 'free' | ||
| 8058 | # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task | ||
| 8059 | # name and type. Set to an empty hash if not required | ||
| 8060 | configHash => {%configHash}, | ||
| 8061 | |||
| 8062 | # IVs for this type of window | ||
| 8063 | |||
| 8064 | # Widgets | ||
| 8065 | |||
| 8066 | # A horizontal pane, dividing the treeview on the left from everything else on the right | ||
| 8067 | hPaned => undef, # Gtk3::HPaned | ||
| 8068 | # The treeview components | ||
| 8069 | treeViewModel => undef, # Gtk3::TreeStore | ||
| 8070 | treeView => undef, # Gtk3::TreeView | ||
| 8071 | treeViewScroller => undef, # Gtk3::ScrolledWindow | ||
| 8072 | # Another horizontal pane, dividing the strip of buttons on the right from everything | ||
| 8073 | # in the middle | ||
| 8074 | hPaned2 => undef, # Gtk3::HPaned | ||
| 8075 | # The notebook | ||
| 8076 | notebook => undef, # Gtk3::Notebook | ||
| 8077 | # A second vertical packing box containing the strip of buttons | ||
| 8078 | vBox => undef, # Gtk3::VBox | ||
| 8079 | # The buttons themselves (children of $self->vBox2) - also contains any separators used | ||
| 8080 | # in the button strip | ||
| 8081 | buttonList => [], | ||
| 8082 | |||
| 8083 | # The data viewer window is divided into three areas - a treeview on the left, something | ||
| 8084 | # in the middle, and a strip of buttons on the right (which are sometimes invisible) | ||
| 8085 | # The widths of these areas (in pixels). When the strip of buttons is hidden, the middle | ||
| 8086 | # area swallows up the right area, and the right area is hidden | ||
| 8087 | leftWidth => int ($axmud::CLIENT->constFreeWinWidth * 0.3), | ||
| 8088 | centreWidth => int ($axmud::CLIENT->constFreeWinWidth * 0.5), | ||
| 8089 | rightWidth => int ($axmud::CLIENT->constFreeWinWidth * 0.2), | ||
| 8090 | |||
| 8091 | # Which layout the notebook is using: | ||
| 8092 | # 'empty' - contains nothing | ||
| 8093 | # 'list' - a GA::Obj::SimpleList on the left, and buttons on the right | ||
| 8094 | # 'text' - a Gtk3::TextView | ||
| 8095 | notebookMode => 'empty', | ||
| 8096 | # Which kind of notebook is currently being displayed - namely, which header in the | ||
| 8097 | # treeview was the last one clicked (matches a key in $self->headerHash) | ||
| 8098 | notebookCurrentHeader => undef, | ||
| 8099 | # When the user double-clicks an item in the notebook's list, the reference of the | ||
| 8100 | # function which should be called in response (usually to make double-clicking the | ||
| 8101 | # equivalent of clicking on one of the buttons) | ||
| 8102 | # Set to 'undef' if nothing should happen | ||
| 8103 | notebookSelectRef => undef, | ||
| 8104 | |||
| 8105 | # Hash of treeview headers, in the form | ||
| 8106 | # $headerHash{header_string} = ref_of_subroutine | ||
| 8107 | headerHash => {}, | ||
| 8108 | |||
| 8109 | # List of notebok 'tab_name's in the same order used in the window | ||
| 8110 | # (match the keys of ->notebookTabHash) | ||
| 8111 | notebookTabList => [], | ||
| 8112 | # Hash of notebook tabs, in the form | ||
| 8113 | # $notebookTagHash{tab_name} = reference_to_Gtk3::Label_of_tab | ||
| 8114 | notebookTabHash => {}, | ||
| 8115 | # Hash of data lists displayed in the notebook, in the form | ||
| 8116 | # $notebookDataHash{tab_name} = reference_to_GA::Obj::SimpleList | ||
| 8117 | notebookDataHash => {}, | ||
| 8118 | |||
| 8119 | # To access Axbasic's default data, $self->setupTreeView creates a dummy | ||
| 8120 | # Language::Axbasic::Script object, which is stored here so that functions like | ||
| 8121 | # $self->axbasicHeader can use it | ||
| 8122 | dummyScriptObj => undef, | ||
| 8123 | }; | ||
| 8124 | |||
| 8125 | # Bless the object into existence | ||
| 8126 | bless $self, $class; | ||
| 8127 | |||
| 8128 | return $self; | ||
| 8129 | } | ||
| 8130 | |||
| 8131 | ################## | ||
| 8132 | # Methods | ||
| 8133 | |||
| 8134 | # Standard window object functions | ||
| 8135 | |||
| 8136 | # sub winSetup {} # Inherited from GA::Generic::FreeWin | ||
| 8137 | |||
| 8138 | sub winEnable { | ||
| 8139 | |||
| 8140 | # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup | ||
| 8141 | # After the Gtk3::Window has been setup and moved into position, makes it visible | ||
| 8142 | # | ||
| 8143 | # Expected arguments | ||
| 8144 | # (none besides $self) | ||
| 8145 | # | ||
| 8146 | # Return values | ||
| 8147 | # 'undef' on improper arguments | ||
| 8148 | # 1 on success | ||
| 8149 | |||
| 8150 | my ($self, $check) = @_; | ||
| 8151 | |||
| 8152 | # Check for improper arguments | ||
| 8153 | if (defined $check) { | ||
| 8154 | |||
| 8155 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_); | ||
| 8156 | } | ||
| 8157 | |||
| 8158 | # Make the window appear on the desktop | ||
| 8159 | $self->winShowAll($self->_objClass . '->winEnable'); | ||
| 8160 | $self->ivPoke('enabledFlag', TRUE); | ||
| 8161 | |||
| 8162 | # This type of window is unique to its GA::Session (only one can be open at any time, per | ||
| 8163 | # session); inform the session it has opened | ||
| 8164 | $self->session->set_viewerWin($self); | ||
| 8165 | |||
| 8166 | return 1; | ||
| 8167 | } | ||
| 8168 | |||
| 8169 | # sub winDesengage {} # Inherited from GA::Generic::FreeWin | ||
| 8170 | |||
| 8171 | sub winDestroy { | ||
| 8172 | |||
| 8173 | # Can be called by anything | ||
| 8174 | # Updates IVs | ||
| 8175 | # | ||
| 8176 | # Expected arguments | ||
| 8177 | # (none besides $self) | ||
| 8178 | # | ||
| 8179 | # Return values | ||
| 8180 | # 'undef' on improper arguments, if the window can't be destroyed or if it has already | ||
| 8181 | # been destroyed | ||
| 8182 | # 1 on success | ||
| 8183 | |||
| 8184 | my ($self, $check) = @_; | ||
| 8185 | |||
| 8186 | # Check for improper arguments | ||
| 8187 | if (defined $check) { | ||
| 8188 | |||
| 8189 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_); | ||
| 8190 | } | ||
| 8191 | |||
| 8192 | if (! $self->winBox) { | ||
| 8193 | |||
| 8194 | # Window already destroyed in a previous call to this function | ||
| 8195 | return undef; | ||
| 8196 | } | ||
| 8197 | |||
| 8198 | # Close any 'free' windows for which this window is a parent | ||
| 8199 | foreach my $winObj ($self->ivValues('childFreeWinHash')) { | ||
| 8200 | |||
| 8201 | $winObj->winDestroy(); | ||
| 8202 | } | ||
| 8203 | |||
| 8204 | # Destroy the Gtk3::Window | ||
| 8205 | eval { $self->winBox->destroy(); }; | ||
| 8206 | if ($@) { | ||
| 8207 | |||
| 8208 | # Window can't be destroyed | ||
| 8209 | return undef; | ||
| 8210 | |||
| 8211 | } else { | ||
| 8212 | |||
| 8213 | $self->ivUndef('winWidget'); | ||
| 8214 | $self->ivUndef('winBox'); | ||
| 8215 | } | ||
| 8216 | |||
| 8217 | # Inform the owner and the desktop object of this 'free' window's demise | ||
| 8218 | $axmud::CLIENT->desktopObj->del_freeWin($self); | ||
| 8219 | if ($self->owner) { | ||
| 8220 | |||
| 8221 | $self->owner->del_childFreeWin($self); | ||
| 8222 | } | ||
| 8223 | |||
| 8224 | # This type of window is unique to its GA::Session (only one can be open at any time, per | ||
| 8225 | # session); inform the session it has closed | ||
| 8226 | $self->session->set_viewerWin(); | ||
| 8227 | |||
| 8228 | return 1; | ||
| 8229 | } | ||
| 8230 | |||
| 8231 | # sub winShowAll {} # Inherited from GA::Generic::Win | ||
| 8232 | |||
| 8233 | sub drawWidgets { | ||
| 8234 | |||
| 8235 | # Called by $self->winSetup | ||
| 8236 | # Sets up the data viewer window with its standard widgets | ||
| 8237 | # | ||
| 8238 | # Expected arguments | ||
| 8239 | # (none besides $self) | ||
| 8240 | # | ||
| 8241 | # Return values | ||
| 8242 | # 'undef' on improper arguments | ||
| 8243 | # 1 otherwise | ||
| 8244 | |||
| 8245 | my ($self, $check) = @_; | ||
| 8246 | |||
| 8247 | # Check for improper arguments | ||
| 8248 | if (defined $check) { | ||
| 8249 | |||
| 8250 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_); | ||
| 8251 | } | ||
| 8252 | |||
| 8253 | # Create a packing box | ||
| 8254 | my $packingBox = Gtk3::VBox->new(FALSE, 0); | ||
| 8255 | $self->winBox->add($packingBox); | ||
| 8256 | $packingBox->set_border_width(0); | ||
| 8257 | |||
| 8258 | # Create a horizontal pane to divide the window into two, with the treeview on the left, and | ||
| 8259 | # everything else on the right | ||
| 8260 | my $hPaned = Gtk3::HPaned->new(); | ||
| 8261 | $packingBox->pack_start($hPaned, TRUE, TRUE, 0); | ||
| 8262 | |||
| 8263 | # Add a treeview on the left of the window | ||
| 8264 | my $treeViewModel = Gtk3::TreeStore->new( ['Glib::String'] ); | ||
| 8265 | my $treeView = Gtk3::TreeView->new($treeViewModel); | ||
| 8266 | $treeView->set_enable_search(FALSE); | ||
| 8267 | # Append a single column to the treeview | ||
| 8268 | $treeView->append_column( | ||
| 8269 | Gtk3::TreeViewColumn->new_with_attributes( | ||
| 8270 | 'Objects', | ||
| 8271 | Gtk3::CellRendererText->new, | ||
| 8272 | text => 0, | ||
| 8273 | ) | ||
| 8274 | ); | ||
| 8275 | |||
| 8276 | # Make the treeview scrollable | ||
| 8277 | my $treeViewScroller = Gtk3::ScrolledWindow->new(); | ||
| 8278 | $hPaned->pack1($treeViewScroller, FALSE, FALSE); | ||
| 8279 | $treeViewScroller->add($treeView); | ||
| 8280 | $treeViewScroller->set_policy(qw/automatic automatic/); | ||
| 8281 | |||
| 8282 | # Make the branches of the list tree clickable, so the rows can be expanded and collapsed | ||
| 8283 | $treeView->signal_connect('row_activated' => \&treeViewRowActivated, $self); | ||
| 8284 | # Respond to clicks on the treeview | ||
| 8285 | $treeView->get_selection->set_mode('browse'); | ||
| 8286 | $treeView->get_selection->signal_connect('changed' => \&treeViewChanged, $self); | ||
| 8287 | |||
| 8288 | # Fill the tree | ||
| 8289 | $self->setupTreeView($treeView); | ||
| 8290 | |||
| 8291 | # Add a notebook on the right. Later, this might be replaced by a second Gtk3::HPaned | ||
| 8292 | my $notebook = Gtk3::Notebook->new(); | ||
| 8293 | $hPaned->pack2($notebook, TRUE, FALSE); | ||
| 8294 | $notebook->set_scrollable(TRUE); | ||
| 8295 | $notebook->popup_enable(); | ||
| 8296 | |||
| 8297 | $hPaned->set_position($self->leftWidth); | ||
| 8298 | |||
| 8299 | # Set up the window's background photo using a CSS style | ||
| 8300 | my $provider = Gtk3::CssProvider->new(); | ||
| 8301 | my $display = Gtk3::Gdk::Display::get_default(); | ||
| 8302 | my $screen = Gtk3::Gdk::Display::get_default_screen($display); | ||
| 8303 | # (Don't call ->add_provider_for_screen so that the style is only applied to this window) | ||
| 8304 | # Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600); | ||
| 8305 | |||
| 8306 | my $imagePath = $axmud::SHARE_DIR . '/images/viewerbg.jpg'; | ||
| 8307 | |||
| 8308 | my $theming = "#css_oov_id, window.background {\n"; | ||
| 8309 | $theming .= " background-image: url(\"$imagePath\");\n"; | ||
| 8310 | $theming .= " background-repeat: repeat;\n"; | ||
| 8311 | $theming .= " background-position: top left;\n"; | ||
| 8312 | $theming .= "}"; | ||
| 8313 | |||
| 8314 | $provider->load_from_data ([map ord, split //, $theming]); | ||
| 8315 | |||
| 8316 | my $context = $self->winWidget->get_style_context(); | ||
| 8317 | $context->add_provider($provider, 600); | ||
| 8318 | |||
| 8319 | # Update IVs | ||
| 8320 | $self->ivPoke('packingBox', $packingBox); | ||
| 8321 | $self->ivPoke('hPaned', $hPaned); | ||
| 8322 | $self->ivPoke('treeViewModel', $treeViewModel); | ||
| 8323 | $self->ivPoke('treeView', $treeView); | ||
| 8324 | $self->ivPoke('treeViewScroller', $treeViewScroller); | ||
| 8325 | $self->ivPoke('notebook', $notebook); | ||
| 8326 | |||
| 8327 | return 1; | ||
| 8328 | } | ||
| 8329 | |||
| 8330 | # sub redrawWidgets {} # Inherited from GA::Generic::Win | ||
| 8331 | |||
| 8332 | # ->signal_connects | ||
| 8333 | |||
| 8334 | # Other functions | ||
| 8335 | |||
| 8336 | # Set up widgets | ||
| 8337 | |||
| 8338 | sub setupTreeView { | ||
| 8339 | |||
| 8340 | # Called by $self->enable | ||
| 8341 | # Fills the object tree on the left of the window | ||
| 8342 | # | ||
| 8343 | # Expected arguments | ||
| 8344 | # $treeView - The Gtk3::TreeView widget | ||
| 8345 | # | ||
| 8346 | # Return values | ||
| 8347 | # 'undef' on improper arguments | ||
| 8348 | # 1 otherwise | ||
| 8349 | |||
| 8350 | my ($self, $treeView, $check) = @_; | ||
| 8351 | |||
| 8352 | # Local variables | ||
| 8353 | my ( | ||
| 8354 | $model, $pointer, $child, $grandChild, $greatGrandChild, $greatGreatGrandChild, | ||
| 8355 | $scriptObj, | ||
| 8356 | @sortedList, @functionList, @taskList, | ||
| 8357 | %functionHash, | ||
| 8358 | ); | ||
| 8359 | |||
| 8360 | # Check for improper arguments | ||
| 8361 | if (! defined $treeView || defined $check) { | ||
| 8362 | |||
| 8363 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setupTreeView', @_); | ||
| 8364 | } | ||
| 8365 | |||
| 8366 | # Fill a model of the tree, not the tree itself | ||
| 8367 | $model = $treeView->get_model(); | ||
| 8368 | $model->clear(); | ||
| 8369 | |||
| 8370 | # Profiles | ||
| 8371 | $pointer = $model->append(undef); | ||
| 8372 | $model->set($pointer, [0], ['Profiles']); | ||
| 8373 | |||
| 8374 | $child = $model->append($pointer); | ||
| 8375 | $model->set($child, [0], ['All profiles']); | ||
| 8376 | $self->ivAdd('headerHash', 'All profiles', 'allProfHeader'); | ||
| 8377 | $child = $model->append($pointer); | ||
| 8378 | $model->set($child, [0], ['Current profiles']); | ||
| 8379 | $self->ivAdd('headerHash', 'Current profiles', 'currentProfHeader'); | ||
| 8380 | $child = $model->append($pointer); | ||
| 8381 | $model->set($child, [0], ['Profile templates']); | ||
| 8382 | $self->ivAdd('headerHash', 'Profile templates', 'templateHeader'); | ||
| 8383 | $child = $model->append($pointer); | ||
| 8384 | $model->set($child, [0], ['Profile priority list']); | ||
| 8385 | $self->ivAdd('headerHash', 'Profile priority list', 'profPriorityHeader'); | ||
| 8386 | |||
| 8387 | # Cages | ||
| 8388 | $pointer = $model->append(undef); | ||
| 8389 | $model->set($pointer, [0], ['Cages']); | ||
| 8390 | |||
| 8391 | $child = $model->append($pointer); | ||
| 8392 | $model->set($child, [0], ['All cages']); | ||
| 8393 | $self->ivAdd('headerHash', 'All cages', 'allCageHeader'); | ||
| 8394 | $child = $model->append($pointer); | ||
| 8395 | $model->set($child, [0], ['Current cages']); | ||
| 8396 | $self->ivAdd('headerHash', 'Current cages', 'currentCageHeader'); | ||
| 8397 | $child = $model->append($pointer); | ||
| 8398 | $model->set($child, [0], ['Active interfaces']); | ||
| 8399 | $self->ivAdd('headerHash', 'Active interfaces', 'activeInterfaceHeader'); | ||
| 8400 | $child = $model->append($pointer); | ||
| 8401 | $model->set($child, [0], ['Interface models']); | ||
| 8402 | $self->ivAdd('headerHash', 'Interface models', 'interfaceModelHeader'); | ||
| 8403 | |||
| 8404 | # Dictionaries | ||
| 8405 | $pointer = $model->append(undef); | ||
| 8406 | $model->set($pointer, [0], ['Dictionaries']); | ||
| 8407 | |||
| 8408 | $child = $model->append($pointer); | ||
| 8409 | $model->set($child, [0], ['All dictionaries']); | ||
| 8410 | $self->ivAdd('headerHash', 'All dictionaries', 'allDictHeader'); | ||
| 8411 | $child = $model->append($pointer); | ||
| 8412 | $model->set($child, [0], ['Current dictionary']); | ||
| 8413 | $self->ivAdd('headerHash', 'Current dictionary', 'currentDictHeader'); | ||
| 8414 | |||
| 8415 | # Tasks | ||
| 8416 | $pointer = $model->append(undef); | ||
| 8417 | $model->set($pointer, [0], ['Tasks']); | ||
| 8418 | |||
| 8419 | $child = $model->append($pointer); | ||
| 8420 | $model->set($child, [0], ['Available tasks']); | ||
| 8421 | $self->ivAdd('headerHash', 'Available tasks', 'availableTaskHeader'); | ||
| 8422 | $child = $model->append($pointer); | ||
| 8423 | $model->set($child, [0], ['Current tasklist']); | ||
| 8424 | $self->ivAdd('headerHash', 'Current tasklist', 'currentTaskHeader'); | ||
| 8425 | $child = $model->append($pointer); | ||
| 8426 | $model->set($child, [0], ['Global initial tasklist']); | ||
| 8427 | $self->ivAdd('headerHash', 'Global initial tasklist', 'initialTaskHeader'); | ||
| 8428 | $child = $model->append($pointer); | ||
| 8429 | $model->set($child, [0], ['Custom tasklist']); | ||
| 8430 | $self->ivAdd('headerHash', 'Custom tasklist', 'customTaskHeader'); | ||
| 8431 | $child = $model->append($pointer); | ||
| 8432 | $model->set($child, [0], ['Task package names']); | ||
| 8433 | $self->ivAdd('headerHash', 'Task package names', 'taskPackageHeader'); | ||
| 8434 | $child = $model->append($pointer); | ||
| 8435 | $model->set($child, [0], ['Task labels']); | ||
| 8436 | $self->ivAdd('headerHash', 'Task labels', 'taskLabelHeader'); | ||
| 8437 | |||
| 8438 | # World model | ||
| 8439 | $pointer = $model->append(undef); | ||
| 8440 | $model->set($pointer, [0], ['World model']); | ||
| 8441 | |||
| 8442 | $child = $model->append($pointer); | ||
| 8443 | $model->set($child, [0], ['All objects']); | ||
| 8444 | $self->ivAdd('headerHash', 'All objects', 'allModelHeader'); | ||
| 8445 | $child = $model->append($pointer); | ||
| 8446 | $model->set($child, [0], ['Regions']); | ||
| 8447 | $self->ivAdd('headerHash', 'Regions', 'regionModelHeader'); | ||
| 8448 | $child = $model->append($pointer); | ||
| 8449 | $model->set($child, [0], ['Rooms']); | ||
| 8450 | $self->ivAdd('headerHash', 'Rooms', 'roomModelHeader'); | ||
| 8451 | $child = $model->append($pointer); | ||
| 8452 | $model->set($child, [0], ['Weapons']); | ||
| 8453 | $self->ivAdd('headerHash', 'Weapons', 'weaponModelHeader'); | ||
| 8454 | $child = $model->append($pointer); | ||
| 8455 | $model->set($child, [0], ['Armours']); | ||
| 8456 | $self->ivAdd('headerHash', 'Armours', 'armourModelHeader'); | ||
| 8457 | $child = $model->append($pointer); | ||
| 8458 | $model->set($child, [0], ['Garments']); | ||
| 8459 | $self->ivAdd('headerHash', 'Garments', 'garmentModelHeader'); | ||
| 8460 | $child = $model->append($pointer); | ||
| 8461 | $model->set($child, [0], ['Characters']); | ||
| 8462 | $self->ivAdd('headerHash', 'Characters', 'charModelHeader'); | ||
| 8463 | $child = $model->append($pointer); | ||
| 8464 | $model->set($child, [0], ['Minions']); | ||
| 8465 | $self->ivAdd('headerHash', 'Minions', 'minionModelHeader'); | ||
| 8466 | $child = $model->append($pointer); | ||
| 8467 | $model->set($child, [0], ['Sentients']); | ||
| 8468 | $self->ivAdd('headerHash', 'Sentients', 'sentientModelHeader'); | ||
| 8469 | $child = $model->append($pointer); | ||
| 8470 | $model->set($child, [0], ['Creatures']); | ||
| 8471 | $self->ivAdd('headerHash', 'Creatures', 'creatureModelHeader'); | ||
| 8472 | $child = $model->append($pointer); | ||
| 8473 | $model->set($child, [0], ['Portables']); | ||
| 8474 | $self->ivAdd('headerHash', 'Portables', 'portableModelHeader'); | ||
| 8475 | $child = $model->append($pointer); | ||
| 8476 | $model->set($child, [0], ['Decorations']); | ||
| 8477 | $self->ivAdd('headerHash', 'Decorations', 'decorationModelHeader'); | ||
| 8478 | $child = $model->append($pointer); | ||
| 8479 | $model->set($child, [0], ['Custom objects']); | ||
| 8480 | $self->ivAdd('headerHash', 'Custom objects', 'customModelHeader'); | ||
| 8481 | $child = $model->append($pointer); | ||
| 8482 | $model->set($child, [0], ['Exits']); | ||
| 8483 | $self->ivAdd('headerHash', 'Exits', 'exitModelHeader'); | ||
| 8484 | |||
| 8485 | # Buffers | ||
| 8486 | $pointer = $model->append(undef); | ||
| 8487 | $model->set($pointer, [0], ['Buffers']); | ||
| 8488 | |||
| 8489 | $child = $model->append($pointer); | ||
| 8490 | $model->set($child, [0], ['Display buffer']); | ||
| 8491 | $self->ivAdd('headerHash', 'Display buffer', 'displayBufferHeader'); | ||
| 8492 | $child = $model->append($pointer); | ||
| 8493 | $model->set($child, [0], ['Instruction buffer']); | ||
| 8494 | $self->ivAdd('headerHash', 'Instruction buffer', 'instructBufferHeader'); | ||
| 8495 | $child = $model->append($pointer); | ||
| 8496 | $model->set($child, [0], ['Command buffer']); | ||
| 8497 | $self->ivAdd('headerHash', 'Command buffer', 'cmdBufferHeader'); | ||
| 8498 | |||
| 8499 | # Other objects | ||
| 8500 | $pointer = $model->append(undef); | ||
| 8501 | $model->set($pointer, [0], ['Other objects']); | ||
| 8502 | |||
| 8503 | $child = $model->append($pointer); | ||
| 8504 | $model->set($child, [0], ['Chat contacts']); | ||
| 8505 | $self->ivAdd('headerHash', 'Chat contacts', 'chatContactHeader'); | ||
| 8506 | |||
| 8507 | $child = $model->append($pointer); | ||
| 8508 | $model->set($child, [0], ['Colour schemes']); | ||
| 8509 | $self->ivAdd('headerHash', 'Colour schemes', 'colourSchemeHeader'); | ||
| 8510 | |||
| 8511 | $child = $model->append($pointer); | ||
| 8512 | $model->set($child, [0], ['Map label styles']); | ||
| 8513 | $self->ivAdd('headerHash', 'Map label styles', 'mapLabelStyleHeader'); | ||
| 8514 | |||
| 8515 | $child = $model->append($pointer); | ||
| 8516 | $model->set($child, [0], ['Region colour schemes']); | ||
| 8517 | $self->ivAdd('headerHash', 'Region colour schemes', 'regionSchemeHeader'); | ||
| 8518 | |||
| 8519 | $child = $model->append($pointer); | ||
| 8520 | $model->set($child, [0], ['TTS configurations']); | ||
| 8521 | $self->ivAdd('headerHash', 'TTS configurations', 'ttsHeader'); | ||
| 8522 | |||
| 8523 | $child = $model->append($pointer); | ||
| 8524 | $model->set($child, [0], ['Winmaps']); | ||
| 8525 | $self->ivAdd('headerHash', 'Winmaps', 'winmapHeader'); | ||
| 8526 | |||
| 8527 | $child = $model->append($pointer); | ||
| 8528 | $model->set($child, [0], ['Zonemaps']); | ||
| 8529 | $self->ivAdd('headerHash', 'Zonemaps', 'zonemapHeader'); | ||
| 8530 | |||
| 8531 | # Help | ||
| 8532 | $pointer = $model->append(undef); | ||
| 8533 | $model->set($pointer, [0], ['Help']); | ||
| 8534 | |||
| 8535 | # Quick help | ||
| 8536 | $child = $model->append($pointer); | ||
| 8537 | $model->set($child, [0], ['Quick help']); | ||
| 8538 | $self->ivAdd('headerHash', 'Quick help', 'quickHelpHeader'); | ||
| 8539 | |||
| 8540 | # Client command Help | ||
| 8541 | $child = $model->append($pointer); | ||
| 8542 | $model->set($child, [0], ['Client commands']); | ||
| 8543 | |||
| 8544 | $grandChild = $model->append($child); | ||
| 8545 | $model->set($grandChild, [0], ['Categorised commands']); | ||
| 8546 | |||
| 8547 | foreach my $item ($axmud::CLIENT->clientCmdPrettyList) { | ||
| 8548 | |||
| 8549 | if (index ($item, '@') == 0) { | ||
| 8550 | |||
| 8551 | # It's a group heading, so remove the @ character | ||
| 8552 | $item =~ s/\@//; | ||
| 8553 | $greatGrandChild = $model->append($grandChild); | ||
| 8554 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8555 | |||
| 8556 | } else { | ||
| 8557 | |||
| 8558 | # It's a client command, which begins with ; to distinguish it from Axbasic items | ||
| 8559 | $item = $axmud::CLIENT->cmdSep . lc($item); | ||
| 8560 | $greatGreatGrandChild = $model->append($greatGrandChild); | ||
| 8561 | $model->set($greatGreatGrandChild, [0], [$item]); | ||
| 8562 | $self->ivAdd('headerHash', $item, 'cmdHeader'); | ||
| 8563 | } | ||
| 8564 | } | ||
| 8565 | |||
| 8566 | $grandChild = $model->append($child); | ||
| 8567 | $model->set($grandChild, [0], ['Sorted commands']); | ||
| 8568 | |||
| 8569 | @sortedList = sort {$a cmp $b} ($axmud::CLIENT->clientCmdList); | ||
| 8570 | foreach my $item (@sortedList) { | ||
| 8571 | |||
| 8572 | # It's a client command, which begins with ; to distinguish it from Axbasic items | ||
| 8573 | $item = $axmud::CLIENT->cmdSep . lc($item); | ||
| 8574 | $greatGrandChild = $model->append($grandChild); | ||
| 8575 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8576 | $self->ivAdd('headerHash', $item, 'cmdHeader'); | ||
| 8577 | } | ||
| 8578 | |||
| 8579 | # Axbasic Help | ||
| 8580 | |||
| 8581 | # Create a dummy LA::Script object so we can access the default instance variables and help | ||
| 8582 | # functions | ||
| 8583 | $scriptObj = Language::Axbasic::Script->new($self->session); | ||
| 8584 | if ($scriptObj) { | ||
| 8585 | |||
| 8586 | $child = $model->append($pointer); | ||
| 8587 | $model->set($child, [0], [$axmud::BASIC_NAME . ' help']); | ||
| 8588 | |||
| 8589 | $grandChild = $model->append($child); | ||
| 8590 | $model->set($grandChild, [0], ['Keywords']); | ||
| 8591 | |||
| 8592 | foreach my $item ($scriptObj->keywordList) { | ||
| 8593 | |||
| 8594 | $greatGrandChild = $model->append($grandChild); | ||
| 8595 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8596 | $self->ivAdd('headerHash', $item, 'axbasicKeywordHeader'); | ||
| 8597 | } | ||
| 8598 | |||
| 8599 | $grandChild = $model->append($child); | ||
| 8600 | $model->set($grandChild, [0], ['Modern keywords']); | ||
| 8601 | |||
| 8602 | foreach my $item ($scriptObj->modernKeywordList) { | ||
| 8603 | |||
| 8604 | $greatGrandChild = $model->append($grandChild); | ||
| 8605 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8606 | $self->ivAdd('headerHash', $item, 'axbasicKeywordHeader'); | ||
| 8607 | } | ||
| 8608 | |||
| 8609 | $grandChild = $model->append($child); | ||
| 8610 | $model->set($grandChild, [0], ['Primitive keywords']); | ||
| 8611 | |||
| 8612 | foreach my $item ($scriptObj->primKeywordList) { | ||
| 8613 | |||
| 8614 | $greatGrandChild = $model->append($grandChild); | ||
| 8615 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8616 | $self->ivAdd('headerHash', $item, 'axbasicKeywordHeader'); | ||
| 8617 | } | ||
| 8618 | |||
| 8619 | $grandChild = $model->append($child); | ||
| 8620 | $model->set($grandChild, [0], ['Weak keywords']); | ||
| 8621 | |||
| 8622 | @sortedList = sort {$a cmp $b} ($scriptObj->ivKeys('weakKeywordHash')); | ||
| 8623 | foreach my $item (@sortedList) { | ||
| 8624 | |||
| 8625 | $greatGrandChild = $model->append($grandChild); | ||
| 8626 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8627 | $self->ivAdd('headerHash', $item, 'axbasicKeywordHeader'); | ||
| 8628 | } | ||
| 8629 | |||
| 8630 | $grandChild = $model->append($child); | ||
| 8631 | $model->set($grandChild, [0], ['Client keywords']); | ||
| 8632 | |||
| 8633 | foreach my $item ($scriptObj->clientKeywordList) { | ||
| 8634 | |||
| 8635 | $greatGrandChild = $model->append($grandChild); | ||
| 8636 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8637 | $self->ivAdd('headerHash', $item, 'axbasicKeywordHeader'); | ||
| 8638 | } | ||
| 8639 | |||
| 8640 | $grandChild = $model->append($child); | ||
| 8641 | $model->set($grandChild, [0], ['Task keywords']); | ||
| 8642 | |||
| 8643 | foreach my $item ($scriptObj->taskKeywordList) { | ||
| 8644 | |||
| 8645 | $greatGrandChild = $model->append($grandChild); | ||
| 8646 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8647 | $self->ivAdd('headerHash', $item, 'axbasicKeywordHeader'); | ||
| 8648 | } | ||
| 8649 | |||
| 8650 | $grandChild = $model->append($child); | ||
| 8651 | $model->set($grandChild, [0], ['Intrinsic functions']); | ||
| 8652 | |||
| 8653 | %functionHash = $scriptObj->funcArgHash; | ||
| 8654 | @functionList = sort {$a cmp $b} (keys %functionHash); | ||
| 8655 | foreach my $item (@functionList) { | ||
| 8656 | |||
| 8657 | $greatGrandChild = $model->append($grandChild); | ||
| 8658 | $model->set($greatGrandChild, [0], [$item]); | ||
| 8659 | $self->ivAdd('headerHash', $item, 'axbasicFuncHeader'); | ||
| 8660 | } | ||
| 8661 | |||
| 8662 | # (Store the dummy script object, so that functions like $self->axbasicKeywordHeader can | ||
| 8663 | # use it) | ||
| 8664 | $self->ivPoke('dummyScriptObj', $scriptObj); | ||
| 8665 | } | ||
| 8666 | |||
| 8667 | # Task Help | ||
| 8668 | $child = $model->append($pointer); | ||
| 8669 | $model->set($child, [0], ['Task help']); | ||
| 8670 | |||
| 8671 | @taskList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskPackageHash')); | ||
| 8672 | foreach my $task (@taskList) { | ||
| 8673 | |||
| 8674 | $grandChild = $model->append($child); | ||
| 8675 | $model->set($grandChild, [0], [$task]); | ||
| 8676 | $self->ivAdd('headerHash', $task, 'taskHeader'); | ||
| 8677 | } | ||
| 8678 | |||
| 8679 | # Peek/poke help | ||
| 8680 | $child = $model->append($pointer); | ||
| 8681 | $model->set($child, [0], ['Peek/poke strings']); | ||
| 8682 | $self->ivAdd('headerHash', 'Peek/poke strings', 'peekPokeHelpHeader'); | ||
| 8683 | |||
| 8684 | return 1; | ||
| 8685 | } | ||
| 8686 | |||
| 8687 | sub refreshNotebook { | ||
| 8688 | |||
| 8689 | # Called by $self->currentProfHeader, $self->allProfHeader, (etc etc) | ||
| 8690 | # Populates the notebook with tabs and a list, using the supplied arguments | ||
| 8691 | # (Header functions which need a textview, rather than a simple list, call | ||
| 8692 | # ->refreshTextView) | ||
| 8693 | # | ||
| 8694 | # Expected arguments | ||
| 8695 | # $tabListRef - a reference to a hash of tabs, in the format | ||
| 8696 | # [ | ||
| 8697 | # 'tab_name' => 'tab_mnemonic', | ||
| 8698 | # 'tab_name' => 'tab_mnemonic', | ||
| 8699 | # 'tab_name' => 'tab_mnemonic', | ||
| 8700 | # ... | ||
| 8701 | # ] | ||
| 8702 | # | ||
| 8703 | # $columnListRef - a list of columns used in the call to GA::Obj::SimpleList->new, in | ||
| 8704 | # the format | ||
| 8705 | # [ | ||
| 8706 | # 'column_name' => 'type', | ||
| 8707 | # 'column_name' => 'type', | ||
| 8708 | # 'column_name' => 'type', | ||
| 8709 | # ... | ||
| 8710 | # ] | ||
| 8711 | # | ||
| 8712 | # $dataHashRef - a reference to a hash. The keys are the same as the keys in | ||
| 8713 | # $tabListRef; the corresponding values contain a reference to a | ||
| 8714 | # two-dimensional list of data to be displayed in the | ||
| 8715 | # GA::Obj::SimpleList, in the form | ||
| 8716 | # [ | ||
| 8717 | # [row0_cell0, row0_cell1, row0cell2...], | ||
| 8718 | # [row1_cell0, row1_cell1, row1cell2...], | ||
| 8719 | # [row2_cell0, row2_cell1, row2cell2...], | ||
| 8720 | # ... | ||
| 8721 | # ] | ||
| 8722 | # | ||
| 8723 | # Optional arguments | ||
| 8724 | # $buttonListRef - a reference to a list of buttons, in the format | ||
| 8725 | # [ | ||
| 8726 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 8727 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 8728 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 8729 | # ... | ||
| 8730 | # ] | ||
| 8731 | # - if $buttonListRef is 'undef', no buttons are displayed | ||
| 8732 | # | ||
| 8733 | # $scrollFlag - if set to TRUE, the Gtk3::ScrolledWindow is scrolled to the bottom; | ||
| 8734 | # if FALSE (or 'undef'), it remains scrolled to the top | ||
| 8735 | # | ||
| 8736 | # Return values | ||
| 8737 | # 'undef' on improper arguments | ||
| 8738 | # 1 otherwise | ||
| 8739 | |||
| 8740 | my ( | ||
| 8741 | $self, $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, $scrollFlag, | ||
| 8742 | $check, | ||
| 8743 | ) = @_; | ||
| 8744 | |||
| 8745 | # Local variables | ||
| 8746 | my ( | ||
| 8747 | $number, $dataListRef, | ||
| 8748 | @tabList, @columnList, @buttonList, @scrollerList, | ||
| 8749 | %dataHash, | ||
| 8750 | ); | ||
| 8751 | |||
| 8752 | # Check for improper arguments | ||
| 8753 | if ( | ||
| 8754 | ! defined $tabListRef || ! defined $columnListRef || ! defined $dataHashRef | ||
| 8755 | || defined $check | ||
| 8756 | ) { | ||
| 8757 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshNotebook', @_); | ||
| 8758 | } | ||
| 8759 | |||
| 8760 | # Dereference the supplied arguments | ||
| 8761 | @tabList = @$tabListRef; | ||
| 8762 | @columnList = @$columnListRef; | ||
| 8763 | %dataHash = %$dataHashRef; | ||
| 8764 | if ($buttonListRef) { | ||
| 8765 | |||
| 8766 | @buttonList = @$buttonListRef; | ||
| 8767 | }; | ||
| 8768 | |||
| 8769 | # Remove the existing tabs and buttons (if any) | ||
| 8770 | $self->resetNotebook(); | ||
| 8771 | |||
| 8772 | # If a button list was not visible, but should now be visible, do some repacking | ||
| 8773 | if (! $self->hPaned2 && $buttonListRef) { | ||
| 8774 | |||
| 8775 | # Unpack existing widgets | ||
| 8776 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned, $self->treeViewScroller); | ||
| 8777 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned, $self->notebook); | ||
| 8778 | |||
| 8779 | # Repack the treeview scroller | ||
| 8780 | $self->hPaned->pack1($self->treeViewScroller, FALSE, FALSE); | ||
| 8781 | |||
| 8782 | # Add a second horizontal pane on the right of the first one | ||
| 8783 | # In this pane, a notebook is on the left, and a strip of buttons is on the right | ||
| 8784 | my $hPaned2 = Gtk3::HPaned->new(); | ||
| 8785 | $self->hPaned->pack2($hPaned2, TRUE, FALSE); | ||
| 8786 | |||
| 8787 | # Repack the notebook on the left of $hPaned2 | ||
| 8788 | $hPaned2->pack1($self->notebook, TRUE, FALSE); | ||
| 8789 | |||
| 8790 | # Add a second vertical packing box for the strip of buttons | ||
| 8791 | my $vBox = Gtk3::VBox->new(FALSE, 0); | ||
| 8792 | $hPaned2->pack2($vBox, FALSE, FALSE); | ||
| 8793 | |||
| 8794 | $self->hPaned->set_position($self->leftWidth); | ||
| 8795 | $hPaned2->set_position($self->centreWidth); | ||
| 8796 | |||
| 8797 | # Update IVs | ||
| 8798 | $self->ivPoke('hPaned2', $hPaned2); | ||
| 8799 | $self->ivPoke('vBox', $vBox); | ||
| 8800 | |||
| 8801 | # Likewise, if the button list was visible and is no longer required, do some repacking | ||
| 8802 | } elsif ($self->hPaned2 && ! $buttonListRef) { | ||
| 8803 | |||
| 8804 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned, $self->treeViewScroller); | ||
| 8805 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned2, $self->notebook); | ||
| 8806 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned, $self->hPaned2); | ||
| 8807 | |||
| 8808 | # Repack the treeview scroller | ||
| 8809 | $self->hPaned->pack1($self->treeViewScroller, FALSE, FALSE); | ||
| 8810 | |||
| 8811 | # Repack the notebook | ||
| 8812 | $self->hPaned->pack2($self->notebook, TRUE, FALSE); | ||
| 8813 | |||
| 8814 | $self->hPaned->set_position($self->leftWidth); | ||
| 8815 | |||
| 8816 | # Update IVs | ||
| 8817 | $self->ivUndef('hPaned2'); | ||
| 8818 | $self->ivUndef('vBox'); | ||
| 8819 | } | ||
| 8820 | |||
| 8821 | # Create new tabs in the notebook | ||
| 8822 | do { | ||
| 8823 | |||
| 8824 | my ( | ||
| 8825 | $tab, $mnemonic, $slWidget, $scroller, $label, $slWidgetRef, $button, $count, | ||
| 8826 | $vAdjust, | ||
| 8827 | @ownColumnList, | ||
| 8828 | ); | ||
| 8829 | |||
| 8830 | $tab = shift @tabList; | ||
| 8831 | $mnemonic = shift @tabList; | ||
| 8832 | |||
| 8833 | # Add a simple list | ||
| 8834 | $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList); | ||
| 8835 | # Make each row double-clickable | ||
| 8836 | $slWidget->signal_connect('row_activated' => sub { | ||
| 8837 | |||
| 8838 | # If doubling-clicking on a row is equivalent to something else, call the specified | ||
| 8839 | # function to make it happen | ||
| 8840 | if ($self->notebookSelectRef) { | ||
| 8841 | |||
| 8842 | &{$self->notebookSelectRef}; | ||
| 8843 | } | ||
| 8844 | }); | ||
| 8845 | |||
| 8846 | # Make the simple list scrollable | ||
| 8847 | $scroller = Gtk3::ScrolledWindow->new(); | ||
| 8848 | $scroller->set_policy('automatic', 'automatic'); | ||
| 8849 | $scroller->add($slWidget); | ||
| 8850 | push (@scrollerList, $scroller); | ||
| 8851 | |||
| 8852 | # Fill the columns with data | ||
| 8853 | $dataListRef = $dataHash{$tab}; | ||
| 8854 | @{$slWidget->{data}} = @$dataListRef; | ||
| 8855 | |||
| 8856 | # Make all columns of type 'bool' (which are composed of checkbuttons) non-activatable, | ||
| 8857 | # so that the user can't click them on and off | ||
| 8858 | if (@columnList) { | ||
| 8859 | |||
| 8860 | $count = -1; | ||
| 8861 | @ownColumnList = @columnList; | ||
| 8862 | |||
| 8863 | do { | ||
| 8864 | |||
| 8865 | my ($title, $type); | ||
| 8866 | |||
| 8867 | $title = shift @ownColumnList; | ||
| 8868 | $type = shift @ownColumnList; | ||
| 8869 | |||
| 8870 | $count++; | ||
| 8871 | |||
| 8872 | if ($type eq 'bool') { | ||
| 8873 | |||
| 8874 | my ($cellRenderer) = $slWidget->get_column($count)->get_cells(); | ||
| 8875 | $cellRenderer->set(activatable => FALSE); | ||
| 8876 | } | ||
| 8877 | |||
| 8878 | } until (! @ownColumnList); | ||
| 8879 | } | ||
| 8880 | |||
| 8881 | # Give the tab a label | ||
| 8882 | $label = Gtk3::Label->new_with_mnemonic($tab); | ||
| 8883 | $label->set_markup_with_mnemonic($mnemonic); | ||
| 8884 | # Add the tab to the notebook | ||
| 8885 | $self->notebook->append_page($scroller, $label); | ||
| 8886 | |||
| 8887 | # Update IVs | ||
| 8888 | $self->ivAdd('notebookTabHash', $tab, $label); | ||
| 8889 | $self->ivPush('notebookTabList', $tab); | ||
| 8890 | $self->ivAdd('notebookDataHash', $tab, $slWidget); | ||
| 8891 | |||
| 8892 | } until (! @tabList); | ||
| 8893 | |||
| 8894 | # Displaying a list of objects puts the notebook in 'list' mode | ||
| 8895 | $self->ivPoke('notebookMode', 'list'); | ||
| 8896 | |||
| 8897 | # Add an strip of buttons at the top of $self->vBox | ||
| 8898 | if (@buttonList) { | ||
| 8899 | |||
| 8900 | do { | ||
| 8901 | |||
| 8902 | my ($name, $tip, $method, $btn); | ||
| 8903 | |||
| 8904 | $name = shift @buttonList; | ||
| 8905 | $tip = shift @buttonList; | ||
| 8906 | $method = shift @buttonList; | ||
| 8907 | |||
| 8908 | $btn = Gtk3::Button->new($name); | ||
| 8909 | $btn->signal_connect('clicked' => sub { | ||
| 8910 | |||
| 8911 | $self->$method(); | ||
| 8912 | }); | ||
| 8913 | $btn->set_tooltip_text($tip); | ||
| 8914 | |||
| 8915 | $self->vBox->pack_start($btn, FALSE, FALSE, 0); | ||
| 8916 | $self->ivPush('buttonList', $btn); | ||
| 8917 | |||
| 8918 | } until (! @buttonList); | ||
| 8919 | } | ||
| 8920 | |||
| 8921 | # Add a separator just beneath these buttons | ||
| 8922 | my $separator = Gtk3::HSeparator->new(); | ||
| 8923 | $self->vBox->pack_start($separator, FALSE, FALSE, 10); | ||
| 8924 | $self->ivPush('buttonList', $separator); | ||
| 8925 | |||
| 8926 | # Add two standard buttons at the bottom of $self->vBox, regardless of the type of list | ||
| 8927 | # displayed | ||
| 8928 | my $btn = Gtk3::Button->new('Refresh list'); | ||
| 8929 | $btn->signal_connect('clicked' => sub { | ||
| 8930 | |||
| 8931 | $self->updateNotebook(); | ||
| 8932 | }); | ||
| 8933 | $btn->set_tooltip_text('Refresh this list'); | ||
| 8934 | $self->vBox->pack_start($btn, FALSE, FALSE, 0); | ||
| 8935 | $self->ivPush('buttonList', $btn); | ||
| 8936 | |||
| 8937 | my $btn2 = Gtk3::Button->new('Exit viewer'); | ||
| 8938 | $btn2->signal_connect('clicked' => sub { | ||
| 8939 | |||
| 8940 | $self->winDestroy(); | ||
| 8941 | }); | ||
| 8942 | $btn2->set_tooltip_text('Close the ' . $axmud::SCRIPT . ' data viewer'); | ||
| 8943 | $self->vBox->pack_start($btn2, FALSE, FALSE, 0); | ||
| 8944 | $self->ivPush('buttonList', $btn2); | ||
| 8945 | |||
| 8946 | # Set the width of the notebook, depending on whether there are any buttons to display | ||
| 8947 | if ($buttonListRef) { | ||
| 8948 | $self->hPaned2->set_position($self->centreWidth); | ||
| 8949 | } else { | ||
| 8950 | $self->hPaned2->set_position($self->centreWidth + $self->rightWidth); | ||
| 8951 | } | ||
| 8952 | |||
| 8953 | # Render the changes | ||
| 8954 | $self->winShowAll($self->_objClass . '->refreshNotebook'); | ||
| 8955 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->refreshNotebook'); | ||
| 8956 | |||
| 8957 | # If $scrollFlag is set, we can now scroll the Gtk3::ScrolledWindow to the bottom | ||
| 8958 | if ($scrollFlag) { | ||
| 8959 | |||
| 8960 | foreach my $scroller (@scrollerList) { | ||
| 8961 | |||
| 8962 | my $vAdjust = $scroller->get_vadjustment(); | ||
| 8963 | |||
| 8964 | $vAdjust->set_value( | ||
| 8965 | $vAdjust->get_lower() | ||
| 8966 | + (($vAdjust->get_upper() - $vAdjust->get_page_size()) - $vAdjust->get_lower()) | ||
| 8967 | ); | ||
| 8968 | } | ||
| 8969 | |||
| 8970 | $self->winShowAll($self->_objClass . '->refreshNotebook'); | ||
| 8971 | } | ||
| 8972 | |||
| 8973 | return 1; | ||
| 8974 | } | ||
| 8975 | |||
| 8976 | sub resetNotebook { | ||
| 8977 | |||
| 8978 | # Called by $self->refreshNotebook | ||
| 8979 | # Resets the notebook, removing tabs and buttons | ||
| 8980 | # | ||
| 8981 | # Expected arguments | ||
| 8982 | # (none besides $self) | ||
| 8983 | # | ||
| 8984 | # Return values | ||
| 8985 | # 'undef' on improper arguments or if there is no notebook to reset | ||
| 8986 | # 1 otherwise | ||
| 8987 | |||
| 8988 | my ($self, $check) = @_; | ||
| 8989 | |||
| 8990 | # Local variables | ||
| 8991 | my $number; | ||
| 8992 | |||
| 8993 | # Check for improper arguments | ||
| 8994 | if (defined $check) { | ||
| 8995 | |||
| 8996 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetNotebook', @_); | ||
| 8997 | } | ||
| 8998 | |||
| 8999 | # If the notebook doesn't exist, there's nothing to reset | ||
| 9000 | if (! $self->notebook) { | ||
| 9001 | |||
| 9002 | return undef; | ||
| 9003 | } | ||
| 9004 | |||
| 9005 | # Remove the existing tabs (if any) | ||
| 9006 | if ( | ||
| 9007 | $self->notebookMode eq 'list' | ||
| 9008 | || $self->notebookMode eq 'text' | ||
| 9009 | ) { | ||
| 9010 | $number = $self->notebook->get_n_pages(); | ||
| 9011 | if ($number) { | ||
| 9012 | |||
| 9013 | for (my $count = 0; $count < $number; $count++) { | ||
| 9014 | |||
| 9015 | $self->notebook->remove_page(0); | ||
| 9016 | } | ||
| 9017 | } | ||
| 9018 | |||
| 9019 | $self->ivEmpty('notebookTabHash'); | ||
| 9020 | $self->ivEmpty('notebookTabList'); | ||
| 9021 | $self->ivEmpty('notebookDataHash'); | ||
| 9022 | } | ||
| 9023 | |||
| 9024 | # Remove the existing buttons (if any) | ||
| 9025 | if ($self->buttonList) { | ||
| 9026 | |||
| 9027 | foreach my $button ($self->buttonList) { | ||
| 9028 | |||
| 9029 | $button->destroy; | ||
| 9030 | } | ||
| 9031 | |||
| 9032 | $self->ivEmpty('buttonList'); | ||
| 9033 | } | ||
| 9034 | |||
| 9035 | return 1; | ||
| 9036 | } | ||
| 9037 | |||
| 9038 | sub refreshTextView { | ||
| 9039 | |||
| 9040 | # Called by $self->cmdHeader (etc) | ||
| 9041 | # Creates a Gtk3::TextView in the notebook, and writes the supplied text to it | ||
| 9042 | # (Header functions which need a simple list, rather than a textview, call | ||
| 9043 | # ->refreshNotebook) | ||
| 9044 | # | ||
| 9045 | # Expected arguments | ||
| 9046 | # $tab - The title of the notebook tab | ||
| 9047 | # @list - A list of lines to display in the textview | ||
| 9048 | # | ||
| 9049 | # Return values | ||
| 9050 | # 'undef' on improper arguments | ||
| 9051 | # 1 otherwise | ||
| 9052 | |||
| 9053 | my ($self, $tab, @list) = @_; | ||
| 9054 | |||
| 9055 | # Local variables | ||
| 9056 | my $label; | ||
| 9057 | |||
| 9058 | # Check for improper arguments | ||
| 9059 | if (! defined $tab) { | ||
| 9060 | |||
| 9061 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshTextView', @_); | ||
| 9062 | } | ||
| 9063 | |||
| 9064 | # If the button strip is visible, do some repacking | ||
| 9065 | if ($self->hPaned2) { | ||
| 9066 | |||
| 9067 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned2, $self->notebook); | ||
| 9068 | $axmud::CLIENT->desktopObj->removeWidget($self->hPaned, $self->hPaned2); | ||
| 9069 | |||
| 9070 | $self->hPaned->add2($self->notebook); | ||
| 9071 | |||
| 9072 | $self->hPaned->set_position($self->leftWidth); | ||
| 9073 | } | ||
| 9074 | |||
| 9075 | # Update IVs | ||
| 9076 | $self->ivUndef('hPaned2'); | ||
| 9077 | $self->ivUndef('vBox'); | ||
| 9078 | |||
| 9079 | # Remove the existing notebook content | ||
| 9080 | $self->resetNotebook(); | ||
| 9081 | |||
| 9082 | # Create a scrolled window | ||
| 9083 | my $scrolled = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 9084 | $scrolled->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 9085 | $scrolled->set_policy('automatic', 'automatic'); | ||
| 9086 | $scrolled->set_border_width(5); | ||
| 9087 | |||
| 9088 | # Create a textview with default colours/fonts | ||
| 9089 | my $textView = Gtk3::TextView->new(); | ||
| 9090 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 9091 | $textView->set_buffer($buffer); | ||
| 9092 | $textView->set_editable(FALSE); | ||
| 9093 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView); | ||
| 9094 | |||
| 9095 | # Copy the text into the textview | ||
| 9096 | $buffer->set_text(join("\n", @list)); | ||
| 9097 | |||
| 9098 | # Complete setup | ||
| 9099 | $scrolled->add($textView); | ||
| 9100 | |||
| 9101 | # Add a label | ||
| 9102 | $label = Gtk3::Label->new_with_mnemonic($tab); | ||
| 9103 | $self->notebook->append_page($scrolled, $label); | ||
| 9104 | |||
| 9105 | # Render the changes | ||
| 9106 | $self->winShowAll($self->_objClass . '->refreshTextView'); | ||
| 9107 | |||
| 9108 | # Update IVs | ||
| 9109 | $self->ivAdd('notebookTabHash', $tab, $label); | ||
| 9110 | $self->ivPoke('notebookMode', 'text'); | ||
| 9111 | |||
| 9112 | return 1; | ||
| 9113 | } | ||
| 9114 | |||
| 9115 | sub updateNotebook { | ||
| 9116 | |||
| 9117 | # Called whenever the current notebook changes (when a new profile or cage is created or | ||
| 9118 | # deleted - eg by $self->refreshNotebook) | ||
| 9119 | # Updates the notebook by calling the same method called when a header in the treeview is | ||
| 9120 | # selected | ||
| 9121 | # | ||
| 9122 | # Expected arguments | ||
| 9123 | # (none besides $self) | ||
| 9124 | # | ||
| 9125 | # Optional arguments | ||
| 9126 | # @list - The rows in the notebook's GA::Obj::SimpleList which should be marked as | ||
| 9127 | # 'selected' (as if the user had clicked on them). If the list is empty, | ||
| 9128 | # no rows are marked as 'selected' | ||
| 9129 | # | ||
| 9130 | # Return values | ||
| 9131 | # 'undef' on improper arguments or if the notebook isn't displaying anything | ||
| 9132 | # 1 otherwise | ||
| 9133 | |||
| 9134 | my ($self, @list) = @_; | ||
| 9135 | |||
| 9136 | # Local variables | ||
| 9137 | my ($method, $currentTab); | ||
| 9138 | |||
| 9139 | # (No improper arguments to check) | ||
| 9140 | |||
| 9141 | if ( | ||
| 9142 | $self->notebookCurrentHeader | ||
| 9143 | && $self->ivExists('headerHash', $self->notebookCurrentHeader) | ||
| 9144 | ) { | ||
| 9145 | # Remember the currently selected tab | ||
| 9146 | $currentTab = $self->notebook->get_current_page(); | ||
| 9147 | |||
| 9148 | # Call the method specified by $self->headerHash | ||
| 9149 | $method = $self->ivShow('headerHash', $self->notebookCurrentHeader); | ||
| 9150 | $self->$method($self->notebookCurrentHeader); | ||
| 9151 | |||
| 9152 | # If @list isn't empty, mark some of the rows as selected | ||
| 9153 | if (@list) { | ||
| 9154 | |||
| 9155 | $self->notebookSetSelectedLines(@list); | ||
| 9156 | } | ||
| 9157 | |||
| 9158 | # Open the previously selected tab | ||
| 9159 | $self->notebook->set_current_page($currentTab); | ||
| 9160 | |||
| 9161 | return 1; | ||
| 9162 | |||
| 9163 | } else { | ||
| 9164 | |||
| 9165 | return undef; | ||
| 9166 | } | ||
| 9167 | } | ||
| 9168 | |||
| 9169 | # Notebook support functions | ||
| 9170 | |||
| 9171 | sub notebookGetTab { | ||
| 9172 | |||
| 9173 | # Can be called by anything | ||
| 9174 | # Finds the name of the current tab in the notebook | ||
| 9175 | # | ||
| 9176 | # Expected arguments | ||
| 9177 | # (none besides $self) | ||
| 9178 | # | ||
| 9179 | # Return values | ||
| 9180 | # 'undef' on improper arguments | ||
| 9181 | # Otherwise, returns the name (label) of the tab | ||
| 9182 | |||
| 9183 | my ($self, $check) = @_; | ||
| 9184 | |||
| 9185 | # Local variables | ||
| 9186 | my $number; | ||
| 9187 | |||
| 9188 | # Check for improper arguments | ||
| 9189 | if (defined $check) { | ||
| 9190 | |||
| 9191 | return $axmud::CLIENT->writeImproper($self->_objClass . '->notebookGetTab', @_); | ||
| 9192 | } | ||
| 9193 | |||
| 9194 | $number = $self->notebook->get_current_page(); | ||
| 9195 | return $self->ivIndex('notebookTabList', $number); | ||
| 9196 | } | ||
| 9197 | |||
| 9198 | sub notebookGetData { | ||
| 9199 | |||
| 9200 | # Can be called by anything | ||
| 9201 | # Finds the data displayed in the GA::Obj::SimpleList of the current notebook tab | ||
| 9202 | # (use ->notebookGetSelectedData to get only the selected data) | ||
| 9203 | # | ||
| 9204 | # Expected arguments | ||
| 9205 | # (none besides $self) | ||
| 9206 | # | ||
| 9207 | # Return values | ||
| 9208 | # 'undef' on improper arguments | ||
| 9209 | # Otherwise, returns the reference to the selected data, matching | ||
| 9210 | # GA::Obj::SimpleList->{data} | ||
| 9211 | |||
| 9212 | my ($self, $check) = @_; | ||
| 9213 | |||
| 9214 | # Local variables | ||
| 9215 | my $tabName; | ||
| 9216 | |||
| 9217 | # Check for improper arguments | ||
| 9218 | if (defined $check) { | ||
| 9219 | |||
| 9220 | return $axmud::CLIENT->writeImproper($self->_objClass . '->notebookGetData', @_); | ||
| 9221 | } | ||
| 9222 | |||
| 9223 | $tabName = $self->notebookGetTab(); | ||
| 9224 | return $self->ivShow('notebookDataHash', $tabName); | ||
| 9225 | } | ||
| 9226 | |||
| 9227 | sub notebookGetSelectedData { | ||
| 9228 | |||
| 9229 | # Can be called by anything | ||
| 9230 | # Gets the data displayed in the selected line of the GA::Obj::SimpleList of the current | ||
| 9231 | # notebook tab | ||
| 9232 | # | ||
| 9233 | # Expected arguments | ||
| 9234 | # (none besides $self) | ||
| 9235 | # | ||
| 9236 | # Return values | ||
| 9237 | # An empty list on improper arguments | ||
| 9238 | # Otherwise, returns a list, each element containing a list reference with all the data in | ||
| 9239 | # a selected row | ||
| 9240 | |||
| 9241 | my ($self, $check) = @_; | ||
| 9242 | |||
| 9243 | # Local variables | ||
| 9244 | my ( | ||
| 9245 | $dataRef, | ||
| 9246 | @emptyList, @selectList, @returnList, | ||
| 9247 | ); | ||
| 9248 | |||
| 9249 | # Check for improper arguments | ||
| 9250 | if (defined $check) { | ||
| 9251 | |||
| 9252 | $axmud::CLIENT->writeImproper($self->_objClass . '->notebookGetSelectedData', @_); | ||
| 9253 | return @emptyList, | ||
| 9254 | } | ||
| 9255 | |||
| 9256 | $dataRef = $self->notebookGetData(); | ||
| 9257 | @selectList = $dataRef->get_selected_indices(); | ||
| 9258 | |||
| 9259 | foreach my $index (@selectList) { | ||
| 9260 | |||
| 9261 | push (@returnList, ${$dataRef->{data}}[$index]); | ||
| 9262 | } | ||
| 9263 | |||
| 9264 | return @returnList; | ||
| 9265 | } | ||
| 9266 | |||
| 9267 | sub notebookGetSelectedLines { | ||
| 9268 | |||
| 9269 | # Can be called by anything | ||
| 9270 | # Gets a list containing the number of each selected line in the GA::Obj::SimpleList of | ||
| 9271 | # the current notebook tab | ||
| 9272 | # | ||
| 9273 | # Expected arguments | ||
| 9274 | # (none besides $self) | ||
| 9275 | # | ||
| 9276 | # Return values | ||
| 9277 | # An empty list on improper arguments | ||
| 9278 | # Otherwise, returns the list of selected line numbers | ||
| 9279 | |||
| 9280 | my ($self, $check) = @_; | ||
| 9281 | |||
| 9282 | # Local variables | ||
| 9283 | my ( | ||
| 9284 | $dataRef, | ||
| 9285 | @emptyList, @returnList, | ||
| 9286 | ); | ||
| 9287 | |||
| 9288 | # Check for improper arguments | ||
| 9289 | if (defined $check) { | ||
| 9290 | |||
| 9291 | $axmud::CLIENT->writeImproper($self->_objClass . '->notebookGetSelectedLines', @_); | ||
| 9292 | return @emptyList, | ||
| 9293 | } | ||
| 9294 | |||
| 9295 | $dataRef = $self->notebookGetData(); | ||
| 9296 | @returnList = $dataRef->get_selected_indices(); | ||
| 9297 | |||
| 9298 | return @returnList; | ||
| 9299 | } | ||
| 9300 | |||
| 9301 | sub notebookSetSelectedLines { | ||
| 9302 | |||
| 9303 | # Can be called by anything, but usually by $self->updateNotebook | ||
| 9304 | # Selects lines in the GA::Obj::SimpleList of the current notebook tab, as if the user had | ||
| 9305 | # clicked on them | ||
| 9306 | # | ||
| 9307 | # Expected arguments | ||
| 9308 | # @list - List of indices in the GA::Obj::SimpleList to select | ||
| 9309 | # | ||
| 9310 | # Return values | ||
| 9311 | # 1 | ||
| 9312 | |||
| 9313 | my ($self, @list) = @_; | ||
| 9314 | |||
| 9315 | # Local variables | ||
| 9316 | my $dataRef; | ||
| 9317 | |||
| 9318 | # (No improper arguments to check) | ||
| 9319 | |||
| 9320 | $dataRef = $self->notebookGetData(); | ||
| 9321 | foreach my $index (@list) { | ||
| 9322 | |||
| 9323 | $dataRef->select($index); | ||
| 9324 | } | ||
| 9325 | |||
| 9326 | return 1; | ||
| 9327 | } | ||
| 9328 | |||
| 9329 | sub getMnemonic { | ||
| 9330 | |||
| 9331 | # Called by $self->setTabList_prof and several other functions | ||
| 9332 | # Given the label of a tab - e.g. 'world' - create a label mnemonic, e.g. '_world' (which | ||
| 9333 | # the user can select with the ALT+W key combination) | ||
| 9334 | # The calling function supplies a hash of letters that have already been used for other | ||
| 9335 | # mnemonics, so that each label can be selected with a different key combination (for as | ||
| 9336 | # long as there are spare letters remaining) | ||
| 9337 | # | ||
| 9338 | # Expected arguments | ||
| 9339 | # $string - The string to process, e.g. 'world' | ||
| 9340 | # $hashRef - Reference to a hash of mnemonics already used, in the form | ||
| 9341 | # $hash{letter} = undef | ||
| 9342 | # | ||
| 9343 | # Return values | ||
| 9344 | # 'undef' on improper arguments | ||
| 9345 | # Otherwise, returns the modified string | ||
| 9346 | |||
| 9347 | my ($self, $string, $hashRef, $check) = @_; | ||
| 9348 | |||
| 9349 | # Check for improper arguments | ||
| 9350 | if (! defined $string || ! defined $hashRef || defined $check) { | ||
| 9351 | |||
| 9352 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getMnemonic', @_); | ||
| 9353 | } | ||
| 9354 | |||
| 9355 | if (! $string) { | ||
| 9356 | |||
| 9357 | # Can't process an empty string | ||
| 9358 | return $string; | ||
| 9359 | } | ||
| 9360 | |||
| 9361 | # Dereference the supplied hash (for convenience) | ||
| 9362 | |||
| 9363 | # Examine each letter of $string in turn, looking for one which hasn't already been used as | ||
| 9364 | # a mnemonic | ||
| 9365 | for (my $count = 0; $count < length($string); $count++) { | ||
| 9366 | |||
| 9367 | my $letter = lc(substr($string, $count, 1)); | ||
| 9368 | |||
| 9369 | if (! exists $$hashRef{$letter}) { | ||
| 9370 | |||
| 9371 | # Insert an underline at this location | ||
| 9372 | substr($string, $count, 0, '_'); | ||
| 9373 | # This mnemonic is no longer available | ||
| 9374 | $$hashRef{$letter} = undef; | ||
| 9375 | |||
| 9376 | return $string; | ||
| 9377 | } | ||
| 9378 | } | ||
| 9379 | |||
| 9380 | # Cannot add an underline to $string; all of its letters are already in use. Return the | ||
| 9381 | # unmodified string | ||
| 9382 | return $string | ||
| 9383 | } | ||
| 9384 | |||
| 9385 | # Treeview header responses - profiles | ||
| 9386 | |||
| 9387 | sub allProfHeader { | ||
| 9388 | |||
| 9389 | # Called by ->treeViewChanged when the user clicks on the 'All profiles' header in the | ||
| 9390 | # treeview | ||
| 9391 | # | ||
| 9392 | # Expected arguments | ||
| 9393 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9394 | # | ||
| 9395 | # Return values | ||
| 9396 | # 'undef' on improper arguments | ||
| 9397 | # 1 otherwise | ||
| 9398 | |||
| 9399 | my ($self, $item, $check) = @_; | ||
| 9400 | |||
| 9401 | # Local variables | ||
| 9402 | my ( | ||
| 9403 | $tabListRef, $shortTabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9404 | @shortTabList, | ||
| 9405 | %dataHash, | ||
| 9406 | ); | ||
| 9407 | |||
| 9408 | # Check for improper arguments | ||
| 9409 | if (! defined $item || defined $check) { | ||
| 9410 | |||
| 9411 | return $axmud::CLIENT->writeImproper($self->_objClass . '->allProfHeader', @_); | ||
| 9412 | } | ||
| 9413 | |||
| 9414 | # Prepare the list of tabs | ||
| 9415 | ($tabListRef, $shortTabListRef) = $self->setTabList_prof(); | ||
| 9416 | # Prepare the list of column headings | ||
| 9417 | $columnListRef = $self->setColumnList_prof(); | ||
| 9418 | # Prepare the list of buttons | ||
| 9419 | $buttonListRef = $self->setButtonList_prof(); | ||
| 9420 | |||
| 9421 | # Prepare the data to be displayed. Each item in @$shortTabListRef is a profile category, | ||
| 9422 | # e.g. 'world' or 'char' | ||
| 9423 | @shortTabList = @$shortTabListRef; | ||
| 9424 | foreach my $tab (@shortTabList) { | ||
| 9425 | |||
| 9426 | my (@profList, @sortedList, @dataList); | ||
| 9427 | |||
| 9428 | if ($tab eq 'world') { | ||
| 9429 | |||
| 9430 | # Add world profiles from the GA::Client's hash | ||
| 9431 | @profList = sort {lc($a->name) cmp lc($b->name)} | ||
| 9432 | ($axmud::CLIENT->ivValues('worldProfHash')); | ||
| 9433 | |||
| 9434 | foreach my $profObj (@profList) { | ||
| 9435 | |||
| 9436 | my ($flag, $listRef); | ||
| 9437 | |||
| 9438 | if ($profObj eq $self->session->currentWorld) { | ||
| 9439 | $flag = TRUE; | ||
| 9440 | } else { | ||
| 9441 | $flag = FALSE; | ||
| 9442 | } | ||
| 9443 | |||
| 9444 | $listRef = [$flag, $profObj->name, $profObj->category]; | ||
| 9445 | push (@dataList, $listRef); | ||
| 9446 | } | ||
| 9447 | |||
| 9448 | } else { | ||
| 9449 | |||
| 9450 | # Add non-world profiles from the current GA::Session | ||
| 9451 | foreach my $profObj ($self->session->ivValues('profHash')) { | ||
| 9452 | |||
| 9453 | if ($profObj->category eq $tab) { | ||
| 9454 | |||
| 9455 | push (@profList, $profObj); | ||
| 9456 | } | ||
| 9457 | } | ||
| 9458 | |||
| 9459 | @sortedList = sort {lc($a->name) cmp lc($b->name)} (@profList); | ||
| 9460 | foreach my $profObj (@sortedList) { | ||
| 9461 | |||
| 9462 | my ($flag, $listRef); | ||
| 9463 | |||
| 9464 | if ( | ||
| 9465 | $self->session->ivExists('currentProfHash', $tab) | ||
| 9466 | && $self->session->ivShow('currentProfHash', $tab) eq $profObj | ||
| 9467 | ) { | ||
| 9468 | $flag = TRUE; | ||
| 9469 | } else { | ||
| 9470 | $flag = FALSE; | ||
| 9471 | } | ||
| 9472 | |||
| 9473 | $listRef = [$flag, $profObj->name, $profObj->category]; | ||
| 9474 | push (@dataList, $listRef); | ||
| 9475 | } | ||
| 9476 | } | ||
| 9477 | |||
| 9478 | $dataHash{$tab} = \@dataList; | ||
| 9479 | } | ||
| 9480 | |||
| 9481 | $dataHashRef = \%dataHash; | ||
| 9482 | |||
| 9483 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 9484 | # equivalent to the edit button | ||
| 9485 | $self->ivPoke('notebookSelectRef', sub { | ||
| 9486 | |||
| 9487 | $self->buttonEdit_prof(); | ||
| 9488 | }); | ||
| 9489 | |||
| 9490 | # Display all of this in the notebook | ||
| 9491 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9492 | } | ||
| 9493 | |||
| 9494 | sub currentProfHeader { | ||
| 9495 | |||
| 9496 | # Called by ->treeViewChanged when the user clicks on the 'Current profiles' header in the | ||
| 9497 | # treeview | ||
| 9498 | # | ||
| 9499 | # Expected arguments | ||
| 9500 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9501 | # | ||
| 9502 | # Return values | ||
| 9503 | # 'undef' on improper arguments | ||
| 9504 | # 1 otherwise | ||
| 9505 | |||
| 9506 | my ($self, $item, $check) = @_; | ||
| 9507 | |||
| 9508 | # Local variables | ||
| 9509 | my ( | ||
| 9510 | $tabListRef, $shortTabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9511 | @shortTabList, | ||
| 9512 | %dataHash, | ||
| 9513 | ); | ||
| 9514 | |||
| 9515 | # Check for improper arguments | ||
| 9516 | if (! defined $item || defined $check) { | ||
| 9517 | |||
| 9518 | return $axmud::CLIENT->writeImproper($self->_objClass . '->currentProfHeader', @_); | ||
| 9519 | } | ||
| 9520 | |||
| 9521 | # Prepare the list of tabs | ||
| 9522 | ($tabListRef, $shortTabListRef) = $self->setTabList_prof(); | ||
| 9523 | # Prepare the list of column headings | ||
| 9524 | $columnListRef = $self->setColumnList_prof(); | ||
| 9525 | # Prepare the list of buttons | ||
| 9526 | $buttonListRef = $self->setButtonList_prof(); | ||
| 9527 | |||
| 9528 | # Prepare the data to be displayed. Each item in @$shortTabListRef is a profile category, | ||
| 9529 | # e.g. 'world' or 'char' | ||
| 9530 | @shortTabList = @$shortTabListRef; | ||
| 9531 | foreach my $tab (@shortTabList) { | ||
| 9532 | |||
| 9533 | my @dataList; | ||
| 9534 | |||
| 9535 | # Add all current profiles from the current GA::Session (there should only be one from | ||
| 9536 | # each category of profile, so no need to sort the list alphabetically) | ||
| 9537 | foreach my $profObj ($self->session->ivValues('currentProfHash')) { | ||
| 9538 | |||
| 9539 | my $listRef; | ||
| 9540 | |||
| 9541 | if ($profObj->category eq $tab) { | ||
| 9542 | |||
| 9543 | # The TRUE argument marks this as a current profile | ||
| 9544 | $listRef = [TRUE, $profObj->name, $profObj->category]; | ||
| 9545 | push (@dataList, $listRef); | ||
| 9546 | } | ||
| 9547 | } | ||
| 9548 | |||
| 9549 | $dataHash{$tab} = \@dataList; | ||
| 9550 | } | ||
| 9551 | |||
| 9552 | $dataHashRef = \%dataHash; | ||
| 9553 | |||
| 9554 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 9555 | # equivalent to the edit button | ||
| 9556 | $self->ivPoke('notebookSelectRef', sub { | ||
| 9557 | |||
| 9558 | $self->buttonEdit_prof(); | ||
| 9559 | }); | ||
| 9560 | |||
| 9561 | # Display all of this in the notebook | ||
| 9562 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9563 | } | ||
| 9564 | |||
| 9565 | sub templateHeader { | ||
| 9566 | |||
| 9567 | # Called by ->treeViewChanged when the user clicks on the 'Profile templates' header in the | ||
| 9568 | # treeview | ||
| 9569 | # | ||
| 9570 | # Expected arguments | ||
| 9571 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9572 | # | ||
| 9573 | # Return values | ||
| 9574 | # 'undef' on improper arguments | ||
| 9575 | # 1 otherwise | ||
| 9576 | |||
| 9577 | my ($self, $item, $check) = @_; | ||
| 9578 | |||
| 9579 | # Local variables | ||
| 9580 | my ( | ||
| 9581 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9582 | @objList, @dataList, | ||
| 9583 | %dataHash, | ||
| 9584 | ); | ||
| 9585 | |||
| 9586 | # Check for improper arguments | ||
| 9587 | if (! defined $item || defined $check) { | ||
| 9588 | |||
| 9589 | return $axmud::CLIENT->writeImproper($self->_objClass . '->templateHeader', @_); | ||
| 9590 | } | ||
| 9591 | |||
| 9592 | # Prepare the list of tabs | ||
| 9593 | $tabListRef = [ | ||
| 9594 | 'Profile templates', 'Profile _templates', | ||
| 9595 | ]; | ||
| 9596 | |||
| 9597 | # Prepare the list of column headings | ||
| 9598 | $columnListRef = [ | ||
| 9599 | 'Fixed' => 'bool', | ||
| 9600 | 'Template category' => 'text', | ||
| 9601 | ]; | ||
| 9602 | |||
| 9603 | # Prepare the list of buttons | ||
| 9604 | $buttonListRef = [ | ||
| 9605 | 'Add', 'Add a new template profile', 'buttonAdd_template', | ||
| 9606 | 'Edit', 'Edit the selected template profile', 'buttonEdit_template', | ||
| 9607 | 'Clone', 'Clone the selected template profile', 'buttonClone_template', | ||
| 9608 | 'Delete', 'Delete the selected template profile', 'buttonDelete_template', | ||
| 9609 | 'Dump', 'Display the list of template in the \'main\' window', 'buttonDump_template', | ||
| 9610 | ]; | ||
| 9611 | |||
| 9612 | # Prepare the data to be displayed (there is only one tab) | ||
| 9613 | @objList = sort {lc($a->category) cmp lc($b->category)} | ||
| 9614 | ($self->session->ivValues('templateHash')); | ||
| 9615 | OUTER: foreach my $templObj (@objList) { | ||
| 9616 | |||
| 9617 | my $listRef = [$templObj->constFixedFlag, $templObj->category]; | ||
| 9618 | |||
| 9619 | push (@dataList, $listRef); | ||
| 9620 | } | ||
| 9621 | |||
| 9622 | $dataHash{'Profile templates'} = \@dataList; | ||
| 9623 | $dataHashRef = \%dataHash; | ||
| 9624 | |||
| 9625 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 9626 | # equivalent to the edit button | ||
| 9627 | $self->ivPoke('notebookSelectRef', sub { | ||
| 9628 | |||
| 9629 | $self->buttonEdit_template(); | ||
| 9630 | }); | ||
| 9631 | |||
| 9632 | # Display all of this in the notebook | ||
| 9633 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9634 | } | ||
| 9635 | |||
| 9636 | sub profPriorityHeader { | ||
| 9637 | |||
| 9638 | # Called by ->treeViewChanged when the user clicks on the 'Profile priority' header in the | ||
| 9639 | # treeview | ||
| 9640 | # | ||
| 9641 | # Expected arguments | ||
| 9642 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9643 | # | ||
| 9644 | # Return values | ||
| 9645 | # 'undef' on improper arguments | ||
| 9646 | # 1 otherwise | ||
| 9647 | |||
| 9648 | my ($self, $item, $check) = @_; | ||
| 9649 | |||
| 9650 | # Local variables | ||
| 9651 | my ( | ||
| 9652 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, $count, | ||
| 9653 | @dataList, @otherList, | ||
| 9654 | %dataHash, | ||
| 9655 | ); | ||
| 9656 | |||
| 9657 | # Check for improper arguments | ||
| 9658 | if (! defined $item || defined $check) { | ||
| 9659 | |||
| 9660 | return $axmud::CLIENT->writeImproper($self->_objClass . '->profPriorityHeader', @_); | ||
| 9661 | } | ||
| 9662 | |||
| 9663 | # Prepare the list of tabs | ||
| 9664 | $tabListRef = [ | ||
| 9665 | 'Profile priority list', 'Profile _priority list', | ||
| 9666 | ]; | ||
| 9667 | |||
| 9668 | # Prepare the list of column headings | ||
| 9669 | $columnListRef = [ | ||
| 9670 | 'Priority' => 'text', | ||
| 9671 | 'Category' => 'text', | ||
| 9672 | ]; | ||
| 9673 | |||
| 9674 | # Prepare the list of buttons | ||
| 9675 | $buttonListRef = [ | ||
| 9676 | 'Move to top', 'Profile category has the highest priority', | ||
| 9677 | 'buttonMoveTop_profPriority', | ||
| 9678 | 'Move up', 'Profile category has a higher priority', | ||
| 9679 | 'buttonMoveUp_profPriority', | ||
| 9680 | 'Move down', 'Profile category has a lower priority', | ||
| 9681 | 'buttonMoveDown_profPriority', | ||
| 9682 | 'Give priority', 'Add the selected category to the priority list', | ||
| 9683 | 'buttonGivePriority_profPriority', | ||
| 9684 | 'Lose priority', 'Remove the selected category from the priority list', | ||
| 9685 | 'buttonLosePriority_profPriority', | ||
| 9686 | 'Reset list', 'Use the default priority list', | ||
| 9687 | 'buttonResetList_profPriority', | ||
| 9688 | ]; | ||
| 9689 | |||
| 9690 | # Compile the data to display | ||
| 9691 | $dataHashRef = $self->compileList_profPriority(); | ||
| 9692 | |||
| 9693 | # (Nothing happens if the user double-clicks on a row) | ||
| 9694 | |||
| 9695 | # Display all of this in the notebook | ||
| 9696 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9697 | } | ||
| 9698 | |||
| 9699 | # Treeview header responses - dictionaries | ||
| 9700 | |||
| 9701 | sub allDictHeader { | ||
| 9702 | |||
| 9703 | # Called by ->treeViewChanged when the user clicks on the 'All dictionaries' header in the | ||
| 9704 | # treeview | ||
| 9705 | # | ||
| 9706 | # Expected arguments | ||
| 9707 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9708 | # | ||
| 9709 | # Return values | ||
| 9710 | # 'undef' on improper arguments | ||
| 9711 | # 1 otherwise | ||
| 9712 | |||
| 9713 | my ($self, $item, $check) = @_; | ||
| 9714 | |||
| 9715 | # Local variables | ||
| 9716 | my ( | ||
| 9717 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9718 | @objList, @dataList, | ||
| 9719 | %dataHash, | ||
| 9720 | ); | ||
| 9721 | |||
| 9722 | # Check for improper arguments | ||
| 9723 | if (! defined $item || defined $check) { | ||
| 9724 | |||
| 9725 | return $axmud::CLIENT->writeImproper($self->_objClass . '->allDictHeader', @_); | ||
| 9726 | } | ||
| 9727 | |||
| 9728 | # Prepare the list of tabs | ||
| 9729 | $tabListRef = [ | ||
| 9730 | 'Dictionary' => '_Dictionary', | ||
| 9731 | ]; | ||
| 9732 | |||
| 9733 | # Prepare the list of column headings | ||
| 9734 | $columnListRef = [ | ||
| 9735 | 'Current' => 'bool', | ||
| 9736 | 'Name' => 'text', | ||
| 9737 | 'Language' => 'text', | ||
| 9738 | ]; | ||
| 9739 | |||
| 9740 | # Prepare the list of buttons | ||
| 9741 | $buttonListRef = [ | ||
| 9742 | 'Add', 'Add a new dictionary', 'buttonAdd_dict', | ||
| 9743 | 'Edit', 'Edit the selected dictionary', 'buttonEdit_dict', | ||
| 9744 | 'Set current', 'Set the current dictionary', 'buttonSet_dict', | ||
| 9745 | 'Clone', 'Clone the selected dictionary', 'buttonClone_dict', | ||
| 9746 | 'Delete', 'Delete the selected dictinoary', 'buttonDelete_dict', | ||
| 9747 | 'Dump', 'Display a list of dictionaries in the \'main\' window', 'buttonDump_dict', | ||
| 9748 | ]; | ||
| 9749 | |||
| 9750 | # Prepare the data to be displayed (there is only one tab) | ||
| 9751 | @objList = sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('dictHash')); | ||
| 9752 | OUTER: foreach my $dictObj (@objList) { | ||
| 9753 | |||
| 9754 | my ($listRef, $flag); | ||
| 9755 | |||
| 9756 | if ($dictObj eq $self->session->currentDict) { | ||
| 9757 | $flag = TRUE; | ||
| 9758 | } else { | ||
| 9759 | $flag = FALSE; | ||
| 9760 | } | ||
| 9761 | |||
| 9762 | $listRef = [$flag, $dictObj->name, $dictObj->language]; | ||
| 9763 | push (@dataList, $listRef); | ||
| 9764 | } | ||
| 9765 | |||
| 9766 | $dataHash{'Dictionary'} = \@dataList; | ||
| 9767 | $dataHashRef = \%dataHash; | ||
| 9768 | |||
| 9769 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 9770 | # equivalent to the edit button | ||
| 9771 | $self->ivPoke('notebookSelectRef', sub { | ||
| 9772 | |||
| 9773 | $self->buttonEdit_dict(); | ||
| 9774 | }); | ||
| 9775 | |||
| 9776 | # Display all of this in the notebook | ||
| 9777 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9778 | } | ||
| 9779 | |||
| 9780 | sub currentDictHeader { | ||
| 9781 | |||
| 9782 | # Called by ->treeViewChanged when the user clicks on the 'Current dictionaries' header in | ||
| 9783 | # the treeview | ||
| 9784 | # | ||
| 9785 | # Expected arguments | ||
| 9786 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9787 | # | ||
| 9788 | # Return values | ||
| 9789 | # 'undef' on improper arguments | ||
| 9790 | # 1 otherwise | ||
| 9791 | |||
| 9792 | my ($self, $item, $check) = @_; | ||
| 9793 | |||
| 9794 | # Local variables | ||
| 9795 | my ( | ||
| 9796 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9797 | @dataList, | ||
| 9798 | %dataHash, | ||
| 9799 | ); | ||
| 9800 | |||
| 9801 | # Check for improper arguments | ||
| 9802 | if (! defined $item || defined $check) { | ||
| 9803 | |||
| 9804 | return $axmud::CLIENT->writeImproper($self->_objClass . '->currentDictHeader', @_); | ||
| 9805 | } | ||
| 9806 | |||
| 9807 | # Prepare the list of tabs | ||
| 9808 | $tabListRef = [ | ||
| 9809 | 'Dictionary' => '_Dictionary', | ||
| 9810 | ]; | ||
| 9811 | |||
| 9812 | # Prepare the list of column headings | ||
| 9813 | $columnListRef = [ | ||
| 9814 | 'Current' => 'bool', | ||
| 9815 | 'Name' => 'text', | ||
| 9816 | 'Language' => 'text', | ||
| 9817 | ]; | ||
| 9818 | |||
| 9819 | # Prepare the list of buttons | ||
| 9820 | $buttonListRef = [ | ||
| 9821 | 'Add', 'Add a new dictionary', 'buttonAdd_dict', | ||
| 9822 | 'Edit', 'Edit the selected dictionary', 'buttonEdit_dict', | ||
| 9823 | 'Set current', 'Set the current dictionary', 'buttonSet_dict', | ||
| 9824 | 'Clone', 'Clone the selected dictionary', 'buttonClone_dict', | ||
| 9825 | 'Delete', 'Delete the selected dictinoary', 'buttonDelete_dict', | ||
| 9826 | 'Dump', 'Display a list of dictionaries in the \'main\' window', 'buttonDump_dict', | ||
| 9827 | |||
| 9828 | ]; | ||
| 9829 | |||
| 9830 | # Prepare the data to be displayed (there is only one tab, and there should be only one | ||
| 9831 | # dictionary to display) | ||
| 9832 | OUTER: foreach my $dictObj ($axmud::CLIENT->ivValues('dictHash')) { | ||
| 9833 | |||
| 9834 | my $listRef; | ||
| 9835 | |||
| 9836 | if ($dictObj eq $self->session->currentDict) { | ||
| 9837 | |||
| 9838 | $listRef = [TRUE, $dictObj->name, $dictObj->language]; | ||
| 9839 | push (@dataList, $listRef); | ||
| 9840 | } | ||
| 9841 | } | ||
| 9842 | |||
| 9843 | $dataHash{'Dictionary'} = \@dataList; | ||
| 9844 | $dataHashRef = \%dataHash; | ||
| 9845 | |||
| 9846 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 9847 | # equivalent to the edit button | ||
| 9848 | $self->ivPoke('notebookSelectRef', sub { | ||
| 9849 | |||
| 9850 | $self->buttonEdit_dict(); | ||
| 9851 | }); | ||
| 9852 | |||
| 9853 | # Display all of this in the notebook | ||
| 9854 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9855 | } | ||
| 9856 | |||
| 9857 | # Treeview header responses - tasks | ||
| 9858 | |||
| 9859 | sub availableTaskHeader { | ||
| 9860 | |||
| 9861 | # Called by ->treeViewChanged when the user clicks on the 'Available tasks' header in the | ||
| 9862 | # treeview | ||
| 9863 | # | ||
| 9864 | # Expected arguments | ||
| 9865 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 9866 | # | ||
| 9867 | # Return values | ||
| 9868 | # 'undef' on improper arguments | ||
| 9869 | # 1 otherwise | ||
| 9870 | |||
| 9871 | my ($self, $item, $check) = @_; | ||
| 9872 | |||
| 9873 | # Local variables | ||
| 9874 | my ( | ||
| 9875 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9876 | @objList, @dataList, | ||
| 9877 | %dataHash, | ||
| 9878 | ); | ||
| 9879 | |||
| 9880 | # Check for improper arguments | ||
| 9881 | if (! defined $item || defined $check) { | ||
| 9882 | |||
| 9883 | return $axmud::CLIENT->writeImproper($self->_objClass . '->availableTaskHeader', @_); | ||
| 9884 | } | ||
| 9885 | |||
| 9886 | # Prepare the list of tabs | ||
| 9887 | $tabListRef = [ | ||
| 9888 | 'Available tasks' => '_Available tasks', | ||
| 9889 | ]; | ||
| 9890 | |||
| 9891 | # Prepare the list of column headings | ||
| 9892 | $columnListRef = [ | ||
| 9893 | 'Built-in' => 'bool', | ||
| 9894 | 'Task name' => 'text', | ||
| 9895 | ]; | ||
| 9896 | |||
| 9897 | # Prepare the list of buttons | ||
| 9898 | $buttonListRef = [ | ||
| 9899 | 'Start', 'Start a new task with default settings', 'buttonStart_availableTask', | ||
| 9900 | 'Start options', 'Start a new task with non-standard settings', | ||
| 9901 | 'buttonStartOptions_availableTask', | ||
| 9902 | 'Add initial', 'Add a new task to the global initial tasklist', | ||
| 9903 | 'buttonAddInitial_availableTask', | ||
| 9904 | 'Add custom', 'Add a new task to the custom tasklist', | ||
| 9905 | 'buttonAddCustom_availableTask', | ||
| 9906 | 'Halt', 'Halt all currently-running copies of the selected task', | ||
| 9907 | 'buttonHalt_availableTask', | ||
| 9908 | 'Kill', 'Kill all currently-running copies of the selected task', | ||
| 9909 | 'buttonKill_availableTask', | ||
| 9910 | 'Pause', 'Pauses all currently-running copies of the selected task', | ||
| 9911 | 'buttonPause_availableTask', | ||
| 9912 | 'Safe resume', 'Resume all tasks paused with the pause button', | ||
| 9913 | 'buttonSafeResume_task', | ||
| 9914 | 'Reset', 'Reset all currently-running copies of the selected task', | ||
| 9915 | 'buttonReset_availableTask', | ||
| 9916 | 'Help', 'Shows help for the selected task', 'buttonHelp_availableTask', | ||
| 9917 | ]; | ||
| 9918 | |||
| 9919 | # Prepare the data to be displayed (there is only one tab) | ||
| 9920 | @objList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskPackageHash')); | ||
| 9921 | OUTER: foreach my $packageName (@objList) { | ||
| 9922 | |||
| 9923 | my ($listRef, $flag); | ||
| 9924 | |||
| 9925 | if ($axmud::CLIENT->ivExists('constTaskPackageHash', $packageName)) { | ||
| 9926 | $flag = TRUE; | ||
| 9927 | } else { | ||
| 9928 | $flag = FALSE; | ||
| 9929 | } | ||
| 9930 | |||
| 9931 | $listRef = [$flag, $packageName]; | ||
| 9932 | push (@dataList, $listRef); | ||
| 9933 | |||
| 9934 | } | ||
| 9935 | |||
| 9936 | $dataHash{'Available tasks'} = \@dataList; | ||
| 9937 | $dataHashRef = \%dataHash; | ||
| 9938 | |||
| 9939 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 9940 | # equivalent to the 'start' button | ||
| 9941 | $self->ivPoke('notebookSelectRef', sub { | ||
| 9942 | |||
| 9943 | $self->buttonStart_availableTask(); | ||
| 9944 | }); | ||
| 9945 | |||
| 9946 | # Display all of this in the notebook | ||
| 9947 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 9948 | } | ||
| 9949 | |||
| 9950 | sub currentTaskHeader { | ||
| 9951 | |||
| 9952 | # Called by ->treeViewChanged when the user clicks on the 'Current tasklist' header in the | ||
| 9953 | # treeview | ||
| 9954 | # | ||
| 9955 | # Expected arguments | ||
| 9956 | # (none besides $self) | ||
| 9957 | # | ||
| 9958 | # Optional arguments | ||
| 9959 | # $item - The treeview item that was clicked (i.e. the text it contains). Not specified | ||
| 9960 | # when called by GA::Session->taskLoop | ||
| 9961 | # | ||
| 9962 | # Return values | ||
| 9963 | # 'undef' on improper arguments | ||
| 9964 | # 1 otherwise | ||
| 9965 | |||
| 9966 | my ($self, $item, $check) = @_; | ||
| 9967 | |||
| 9968 | # Local variables | ||
| 9969 | my ( | ||
| 9970 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 9971 | @objList, @dataList, | ||
| 9972 | %dataHash, | ||
| 9973 | ); | ||
| 9974 | |||
| 9975 | # Check for improper arguments | ||
| 9976 | if (defined $check) { | ||
| 9977 | |||
| 9978 | return $axmud::CLIENT->writeImproper($self->_objClass . '->currentTaskHeader', @_); | ||
| 9979 | } | ||
| 9980 | |||
| 9981 | # Prepare the list of tabs | ||
| 9982 | $tabListRef = [ | ||
| 9983 | 'Current tasklist' => '_Current tasklist', | ||
| 9984 | ]; | ||
| 9985 | |||
| 9986 | # Prepare the list of column headings | ||
| 9987 | $columnListRef = [ | ||
| 9988 | 'Name' => 'text', # ->name | ||
| 9989 | 'Type' => 'text', # ->category | ||
| 9990 | 'Jealous' => 'bool', # ->jealousyFlag | ||
| 9991 | 'Stage' => 'text', # ->stage | ||
| 9992 | 'Status' => 'text', # ->status | ||
| 9993 | ]; | ||
| 9994 | |||
| 9995 | # Prepare the list of buttons | ||
| 9996 | $buttonListRef = [ | ||
| 9997 | 'Edit', 'Edit a task\'s settings and parameters', 'buttonEdit_task', | ||
| 9998 | 'Halt', 'Halt a task (gracefully)', 'buttonHalt_task', | ||
| 9999 | 'Halt all', 'Halt all tasks (gracefully)', 'buttonHaltAll_task', | ||
| 10000 | 'Kill', ' Kill (stop) a task immediately (not recommended)', 'buttonKill_task', | ||
| 10001 | 'Kill all', 'Kill (stop) all tasks immediately (not recommended)', 'buttonKillAll_task', | ||
| 10002 | 'Pause', 'Pause a task', 'buttonPause_task', | ||
| 10003 | 'Pause all', 'Pause all tasks', 'buttonPauseAll_task', | ||
| 10004 | 'Safe resume', 'Resume all tasks paused with the pause button', 'buttonSafeResume_task', | ||
| 10005 | 'Reset', 'Reset a task', 'buttonReset_task', | ||
| 10006 | 'Reset all', 'Reset all tasks', 'buttonResetAll_task', | ||
| 10007 | '(Un)freeze all', 'Freeze (or unfreeze) all running tasks', 'buttonFreezeAll_task', | ||
| 10008 | 'Dump', 'Dump the list of running tasks to the \'main\' window', 'buttonDump_task', | ||
| 10009 | ]; | ||
| 10010 | |||
| 10011 | # Prepare the data to be displayed (there is only one tab) | ||
| 10012 | @objList = sort {lc($a->uniqueName) cmp lc($b->uniqueName)} | ||
| 10013 | ($self->session->ivValues('currentTaskHash')); | ||
| 10014 | |||
| 10015 | OUTER: foreach my $taskObj (@objList) { | ||
| 10016 | |||
| 10017 | my $listRef = [ | ||
| 10018 | $taskObj->uniqueName, $taskObj->category, $taskObj->jealousyFlag, | ||
| 10019 | $taskObj->stage, $taskObj->status, | ||
| 10020 | ]; | ||
| 10021 | |||
| 10022 | push (@dataList, $listRef); | ||
| 10023 | |||
| 10024 | } | ||
| 10025 | |||
| 10026 | $dataHash{'Current tasklist'} = \@dataList; | ||
| 10027 | $dataHashRef = \%dataHash; | ||
| 10028 | |||
| 10029 | # (Nothing happens when user double-clicks on line) | ||
| 10030 | |||
| 10031 | # Display all of this in the notebook | ||
| 10032 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10033 | } | ||
| 10034 | |||
| 10035 | sub initialTaskHeader { | ||
| 10036 | |||
| 10037 | # Called by ->treeViewChanged when the user clicks on the 'Global initial tasklist' header | ||
| 10038 | # in the treeview | ||
| 10039 | # | ||
| 10040 | # Expected arguments | ||
| 10041 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10042 | # | ||
| 10043 | # Return values | ||
| 10044 | # 'undef' on improper arguments | ||
| 10045 | # 1 otherwise | ||
| 10046 | |||
| 10047 | my ($self, $item, $check) = @_; | ||
| 10048 | |||
| 10049 | # Local variables | ||
| 10050 | my ( | ||
| 10051 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10052 | @dataList, | ||
| 10053 | %dataHash, | ||
| 10054 | ); | ||
| 10055 | |||
| 10056 | # Check for improper arguments | ||
| 10057 | if (! defined $item || defined $check) { | ||
| 10058 | |||
| 10059 | return $axmud::CLIENT->writeImproper($self->_objClass . '->initialTaskHeader', @_); | ||
| 10060 | } | ||
| 10061 | |||
| 10062 | # Prepare the list of tabs | ||
| 10063 | $tabListRef = [ | ||
| 10064 | 'Global initial tasklist' => '_Global initial tasklist', | ||
| 10065 | ]; | ||
| 10066 | |||
| 10067 | # Prepare the list of column headings | ||
| 10068 | $columnListRef = [ | ||
| 10069 | 'Name' => 'text', # ->uniqueName | ||
| 10070 | 'Type' => 'text', # ->category | ||
| 10071 | 'Jealous' => 'bool', # ->jealousyFlag | ||
| 10072 | 'Stage' => 'text', # ->stage | ||
| 10073 | 'Status' => 'text', # ->status | ||
| 10074 | ]; | ||
| 10075 | |||
| 10076 | # Prepare the list of buttons | ||
| 10077 | $buttonListRef = [ | ||
| 10078 | 'Edit', 'Edit the selected task', 'buttonEdit_initialTask', | ||
| 10079 | 'Move up', 'Move the selected task up', 'buttonMoveUp_initialTask', | ||
| 10080 | 'Move down', 'Move the selected task down', 'buttonMoveDown_initialTask', | ||
| 10081 | 'Delete', 'Delete a task from the global initial tasklist', 'buttonDelete_initialTask', | ||
| 10082 | 'Delete all', 'Delete all tasks from the global initial tasklist', | ||
| 10083 | 'buttonDeleteAll_initialTask', | ||
| 10084 | 'Dump', 'Dump the list of initial tasks to the \'main\' window', | ||
| 10085 | 'buttonDump_initialTask', | ||
| 10086 | ]; | ||
| 10087 | |||
| 10088 | # Prepare the data to be displayed (there is only one tab) | ||
| 10089 | OUTER: foreach my $taskName ($axmud::CLIENT->initTaskOrderList) { | ||
| 10090 | |||
| 10091 | my ($taskObj, $listRef); | ||
| 10092 | |||
| 10093 | $taskObj = $axmud::CLIENT->ivShow('initTaskHash', $taskName); | ||
| 10094 | $listRef = [ | ||
| 10095 | $taskObj->uniqueName, $taskObj->category, $taskObj->jealousyFlag, | ||
| 10096 | $taskObj->stage, $taskObj->status, | ||
| 10097 | ]; | ||
| 10098 | |||
| 10099 | push (@dataList, $listRef); | ||
| 10100 | |||
| 10101 | } | ||
| 10102 | |||
| 10103 | $dataHash{'Global initial tasklist'} = \@dataList; | ||
| 10104 | $dataHashRef = \%dataHash; | ||
| 10105 | |||
| 10106 | # (Nothing happens when user double-clicks on line) | ||
| 10107 | |||
| 10108 | # Display all of this in the notebook | ||
| 10109 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10110 | } | ||
| 10111 | |||
| 10112 | sub customTaskHeader { | ||
| 10113 | |||
| 10114 | # Called by ->treeViewChanged when the user clicks on the 'Custom tasklist' header in the | ||
| 10115 | # treeview | ||
| 10116 | # | ||
| 10117 | # Expected arguments | ||
| 10118 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10119 | # | ||
| 10120 | # Return values | ||
| 10121 | # 'undef' on improper arguments | ||
| 10122 | # 1 otherwise | ||
| 10123 | |||
| 10124 | my ($self, $item, $check) = @_; | ||
| 10125 | |||
| 10126 | # Local variables | ||
| 10127 | my ( | ||
| 10128 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10129 | @labelList, @dataList, | ||
| 10130 | %dataHash, | ||
| 10131 | ); | ||
| 10132 | |||
| 10133 | # Check for improper arguments | ||
| 10134 | if (! defined $item || defined $check) { | ||
| 10135 | |||
| 10136 | return $axmud::CLIENT->writeImproper($self->_objClass . '->customTaskHeader', @_); | ||
| 10137 | } | ||
| 10138 | |||
| 10139 | # Prepare the list of tabs | ||
| 10140 | $tabListRef = [ | ||
| 10141 | 'Custom tasklist' => '_Custom tasklist', | ||
| 10142 | ]; | ||
| 10143 | |||
| 10144 | # Prepare the list of column headings | ||
| 10145 | $columnListRef = [ | ||
| 10146 | 'Name' => 'text', # key in GA::Client->customTaskHash | ||
| 10147 | 'Task' => 'text', # ->name | ||
| 10148 | 'Type' => 'text', # ->category | ||
| 10149 | 'Jealous' => 'bool', # ->jealousyFlag | ||
| 10150 | 'Stage' => 'text', # ->stage | ||
| 10151 | 'Status' => 'text', # ->status | ||
| 10152 | ]; | ||
| 10153 | |||
| 10154 | # Prepare the list of buttons | ||
| 10155 | $buttonListRef = [ | ||
| 10156 | 'Start', 'Start the selected custom task', 'buttonStart_customTask', | ||
| 10157 | 'Edit', 'Edit the selected task', 'buttonEdit_customTask', | ||
| 10158 | 'Delete', 'Delete a task from the global initial tasklist', 'buttonDelete_customTask', | ||
| 10159 | 'Delete all', 'Delete all tasks from the global initial tasklist', | ||
| 10160 | 'buttonDeleteAll_customTask', | ||
| 10161 | 'Dump', 'Dump the list of custom tasks to the \'main\' window', | ||
| 10162 | 'buttonDump_customTask', | ||
| 10163 | ]; | ||
| 10164 | |||
| 10165 | # Prepare the data to be displayed (there is only one tab) | ||
| 10166 | @labelList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('customTaskHash')); | ||
| 10167 | OUTER: foreach my $label (@labelList) { | ||
| 10168 | |||
| 10169 | my ($taskObj, $listRef); | ||
| 10170 | |||
| 10171 | $taskObj = $axmud::CLIENT->ivShow('customTaskHash', $label); | ||
| 10172 | $listRef = [ | ||
| 10173 | $label, $taskObj->name, $taskObj->category, | ||
| 10174 | $taskObj->jealousyFlag, $taskObj->stage, $taskObj->status, | ||
| 10175 | ]; | ||
| 10176 | |||
| 10177 | push (@dataList, $listRef); | ||
| 10178 | |||
| 10179 | } | ||
| 10180 | |||
| 10181 | $dataHash{'Custom tasklist'} = \@dataList; | ||
| 10182 | $dataHashRef = \%dataHash; | ||
| 10183 | |||
| 10184 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10185 | # equivalent to the 'start' button | ||
| 10186 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10187 | |||
| 10188 | $self->buttonStart_customTask(); | ||
| 10189 | }); | ||
| 10190 | |||
| 10191 | # Display all of this in the notebook | ||
| 10192 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10193 | } | ||
| 10194 | |||
| 10195 | sub taskPackageHeader { | ||
| 10196 | |||
| 10197 | # Called by ->treeViewChanged when the user clicks on the 'Task package names' header in the | ||
| 10198 | # treeview | ||
| 10199 | # | ||
| 10200 | # Expected arguments | ||
| 10201 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10202 | # | ||
| 10203 | # Return values | ||
| 10204 | # 'undef' on improper arguments | ||
| 10205 | # 1 otherwise | ||
| 10206 | |||
| 10207 | my ($self, $item, $check) = @_; | ||
| 10208 | |||
| 10209 | # Local variables | ||
| 10210 | my ( | ||
| 10211 | $tabListRef, $shortTabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10212 | @list, @dataList, | ||
| 10213 | %dataHash, | ||
| 10214 | ); | ||
| 10215 | |||
| 10216 | # Check for improper arguments | ||
| 10217 | if (! defined $item || defined $check) { | ||
| 10218 | |||
| 10219 | return $axmud::CLIENT->writeImproper($self->_objClass . '->taskPackageHeader', @_); | ||
| 10220 | } | ||
| 10221 | |||
| 10222 | # Prepare the list of tabs | ||
| 10223 | $tabListRef = [ | ||
| 10224 | 'Task package names' => 'Task _package names', | ||
| 10225 | ]; | ||
| 10226 | |||
| 10227 | # Prepare the list of column headings | ||
| 10228 | $columnListRef = [ | ||
| 10229 | 'Built-in' => 'bool', | ||
| 10230 | 'Standard task name' => 'text', | ||
| 10231 | 'Package name' => 'text', | ||
| 10232 | ]; | ||
| 10233 | |||
| 10234 | # Prepare the list of buttons | ||
| 10235 | $buttonListRef = [ | ||
| 10236 | 'Add', 'Add a new task package name', 'buttonAdd_taskPackage', | ||
| 10237 | 'Edit', 'Edit a new task package name', 'buttonEdit_taskPackage', | ||
| 10238 | 'Delete', 'Delete an existing task package name', 'buttonDelete_taskPackage', | ||
| 10239 | 'Reset', 'Reset all task package names to defaults', 'buttonReset_taskPackage', | ||
| 10240 | 'Reset All', 'Reset all task package names to defaults', 'buttonResetAll_taskPackage', | ||
| 10241 | 'Dump', 'Dump the list of task package names to the \'main\' window', | ||
| 10242 | 'buttonDump_taskPackage', | ||
| 10243 | ]; | ||
| 10244 | |||
| 10245 | # Prepare the data to be displayed (there is only one tab) | ||
| 10246 | @list = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskPackageHash')); | ||
| 10247 | foreach my $standardName (@list) { | ||
| 10248 | |||
| 10249 | my ($flag, $listRef); | ||
| 10250 | |||
| 10251 | if ($axmud::CLIENT->ivExists('constTaskPackageHash', $standardName)) { | ||
| 10252 | $flag = TRUE; | ||
| 10253 | } else { | ||
| 10254 | $flag = FALSE; | ||
| 10255 | } | ||
| 10256 | |||
| 10257 | $listRef = [ | ||
| 10258 | $flag, | ||
| 10259 | $standardName, | ||
| 10260 | $axmud::CLIENT->ivShow('taskPackageHash', $standardName), | ||
| 10261 | ]; | ||
| 10262 | push (@dataList, $listRef); | ||
| 10263 | } | ||
| 10264 | |||
| 10265 | $dataHash{'Task package names'} = \@dataList; | ||
| 10266 | $dataHashRef = \%dataHash; | ||
| 10267 | |||
| 10268 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10269 | # equivalent to the edit button | ||
| 10270 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10271 | |||
| 10272 | $self->buttonEdit_taskPackage(); | ||
| 10273 | }); | ||
| 10274 | |||
| 10275 | # Display all of this in the notebook | ||
| 10276 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10277 | } | ||
| 10278 | |||
| 10279 | sub taskLabelHeader { | ||
| 10280 | |||
| 10281 | # Called by ->treeViewChanged when the user clicks on the 'Task labels' header in the | ||
| 10282 | # treeview | ||
| 10283 | # | ||
| 10284 | # Expected arguments | ||
| 10285 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10286 | # | ||
| 10287 | # Return values | ||
| 10288 | # 'undef' on improper arguments | ||
| 10289 | # 1 otherwise | ||
| 10290 | |||
| 10291 | my ($self, $item, $check) = @_; | ||
| 10292 | |||
| 10293 | # Local variables | ||
| 10294 | my ( | ||
| 10295 | $tabListRef, $shortTabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10296 | @list, @dataList, | ||
| 10297 | %dataHash, | ||
| 10298 | ); | ||
| 10299 | |||
| 10300 | # Check for improper arguments | ||
| 10301 | if (! defined $item || defined $check) { | ||
| 10302 | |||
| 10303 | return $axmud::CLIENT->writeImproper($self->_objClass . '->taskLabelHeader', @_); | ||
| 10304 | } | ||
| 10305 | |||
| 10306 | # Prepare the list of tabs | ||
| 10307 | $tabListRef = [ | ||
| 10308 | 'Task labels' => 'Task _labels', | ||
| 10309 | ]; | ||
| 10310 | |||
| 10311 | # Prepare the list of column headings | ||
| 10312 | $columnListRef = [ | ||
| 10313 | 'Built-in' => 'bool', | ||
| 10314 | 'Label' => 'text', | ||
| 10315 | 'Standard task name' => 'text', | ||
| 10316 | ]; | ||
| 10317 | |||
| 10318 | # Prepare the list of buttons | ||
| 10319 | $buttonListRef = [ | ||
| 10320 | 'Add', 'Add a new task label', 'buttonAdd_taskLabel', | ||
| 10321 | 'Delete', 'Delete an existing task label', 'buttonDelete_taskLabel', | ||
| 10322 | 'Empty labels', 'Empties all labels attached to a particular task', | ||
| 10323 | 'buttonEmpty_taskLabel', | ||
| 10324 | 'Reset', 'Reset all task labels to defaults', 'buttonReset_taskLabel', | ||
| 10325 | 'Reset All', 'Resets all task labels to defaults', 'buttonResetAll_taskLabel', | ||
| 10326 | 'Dump', 'Dumps the list of task labels to the \'main\' window', 'buttonDump_taskLabel', | ||
| 10327 | ]; | ||
| 10328 | |||
| 10329 | # Prepare the data to be displayed (there is only one tab) | ||
| 10330 | @list = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskLabelHash')); | ||
| 10331 | foreach my $label (@list) { | ||
| 10332 | |||
| 10333 | my ($flag, $listRef); | ||
| 10334 | |||
| 10335 | if ($axmud::CLIENT->ivExists('constTaskLabelHash', $label)) { | ||
| 10336 | $flag = TRUE; | ||
| 10337 | } else { | ||
| 10338 | $flag = FALSE, | ||
| 10339 | } | ||
| 10340 | |||
| 10341 | $listRef = [ | ||
| 10342 | $flag, | ||
| 10343 | $label, | ||
| 10344 | $axmud::CLIENT->ivShow('taskLabelHash', $label), | ||
| 10345 | ]; | ||
| 10346 | |||
| 10347 | push (@dataList, $listRef); | ||
| 10348 | } | ||
| 10349 | |||
| 10350 | $dataHash{'Task labels'} = \@dataList; | ||
| 10351 | $dataHashRef = \%dataHash; | ||
| 10352 | |||
| 10353 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10354 | # equivalent to the edit button | ||
| 10355 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10356 | |||
| 10357 | $self->buttonEdit_taskLabel(); | ||
| 10358 | }); | ||
| 10359 | |||
| 10360 | # Display all of this in the notebook | ||
| 10361 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10362 | } | ||
| 10363 | |||
| 10364 | # Treeview header responses - cages | ||
| 10365 | |||
| 10366 | sub allCageHeader { | ||
| 10367 | |||
| 10368 | # Called by ->treeViewChanged when the user clicks on the 'All cages' header in the treeview | ||
| 10369 | # | ||
| 10370 | # Expected arguments | ||
| 10371 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10372 | # | ||
| 10373 | # Return values | ||
| 10374 | # 'undef' on improper arguments | ||
| 10375 | # 1 otherwise | ||
| 10376 | |||
| 10377 | my ($self, $item, $check) = @_; | ||
| 10378 | |||
| 10379 | # Local variables | ||
| 10380 | my ( | ||
| 10381 | $tabListRef, $shortTabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10382 | @shortTabList, | ||
| 10383 | %dataHash, | ||
| 10384 | ); | ||
| 10385 | |||
| 10386 | # Check for improper arguments | ||
| 10387 | if (! defined $item || defined $check) { | ||
| 10388 | |||
| 10389 | return $axmud::CLIENT->writeImproper($self->_objClass . '->allCageHeader', @_); | ||
| 10390 | } | ||
| 10391 | |||
| 10392 | # Prepare the list of tabs | ||
| 10393 | ($tabListRef, $shortTabListRef) = $self->setTabList_cage(); | ||
| 10394 | # Prepare the list of column headings | ||
| 10395 | $columnListRef = $self->setColumnList_cage(); | ||
| 10396 | # Prepare the list of buttons | ||
| 10397 | $buttonListRef = $self->setButtonList_cage(); | ||
| 10398 | |||
| 10399 | # Prepare the data to be displayed | ||
| 10400 | @shortTabList = @$shortTabListRef; | ||
| 10401 | OUTER: foreach my $tab (@shortTabList) { | ||
| 10402 | |||
| 10403 | my (@cageList, @dataList); | ||
| 10404 | |||
| 10405 | @cageList = $self->getSortedCages($tab); | ||
| 10406 | |||
| 10407 | # @cageList contains a sorted list of cages. Convert that list into one that can be | ||
| 10408 | # displayed in a GA::Obj::SimpleList, in columns | ||
| 10409 | foreach my $cageObj (@cageList) { | ||
| 10410 | |||
| 10411 | my ($flag, $listRef); | ||
| 10412 | |||
| 10413 | if ( | ||
| 10414 | $self->session->ivExists('currentCageHash', $cageObj->name) | ||
| 10415 | && $self->session->ivShow('currentCageHash', $cageObj->name) eq $cageObj | ||
| 10416 | ) { | ||
| 10417 | $flag = TRUE; | ||
| 10418 | } else { | ||
| 10419 | $flag = FALSE; | ||
| 10420 | } | ||
| 10421 | |||
| 10422 | $listRef = [$flag, $cageObj->name]; | ||
| 10423 | push (@dataList, $listRef); | ||
| 10424 | } | ||
| 10425 | |||
| 10426 | $dataHash{$tab} = \@dataList; | ||
| 10427 | } | ||
| 10428 | |||
| 10429 | $dataHashRef = \%dataHash; | ||
| 10430 | |||
| 10431 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10432 | # equivalent to the edit button | ||
| 10433 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10434 | |||
| 10435 | $self->buttonEdit_cage(); | ||
| 10436 | }); | ||
| 10437 | |||
| 10438 | # Display all of this in the notebook | ||
| 10439 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10440 | } | ||
| 10441 | |||
| 10442 | sub currentCageHeader { | ||
| 10443 | |||
| 10444 | # Called by ->treeViewChanged when the user clicks on the 'Current cages' header in the | ||
| 10445 | # treeview | ||
| 10446 | # | ||
| 10447 | # Expected arguments | ||
| 10448 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10449 | # | ||
| 10450 | # Return values | ||
| 10451 | # 'undef' on improper arguments | ||
| 10452 | # 1 otherwise | ||
| 10453 | |||
| 10454 | my ($self, $item, $check) = @_; | ||
| 10455 | |||
| 10456 | # Local variables | ||
| 10457 | my ( | ||
| 10458 | $tabListRef, $shortTabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10459 | @shortTabList, | ||
| 10460 | %dataHash, | ||
| 10461 | ); | ||
| 10462 | |||
| 10463 | # Check for improper arguments | ||
| 10464 | if (! defined $item || defined $check) { | ||
| 10465 | |||
| 10466 | return $axmud::CLIENT->writeImproper($self->_objClass . '->currentCageHeader', @_); | ||
| 10467 | } | ||
| 10468 | |||
| 10469 | # Prepare the list of tabs | ||
| 10470 | ($tabListRef, $shortTabListRef) = $self->setTabList_cage(); | ||
| 10471 | # Prepare the list of column headings | ||
| 10472 | $columnListRef = $self->setColumnList_cage(); | ||
| 10473 | # Prepare the list of buttons | ||
| 10474 | $buttonListRef = $self->setButtonList_cage(); | ||
| 10475 | |||
| 10476 | # Prepare the data to be displayed | ||
| 10477 | @shortTabList = @$shortTabListRef; | ||
| 10478 | OUTER: foreach my $tab (@shortTabList) { | ||
| 10479 | |||
| 10480 | my (@cageList, @dataList); | ||
| 10481 | |||
| 10482 | @cageList = $self->getSortedCages($tab); | ||
| 10483 | |||
| 10484 | foreach my $cageObj (@cageList) { | ||
| 10485 | |||
| 10486 | my $listRef; | ||
| 10487 | |||
| 10488 | if ( | ||
| 10489 | $self->session->ivExists('currentCageHash', $cageObj->name) | ||
| 10490 | && $self->session->ivShow('currentCageHash', $cageObj->name) eq $cageObj | ||
| 10491 | ) { | ||
| 10492 | # The TRUE argument marks this as a current cage | ||
| 10493 | $listRef = [TRUE, $cageObj->name]; | ||
| 10494 | push (@dataList, $listRef); | ||
| 10495 | } | ||
| 10496 | } | ||
| 10497 | |||
| 10498 | $dataHash{$tab} = \@dataList; | ||
| 10499 | } | ||
| 10500 | |||
| 10501 | $dataHashRef = \%dataHash; | ||
| 10502 | |||
| 10503 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10504 | # equivalent to the edit button | ||
| 10505 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10506 | |||
| 10507 | $self->buttonEdit_cage(); | ||
| 10508 | }); | ||
| 10509 | |||
| 10510 | # Display all of this in the notebook | ||
| 10511 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10512 | } | ||
| 10513 | |||
| 10514 | sub activeInterfaceHeader { | ||
| 10515 | |||
| 10516 | # Called by ->treeViewChanged when the user clicks on the 'Active interfaces' header in the | ||
| 10517 | # treeview | ||
| 10518 | # | ||
| 10519 | # Expected arguments | ||
| 10520 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10521 | # | ||
| 10522 | # Return values | ||
| 10523 | # 'undef' on improper arguments | ||
| 10524 | # 1 otherwise | ||
| 10525 | |||
| 10526 | my ($self, $item, $check) = @_; | ||
| 10527 | |||
| 10528 | # Local variables | ||
| 10529 | my ( | ||
| 10530 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10531 | @shortTabList, | ||
| 10532 | %dataHash, | ||
| 10533 | ); | ||
| 10534 | |||
| 10535 | # Check for improper arguments | ||
| 10536 | if (! defined $item || defined $check) { | ||
| 10537 | |||
| 10538 | return $axmud::CLIENT->writeImproper($self->_objClass . '->activeInterfaceHeader', @_); | ||
| 10539 | } | ||
| 10540 | |||
| 10541 | # Prepare the list of tabs | ||
| 10542 | $tabListRef = [ | ||
| 10543 | 'All' => 'A_ll', | ||
| 10544 | 'Dependent' => '_Dependent', | ||
| 10545 | 'Independent' => 'I_ndependent', | ||
| 10546 | 'Trigger' => '_Trigger', | ||
| 10547 | 'Alias' => '_Alias', | ||
| 10548 | 'Macro' => '_Macro', | ||
| 10549 | 'Timer' => 'T_imer', | ||
| 10550 | 'Hook' => '_Hook', | ||
| 10551 | ]; | ||
| 10552 | |||
| 10553 | @shortTabList = ( | ||
| 10554 | 'All', 'Dependent', 'Independent', | ||
| 10555 | 'Trigger', 'Alias', 'Macro', 'Timer', 'Hook', | ||
| 10556 | ); | ||
| 10557 | |||
| 10558 | # Prepare the list of column headings | ||
| 10559 | $columnListRef = [ | ||
| 10560 | '#' => 'int', | ||
| 10561 | 'Enab.' => 'bool', | ||
| 10562 | 'Indep.' => 'bool', | ||
| 10563 | 'Cat.' => 'text', | ||
| 10564 | 'Name' => 'text', | ||
| 10565 | ]; | ||
| 10566 | |||
| 10567 | # Prepare the list of buttons | ||
| 10568 | $buttonListRef = [ | ||
| 10569 | 'Edit', 'Edit the selected interface', 'buttonEdit_activeInterface', | ||
| 10570 | 'Dump', 'Display this list of interfaces in the \'main\' window', | ||
| 10571 | 'buttonDump_activeInterface', | ||
| 10572 | ]; | ||
| 10573 | |||
| 10574 | # Prepare the data to be displayed | ||
| 10575 | foreach my $tab (@shortTabList) { | ||
| 10576 | |||
| 10577 | my (@interfaceList, @dataList); | ||
| 10578 | |||
| 10579 | @interfaceList = sort {$a->number <=> $b->number} | ||
| 10580 | ($self->session->ivValues('interfaceNumHash')); | ||
| 10581 | |||
| 10582 | foreach my $interfaceObj (@interfaceList) { | ||
| 10583 | |||
| 10584 | my $listRef; | ||
| 10585 | |||
| 10586 | if ( | ||
| 10587 | $tab eq 'All' | ||
| 10588 | || ($tab eq 'Dependent' && ! $interfaceObj->indepFlag) | ||
| 10589 | || ($tab eq 'Independent' && $interfaceObj->indepFlag) | ||
| 10590 | || lc($tab) eq $interfaceObj->category | ||
| 10591 | ) { | ||
| 10592 | $listRef = [ | ||
| 10593 | $interfaceObj->number, | ||
| 10594 | $interfaceObj->enabledFlag, | ||
| 10595 | $interfaceObj->indepFlag, | ||
| 10596 | $interfaceObj->category, | ||
| 10597 | $interfaceObj->name, | ||
| 10598 | ]; | ||
| 10599 | |||
| 10600 | push (@dataList, $listRef); | ||
| 10601 | } | ||
| 10602 | } | ||
| 10603 | |||
| 10604 | $dataHash{$tab} = \@dataList; | ||
| 10605 | } | ||
| 10606 | |||
| 10607 | $dataHashRef = \%dataHash; | ||
| 10608 | |||
| 10609 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10610 | # equivalent to the edit button | ||
| 10611 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10612 | |||
| 10613 | $self->buttonEdit_activeInterface(); | ||
| 10614 | }); | ||
| 10615 | |||
| 10616 | # Display all of this in the notebook | ||
| 10617 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10618 | } | ||
| 10619 | |||
| 10620 | sub interfaceModelHeader { | ||
| 10621 | |||
| 10622 | # Called by ->treeViewChanged when the user clicks on the 'Interface models' header in the | ||
| 10623 | # treeview | ||
| 10624 | # | ||
| 10625 | # Expected arguments | ||
| 10626 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10627 | # | ||
| 10628 | # Return values | ||
| 10629 | # 'undef' on improper arguments | ||
| 10630 | # 1 otherwise | ||
| 10631 | |||
| 10632 | my ($self, $item, $check) = @_; | ||
| 10633 | |||
| 10634 | # Local variables | ||
| 10635 | my ( | ||
| 10636 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 10637 | @categoryList, @dataList, | ||
| 10638 | %dataHash, | ||
| 10639 | ); | ||
| 10640 | |||
| 10641 | # Check for improper arguments | ||
| 10642 | if (! defined $item || defined $check) { | ||
| 10643 | |||
| 10644 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interfaceModelHeader', @_); | ||
| 10645 | } | ||
| 10646 | |||
| 10647 | # Prepare the list of tabs | ||
| 10648 | $tabListRef = [ | ||
| 10649 | 'Interface models' => '_Interface models', | ||
| 10650 | ]; | ||
| 10651 | |||
| 10652 | # Prepare the list of column headings | ||
| 10653 | $columnListRef = [ | ||
| 10654 | 'Category' => 'text', | ||
| 10655 | 'Stimulus' => 'text', | ||
| 10656 | 'Response' => 'text', | ||
| 10657 | ]; | ||
| 10658 | |||
| 10659 | # Prepare the list of buttons | ||
| 10660 | $buttonListRef = [ | ||
| 10661 | 'View', 'View the selected interface model', 'buttonView_interfaceModel', | ||
| 10662 | 'Dump', 'Display this list of interface models in the \'main\' window', | ||
| 10663 | 'buttonDump_interfaceModel', | ||
| 10664 | ]; | ||
| 10665 | |||
| 10666 | # Prepare the data to be displayed (there is only one tab) | ||
| 10667 | @categoryList = ('trigger', 'alias', 'macro', 'timer', 'hook'); | ||
| 10668 | foreach my $category (@categoryList) { | ||
| 10669 | |||
| 10670 | my ($modelObj, $listRef); | ||
| 10671 | |||
| 10672 | $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $category); | ||
| 10673 | $listRef = [$modelObj->category, $modelObj->stimulusName, $modelObj->responseName]; | ||
| 10674 | push (@dataList, $listRef); | ||
| 10675 | } | ||
| 10676 | |||
| 10677 | $dataHash{'Interface models'} = \@dataList; | ||
| 10678 | $dataHashRef = \%dataHash; | ||
| 10679 | |||
| 10680 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10681 | # equivalent to the edit button | ||
| 10682 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10683 | |||
| 10684 | $self->buttonView_interfaceModel(); | ||
| 10685 | }); | ||
| 10686 | |||
| 10687 | # Display all of this in the notebook | ||
| 10688 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10689 | } | ||
| 10690 | |||
| 10691 | # Treeview header responses - world model | ||
| 10692 | |||
| 10693 | sub modelHeader { | ||
| 10694 | |||
| 10695 | # Called by $self->allModelHeader, $self->regionModelHeader etc, after a call by | ||
| 10696 | # ->treeViewChanged when the user clicks on one of the items under the 'world model' | ||
| 10697 | # header in the treeview | ||
| 10698 | # | ||
| 10699 | # Expected arguments | ||
| 10700 | # $tabName - What to display on the tab, e.g. 'Weapons' | ||
| 10701 | # $tabShortCut - e.g. '_Weapons' | ||
| 10702 | # $iv - The GA::Obj::WorldModel IV storing all the world model objects of a | ||
| 10703 | # certain type, e.g. 'regionModelHash', 'weaponModelHash' (or even | ||
| 10704 | # 'modelHash') | ||
| 10705 | # $buttonListRef - Reference to a list containing the buttons to use for this category of | ||
| 10706 | # world model object (usually defined by $self->setButtonList_model, | ||
| 10707 | # but some types of object specify their own buttons) | ||
| 10708 | # | ||
| 10709 | # Return values | ||
| 10710 | # 'undef' on improper arguments | ||
| 10711 | # 1 otherwise | ||
| 10712 | |||
| 10713 | my ($self, $tabName, $tabShortCut, $iv, $buttonListRef, $check) = @_; | ||
| 10714 | |||
| 10715 | # Local variables | ||
| 10716 | my ( | ||
| 10717 | $tabListRef, $columnListRef, $wmObj, $dataHashRef, | ||
| 10718 | @objList, @dataList, | ||
| 10719 | %dataHash, | ||
| 10720 | ); | ||
| 10721 | |||
| 10722 | # Check for improper arguments | ||
| 10723 | if ( | ||
| 10724 | ! defined $tabName || ! defined $tabShortCut || ! defined $iv | ||
| 10725 | || ! defined $buttonListRef || defined $check | ||
| 10726 | ) { | ||
| 10727 | return $axmud::CLIENT->writeImproper($self->_objClass . '->modelHeader', @_); | ||
| 10728 | } | ||
| 10729 | |||
| 10730 | # Prepare the list of tabs | ||
| 10731 | $tabListRef = [ | ||
| 10732 | $tabName => $tabShortCut, | ||
| 10733 | ]; | ||
| 10734 | |||
| 10735 | # Prepare the list of column headings | ||
| 10736 | $columnListRef = $self->setColumnList_model(); | ||
| 10737 | |||
| 10738 | # Import the world model object (for convenience) | ||
| 10739 | $wmObj = $self->session->worldModelObj; | ||
| 10740 | # Prepare the data to be displayed (there is only one tab). Rather than sort the model | ||
| 10741 | # objects by number (which might take a long time), check every number between 1 and | ||
| 10742 | # GA::Obj::WorldModel->modelObjCount, using only objects which are actually stored in $iv | ||
| 10743 | if ($wmObj->modelObjCount) { | ||
| 10744 | |||
| 10745 | for (my $count = 1; $count <= $wmObj->modelObjCount; $count++) { | ||
| 10746 | |||
| 10747 | if (exists $wmObj->{$iv}{$count}) { | ||
| 10748 | |||
| 10749 | push (@objList, $wmObj->{$iv}{$count}); | ||
| 10750 | } | ||
| 10751 | } | ||
| 10752 | } | ||
| 10753 | |||
| 10754 | OUTER: foreach my $obj (@objList) { | ||
| 10755 | |||
| 10756 | my $listRef = [$obj->number, $obj->category, $obj->name]; | ||
| 10757 | push (@dataList, $listRef); | ||
| 10758 | } | ||
| 10759 | |||
| 10760 | $dataHash{$tabName} = \@dataList; | ||
| 10761 | $dataHashRef = \%dataHash; | ||
| 10762 | |||
| 10763 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 10764 | # equivalent to the edit button | ||
| 10765 | $self->ivPoke('notebookSelectRef', sub { | ||
| 10766 | |||
| 10767 | $self->buttonEdit_model(); | ||
| 10768 | }); | ||
| 10769 | |||
| 10770 | # Display all of this in the notebook | ||
| 10771 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 10772 | } | ||
| 10773 | |||
| 10774 | sub allModelHeader { | ||
| 10775 | |||
| 10776 | # Called by ->treeViewChanged when the user clicks on the 'All objects' header in the | ||
| 10777 | # treeview | ||
| 10778 | # The code to display the tab is basically the same for all categories of world model | ||
| 10779 | # object, so all categories call a single function | ||
| 10780 | # | ||
| 10781 | # Expected arguments | ||
| 10782 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10783 | # | ||
| 10784 | # Return values | ||
| 10785 | # 'undef' on improper arguments | ||
| 10786 | # The return value of $self->modelHeader, otherwise | ||
| 10787 | |||
| 10788 | my ($self, $item, $check) = @_; | ||
| 10789 | |||
| 10790 | # Local variables | ||
| 10791 | my @buttonList; | ||
| 10792 | |||
| 10793 | # Check for improper arguments | ||
| 10794 | if (! defined $item || defined $check) { | ||
| 10795 | |||
| 10796 | return $axmud::CLIENT->writeImproper($self->_objClass . '->allModelHeader', @_); | ||
| 10797 | } | ||
| 10798 | |||
| 10799 | # Prepare the list of buttons. This list is the same as the standard list of buttons, but | ||
| 10800 | # without the 'add' button | ||
| 10801 | @buttonList = ( | ||
| 10802 | 'Edit', 'Edit the selected world model object', 'buttonEdit_model', | ||
| 10803 | 'Delete', 'Delete the selected world model object', 'buttonDelete_model', | ||
| 10804 | 'Dump', 'Displays a list of all world model objects in the \'main\' window', | ||
| 10805 | 'buttonDump_model', | ||
| 10806 | 'Edit model', 'Edit the world model itself', 'buttonEdit_worldModel', | ||
| 10807 | ); | ||
| 10808 | |||
| 10809 | return $self->modelHeader( | ||
| 10810 | 'All objects', | ||
| 10811 | 'A_ll objects', | ||
| 10812 | 'modelHash', | ||
| 10813 | \@buttonList, | ||
| 10814 | ); | ||
| 10815 | } | ||
| 10816 | |||
| 10817 | sub regionModelHeader { | ||
| 10818 | |||
| 10819 | # Called by ->treeViewChanged when the user clicks on the 'Regions' header in the treeview | ||
| 10820 | # The code to display the tab is basically the same for all categories of world model | ||
| 10821 | # object, so all categories call a single function | ||
| 10822 | # | ||
| 10823 | # Expected arguments | ||
| 10824 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10825 | # | ||
| 10826 | # Return values | ||
| 10827 | # 'undef' on improper arguments | ||
| 10828 | # The return value of $self->modelHeader, otherwise | ||
| 10829 | |||
| 10830 | my ($self, $item, $check) = @_; | ||
| 10831 | |||
| 10832 | # Local variables | ||
| 10833 | my @buttonList; | ||
| 10834 | |||
| 10835 | # Check for improper arguments | ||
| 10836 | if (! defined $item || defined $check) { | ||
| 10837 | |||
| 10838 | return $axmud::CLIENT->writeImproper($self->_objClass . '->regionModelHeader', @_); | ||
| 10839 | } | ||
| 10840 | |||
| 10841 | # Prepare the list of buttons | ||
| 10842 | @buttonList = ( | ||
| 10843 | 'Add', 'Add a region object to the world model', 'buttonAddRegion_model', | ||
| 10844 | 'Add temporary', | ||
| 10845 | 'Add a temporary region object to the world model', 'buttonAddTempRegion_model', | ||
| 10846 | 'Edit region', 'Edit the selected region model object', 'buttonEdit_model', | ||
| 10847 | 'Edit regionmap', 'Edit the selected region\' regionmap', 'buttonEdit_regionmap', | ||
| 10848 | 'Delete', 'Delete the selected region model object', 'buttonDeleteRegion_model', | ||
| 10849 | 'Dump', 'Displays a list of all world model objects in the \'main\' window', | ||
| 10850 | 'buttonDump_model', | ||
| 10851 | ); | ||
| 10852 | |||
| 10853 | return $self->modelHeader( | ||
| 10854 | 'Regions', | ||
| 10855 | 'Regio_ns', | ||
| 10856 | 'regionModelHash', | ||
| 10857 | \@buttonList, | ||
| 10858 | ); | ||
| 10859 | } | ||
| 10860 | |||
| 10861 | sub roomModelHeader { | ||
| 10862 | |||
| 10863 | # Called by ->treeViewChanged when the user clicks on the 'Rooms' header in the treeview | ||
| 10864 | # The code to display the tab is basically the same for all categories of world model | ||
| 10865 | # object, so all categories call a single function | ||
| 10866 | # | ||
| 10867 | # Expected arguments | ||
| 10868 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10869 | # | ||
| 10870 | # Return values | ||
| 10871 | # 'undef' on improper arguments | ||
| 10872 | # The return value of $self->modelHeader, otherwise | ||
| 10873 | |||
| 10874 | my ($self, $item, $check) = @_; | ||
| 10875 | |||
| 10876 | # Local variables | ||
| 10877 | my @buttonList; | ||
| 10878 | |||
| 10879 | # Check for improper arguments | ||
| 10880 | if (! defined $item || defined $check) { | ||
| 10881 | |||
| 10882 | return $axmud::CLIENT->writeImproper($self->_objClass . '->roomModelHeader', @_); | ||
| 10883 | } | ||
| 10884 | |||
| 10885 | # Prepare the list of buttons | ||
| 10886 | @buttonList = ( | ||
| 10887 | 'Edit', 'Edit the selected world model object', 'buttonEdit_model', | ||
| 10888 | 'Delete', 'Delete the selected room model object', 'buttonDeleteRoom_model', | ||
| 10889 | 'Dump', 'Displays a list of all world model objects in the \'main\' window', | ||
| 10890 | 'buttonDump_model', | ||
| 10891 | ); | ||
| 10892 | |||
| 10893 | return $self->modelHeader( | ||
| 10894 | 'Rooms', | ||
| 10895 | '_Rooms', | ||
| 10896 | 'roomModelHash', | ||
| 10897 | \@buttonList, | ||
| 10898 | ); | ||
| 10899 | } | ||
| 10900 | |||
| 10901 | sub weaponModelHeader { | ||
| 10902 | |||
| 10903 | # Called by ->treeViewChanged when the user clicks on the 'Weapons' header in the treeview | ||
| 10904 | # The code to display the tab is basically the same for all categories of world model | ||
| 10905 | # object, so all categories call a single function | ||
| 10906 | # | ||
| 10907 | # Expected arguments | ||
| 10908 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10909 | # | ||
| 10910 | # Return values | ||
| 10911 | # 'undef' on improper arguments | ||
| 10912 | # The return value of $self->modelHeader, otherwise | ||
| 10913 | |||
| 10914 | my ($self, $item, $check) = @_; | ||
| 10915 | |||
| 10916 | # Local variables | ||
| 10917 | my $buttonListRef; | ||
| 10918 | |||
| 10919 | # Check for improper arguments | ||
| 10920 | if (! defined $item || defined $check) { | ||
| 10921 | |||
| 10922 | return $axmud::CLIENT->writeImproper($self->_objClass . '->weaponModelHeader', @_); | ||
| 10923 | } | ||
| 10924 | |||
| 10925 | # Prepare the list of buttons | ||
| 10926 | $buttonListRef = $self->setButtonList_model(); | ||
| 10927 | |||
| 10928 | return $self->modelHeader( | ||
| 10929 | 'Weapons', | ||
| 10930 | '_Weapons', | ||
| 10931 | 'weaponModelHash', | ||
| 10932 | $buttonListRef, | ||
| 10933 | ); | ||
| 10934 | } | ||
| 10935 | |||
| 10936 | sub armourModelHeader { | ||
| 10937 | |||
| 10938 | # Called by ->treeViewChanged when the user clicks on the 'Armours' header in the treeview | ||
| 10939 | # The code to display the tab is basically the same for all categories of world model | ||
| 10940 | # object, so all categories call a single function | ||
| 10941 | # | ||
| 10942 | # Expected arguments | ||
| 10943 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10944 | # | ||
| 10945 | # Return values | ||
| 10946 | # 'undef' on improper arguments | ||
| 10947 | # The return value of $self->modelHeader, otherwise | ||
| 10948 | |||
| 10949 | my ($self, $item, $check) = @_; | ||
| 10950 | |||
| 10951 | # Local variables | ||
| 10952 | my $buttonListRef; | ||
| 10953 | |||
| 10954 | # Check for improper arguments | ||
| 10955 | if (! defined $item || defined $check) { | ||
| 10956 | |||
| 10957 | return $axmud::CLIENT->writeImproper($self->_objClass . '->armourModelHeader', @_); | ||
| 10958 | } | ||
| 10959 | |||
| 10960 | # Prepare the list of buttons | ||
| 10961 | $buttonListRef = $self->setButtonList_model(); | ||
| 10962 | |||
| 10963 | return $self->modelHeader( | ||
| 10964 | 'Armours', | ||
| 10965 | '_Armours', | ||
| 10966 | 'armourModelHash', | ||
| 10967 | $buttonListRef, | ||
| 10968 | ); | ||
| 10969 | } | ||
| 10970 | |||
| 10971 | sub garmentModelHeader { | ||
| 10972 | |||
| 10973 | # Called by ->treeViewChanged when the user clicks on the 'Garments' header in the treeview | ||
| 10974 | # The code to display the tab is basically the same for all categories of world model | ||
| 10975 | # object, so all categories call a single function | ||
| 10976 | # | ||
| 10977 | # Expected arguments | ||
| 10978 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 10979 | # | ||
| 10980 | # Return values | ||
| 10981 | # 'undef' on improper arguments | ||
| 10982 | # The return value of $self->modelHeader, otherwise | ||
| 10983 | |||
| 10984 | my ($self, $item, $check) = @_; | ||
| 10985 | |||
| 10986 | # Local variables | ||
| 10987 | my $buttonListRef; | ||
| 10988 | |||
| 10989 | # Check for improper arguments | ||
| 10990 | if (! defined $item || defined $check) { | ||
| 10991 | |||
| 10992 | return $axmud::CLIENT->writeImproper($self->_objClass . '->garmentModelHeader', @_); | ||
| 10993 | } | ||
| 10994 | |||
| 10995 | # Prepare the list of buttons | ||
| 10996 | $buttonListRef = $self->setButtonList_model(); | ||
| 10997 | |||
| 10998 | return $self->modelHeader( | ||
| 10999 | 'Garments', | ||
| 11000 | '_Garments', | ||
| 11001 | 'garmentModelHash', | ||
| 11002 | $buttonListRef, | ||
| 11003 | ); | ||
| 11004 | } | ||
| 11005 | |||
| 11006 | sub charModelHeader { | ||
| 11007 | |||
| 11008 | # Called by ->treeViewChanged when the user clicks on the 'Characters' header in the | ||
| 11009 | # treeview | ||
| 11010 | # The code to display the tab is basically the same for all categories of world model | ||
| 11011 | # object, so all categories call a single function | ||
| 11012 | # | ||
| 11013 | # Expected arguments | ||
| 11014 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11015 | # | ||
| 11016 | # Return values | ||
| 11017 | # 'undef' on improper arguments | ||
| 11018 | # The return value of $self->modelHeader, otherwise | ||
| 11019 | |||
| 11020 | my ($self, $item, $check) = @_; | ||
| 11021 | |||
| 11022 | # Local variables | ||
| 11023 | my @buttonList; | ||
| 11024 | |||
| 11025 | # Check for improper arguments | ||
| 11026 | if (! defined $item || defined $check) { | ||
| 11027 | |||
| 11028 | return $axmud::CLIENT->writeImproper($self->_objClass . '->charModelHeader', @_); | ||
| 11029 | } | ||
| 11030 | |||
| 11031 | # Prepare the list of buttons | ||
| 11032 | @buttonList = ( | ||
| 11033 | 'Add', 'Add a player character to the world model', 'buttonAddChar_model', | ||
| 11034 | 'Edit', 'Edit the selected character object', 'buttonEdit_model', | ||
| 11035 | 'Delete', 'Delete the selected character object', 'buttonDelete_model', | ||
| 11036 | 'Dump', 'Displays a list of all world model characters in the \'main\' window', | ||
| 11037 | 'buttonDumpChar_model', | ||
| 11038 | ); | ||
| 11039 | |||
| 11040 | return $self->modelHeader( | ||
| 11041 | 'Characters', | ||
| 11042 | '_Characters', | ||
| 11043 | 'charModelHash', | ||
| 11044 | \@buttonList, | ||
| 11045 | ); | ||
| 11046 | } | ||
| 11047 | |||
| 11048 | sub minionModelHeader { | ||
| 11049 | |||
| 11050 | # Called by ->treeViewChanged when the user clicks on the 'Minions' header in the treeview | ||
| 11051 | # The code to display the tab is basically the same for all categories of world model | ||
| 11052 | # object, so all categories call a single function | ||
| 11053 | # | ||
| 11054 | # Expected arguments | ||
| 11055 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11056 | # | ||
| 11057 | # Return values | ||
| 11058 | # 'undef' on improper arguments | ||
| 11059 | # The return value of $self->modelHeader, otherwise | ||
| 11060 | |||
| 11061 | my ($self, $item, $check) = @_; | ||
| 11062 | |||
| 11063 | # Local variables | ||
| 11064 | my $buttonListRef; | ||
| 11065 | |||
| 11066 | # Check for improper arguments | ||
| 11067 | if (! defined $item || defined $check) { | ||
| 11068 | |||
| 11069 | return $axmud::CLIENT->writeImproper($self->_objClass . '->minionModelHeader', @_); | ||
| 11070 | } | ||
| 11071 | |||
| 11072 | # Prepare the list of buttons | ||
| 11073 | $buttonListRef = $self->setButtonList_model(); | ||
| 11074 | |||
| 11075 | return $self->modelHeader( | ||
| 11076 | 'Minions', | ||
| 11077 | '_Minions', | ||
| 11078 | 'minionModelHash', | ||
| 11079 | $buttonListRef, | ||
| 11080 | ); | ||
| 11081 | } | ||
| 11082 | |||
| 11083 | sub sentientModelHeader { | ||
| 11084 | |||
| 11085 | # Called by ->treeViewChanged when the user clicks on the 'Sentients' header in the treeview | ||
| 11086 | # The code to display the tab is basically the same for all categories of world model | ||
| 11087 | # object, so all categories call a single function | ||
| 11088 | # | ||
| 11089 | # Expected arguments | ||
| 11090 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11091 | # | ||
| 11092 | # Return values | ||
| 11093 | # 'undef' on improper arguments | ||
| 11094 | # The return value of $self->modelHeader, otherwise | ||
| 11095 | |||
| 11096 | my ($self, $item, $check) = @_; | ||
| 11097 | |||
| 11098 | # Local variables | ||
| 11099 | my $buttonListRef; | ||
| 11100 | |||
| 11101 | # Check for improper arguments | ||
| 11102 | if (! defined $item || defined $check) { | ||
| 11103 | |||
| 11104 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sentientModelHeader', @_); | ||
| 11105 | } | ||
| 11106 | |||
| 11107 | # Prepare the list of buttons | ||
| 11108 | $buttonListRef = $self->setButtonList_model(); | ||
| 11109 | |||
| 11110 | return $self->modelHeader( | ||
| 11111 | 'Sentients', | ||
| 11112 | '_Sentients', | ||
| 11113 | 'sentientModelHash', | ||
| 11114 | $buttonListRef, | ||
| 11115 | ); | ||
| 11116 | } | ||
| 11117 | |||
| 11118 | sub creatureModelHeader { | ||
| 11119 | |||
| 11120 | # Called by ->treeViewChanged when the user clicks on the 'Creatures' header in the treeview | ||
| 11121 | # The code to display the tab is basically the same for all categories of world model | ||
| 11122 | # object, so all categories call a single function | ||
| 11123 | # | ||
| 11124 | # Expected arguments | ||
| 11125 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11126 | # | ||
| 11127 | # Return values | ||
| 11128 | # 'undef' on improper arguments | ||
| 11129 | # The return value of $self->modelHeader, otherwise | ||
| 11130 | |||
| 11131 | my ($self, $item, $check) = @_; | ||
| 11132 | |||
| 11133 | # Local variables | ||
| 11134 | my $buttonListRef; | ||
| 11135 | |||
| 11136 | # Check for improper arguments | ||
| 11137 | if (! defined $item || defined $check) { | ||
| 11138 | |||
| 11139 | return $axmud::CLIENT->writeImproper($self->_objClass . '->creatureModelHeader', @_); | ||
| 11140 | } | ||
| 11141 | |||
| 11142 | # Prepare the list of buttons | ||
| 11143 | $buttonListRef = $self->setButtonList_model(); | ||
| 11144 | |||
| 11145 | return $self->modelHeader( | ||
| 11146 | 'Creatures', | ||
| 11147 | 'Crea_tures', | ||
| 11148 | 'creatureModelHash', | ||
| 11149 | $buttonListRef, | ||
| 11150 | ); | ||
| 11151 | } | ||
| 11152 | |||
| 11153 | sub portableModelHeader { | ||
| 11154 | |||
| 11155 | # Called by ->treeViewChanged when the user clicks on the 'Portables' header in the treeview | ||
| 11156 | # The code to display the tab is basically the same for all categories of world model | ||
| 11157 | # object, so all categories call a single function | ||
| 11158 | # | ||
| 11159 | # Expected arguments | ||
| 11160 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11161 | # | ||
| 11162 | # Return values | ||
| 11163 | # 'undef' on improper arguments | ||
| 11164 | # The return value of $self->modelHeader, otherwise | ||
| 11165 | |||
| 11166 | my ($self, $item, $check) = @_; | ||
| 11167 | |||
| 11168 | # Local variables | ||
| 11169 | my $buttonListRef; | ||
| 11170 | |||
| 11171 | # Check for improper arguments | ||
| 11172 | if (! defined $item || defined $check) { | ||
| 11173 | |||
| 11174 | return $axmud::CLIENT->writeImproper($self->_objClass . '->portableModelHeader', @_); | ||
| 11175 | } | ||
| 11176 | |||
| 11177 | # Prepare the list of buttons | ||
| 11178 | $buttonListRef = $self->setButtonList_model(); | ||
| 11179 | |||
| 11180 | return $self->modelHeader( | ||
| 11181 | 'Portables', | ||
| 11182 | '_Portables', | ||
| 11183 | 'portableModelHash', | ||
| 11184 | $buttonListRef, | ||
| 11185 | ); | ||
| 11186 | } | ||
| 11187 | |||
| 11188 | sub decorationModelHeader { | ||
| 11189 | |||
| 11190 | # Called by ->treeViewChanged when the user clicks on the 'Decorations' header in the | ||
| 11191 | # treeview | ||
| 11192 | # The code to display the tab is basically the same for all categories of world model | ||
| 11193 | # object, so all categories call a single function | ||
| 11194 | # | ||
| 11195 | # Expected arguments | ||
| 11196 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11197 | # | ||
| 11198 | # Return values | ||
| 11199 | # 'undef' on improper arguments | ||
| 11200 | # The return value of $self->modelHeader, otherwise | ||
| 11201 | |||
| 11202 | my ($self, $item, $check) = @_; | ||
| 11203 | |||
| 11204 | # Local variables | ||
| 11205 | my $buttonListRef; | ||
| 11206 | |||
| 11207 | # Check for improper arguments | ||
| 11208 | if (! defined $item || defined $check) { | ||
| 11209 | |||
| 11210 | return $axmud::CLIENT->writeImproper($self->_objClass . '->decorationModelHeader', @_); | ||
| 11211 | } | ||
| 11212 | |||
| 11213 | # Prepare the list of buttons | ||
| 11214 | $buttonListRef = $self->setButtonList_model(); | ||
| 11215 | |||
| 11216 | return $self->modelHeader( | ||
| 11217 | 'Decorations', | ||
| 11218 | '_Decorations', | ||
| 11219 | 'decorationModelHash', | ||
| 11220 | $buttonListRef, | ||
| 11221 | ); | ||
| 11222 | } | ||
| 11223 | |||
| 11224 | sub customModelHeader { | ||
| 11225 | |||
| 11226 | # Called by ->treeViewChanged when the user clicks on the 'Custom objects' header in the | ||
| 11227 | # treeview | ||
| 11228 | # The code to display the tab is basically the same for all categories of world model | ||
| 11229 | # object, so all categories call a single function | ||
| 11230 | # | ||
| 11231 | # Expected arguments | ||
| 11232 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11233 | # | ||
| 11234 | # Return values | ||
| 11235 | # 'undef' on improper arguments | ||
| 11236 | # The return value of $self->modelHeader, otherwise | ||
| 11237 | |||
| 11238 | my ($self, $item, $check) = @_; | ||
| 11239 | |||
| 11240 | # Local variables | ||
| 11241 | my $buttonListRef; | ||
| 11242 | |||
| 11243 | # Check for improper arguments | ||
| 11244 | if (! defined $item || defined $check) { | ||
| 11245 | |||
| 11246 | return $axmud::CLIENT->writeImproper($self->_objClass . '->customModelHeader', @_); | ||
| 11247 | } | ||
| 11248 | |||
| 11249 | # Prepare the list of buttons | ||
| 11250 | $buttonListRef = $self->setButtonList_model(); | ||
| 11251 | |||
| 11252 | return $self->modelHeader( | ||
| 11253 | 'Custom', | ||
| 11254 | 'C_ustom', | ||
| 11255 | 'customModelHash', | ||
| 11256 | $buttonListRef, | ||
| 11257 | ); | ||
| 11258 | } | ||
| 11259 | |||
| 11260 | sub exitModelHeader { | ||
| 11261 | |||
| 11262 | # Called by ->treeViewChanged when the user clicks on the 'Exits' header in the treeview | ||
| 11263 | # | ||
| 11264 | # Expected arguments | ||
| 11265 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11266 | # | ||
| 11267 | # Return values | ||
| 11268 | # 'undef' on improper arguments | ||
| 11269 | # 1 otherwise | ||
| 11270 | |||
| 11271 | my ($self, $item, $check) = @_; | ||
| 11272 | |||
| 11273 | # Local variables | ||
| 11274 | my ( | ||
| 11275 | $tabListRef, $columnListRef, $buttonListRef, $wmObj, $dataHashRef, | ||
| 11276 | @objList, @dataList, | ||
| 11277 | %dataHash, | ||
| 11278 | ); | ||
| 11279 | |||
| 11280 | # Check for improper arguments | ||
| 11281 | if (! defined $item || defined $check) { | ||
| 11282 | |||
| 11283 | return $axmud::CLIENT->writeImproper($self->_objClass . '->exitModelHeader', @_); | ||
| 11284 | } | ||
| 11285 | |||
| 11286 | # Prepare the list of tabs | ||
| 11287 | $tabListRef = [ | ||
| 11288 | 'Exits' => '_Exits', | ||
| 11289 | ]; | ||
| 11290 | |||
| 11291 | # Prepare the list of column headings | ||
| 11292 | $columnListRef = [ | ||
| 11293 | 'Exit #' => 'int', | ||
| 11294 | 'Room #' => 'int', | ||
| 11295 | 'Nominal dir' => 'text', | ||
| 11296 | 'Map dir' => 'text', | ||
| 11297 | ]; | ||
| 11298 | |||
| 11299 | # Prepare the list of buttons | ||
| 11300 | $buttonListRef = [ | ||
| 11301 | 'Add', 'Add an exit to the exit model', 'buttonAdd_exitModel', | ||
| 11302 | 'Edit', 'Edit the selected exit', 'buttonEdit_exitModel', | ||
| 11303 | 'Delete', 'Delete the selected exit from the exit model', 'buttonDelete_exitModel', | ||
| 11304 | 'Dump', 'Dump the contents of the exit model in the \'main\' window', | ||
| 11305 | 'buttonDump_exitModel', | ||
| 11306 | ]; | ||
| 11307 | |||
| 11308 | # Import the world model object (for convenience) | ||
| 11309 | $wmObj = $self->session->worldModelObj; | ||
| 11310 | # Prepare the data to be displayed (there is only one tab). Rather than sort the exit model | ||
| 11311 | # objects by number (which might take a long time), check every number between 1 and | ||
| 11312 | # GA::Obj::WorldModel->exitObjCount, using only objects which are actually stored in $iv | ||
| 11313 | if ($wmObj->exitObjCount) { | ||
| 11314 | |||
| 11315 | for (my $count = 1; $count <= $wmObj->exitObjCount; $count++) { | ||
| 11316 | |||
| 11317 | if (exists $wmObj->{'exitModelHash'}{$count}) { | ||
| 11318 | |||
| 11319 | push (@objList, $wmObj->{'exitModelHash'}{$count}); | ||
| 11320 | } | ||
| 11321 | } | ||
| 11322 | } | ||
| 11323 | |||
| 11324 | foreach my $exitObj (@objList) { | ||
| 11325 | |||
| 11326 | my ($listRef, $mapDir); | ||
| 11327 | |||
| 11328 | if ($exitObj->mapDir) { | ||
| 11329 | $mapDir = $exitObj->mapDir; | ||
| 11330 | } else { | ||
| 11331 | $mapDir = 'unallocatable'; | ||
| 11332 | } | ||
| 11333 | |||
| 11334 | $listRef = [$exitObj->number, $exitObj->parent, $exitObj->dir, $mapDir]; | ||
| 11335 | push (@dataList, $listRef); | ||
| 11336 | } | ||
| 11337 | |||
| 11338 | $dataHash{'Exits'} = \@dataList; | ||
| 11339 | $dataHashRef = \%dataHash; | ||
| 11340 | |||
| 11341 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 11342 | # equivalent to the edit button | ||
| 11343 | $self->ivPoke('notebookSelectRef', sub { | ||
| 11344 | |||
| 11345 | $self->buttonEdit_exitModel(); | ||
| 11346 | }); | ||
| 11347 | |||
| 11348 | # Display all of this in the notebook | ||
| 11349 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 11350 | } | ||
| 11351 | |||
| 11352 | # Treeview header responses - buffers | ||
| 11353 | |||
| 11354 | sub displayBufferHeader { | ||
| 11355 | |||
| 11356 | # Called by ->treeViewChanged when the user clicks on the 'Display buffer' header in the | ||
| 11357 | # treeview | ||
| 11358 | # | ||
| 11359 | # Expected arguments | ||
| 11360 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11361 | # | ||
| 11362 | # Return values | ||
| 11363 | # 'undef' on improper arguments | ||
| 11364 | # 1 otherwise | ||
| 11365 | |||
| 11366 | my ($self, $item, $check) = @_; | ||
| 11367 | |||
| 11368 | # Local variables | ||
| 11369 | my ( | ||
| 11370 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11371 | @objList, @dataList, | ||
| 11372 | %dataHash, | ||
| 11373 | ); | ||
| 11374 | |||
| 11375 | # Check for improper arguments | ||
| 11376 | if (! defined $item || defined $check) { | ||
| 11377 | |||
| 11378 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayBufferHeader', @_); | ||
| 11379 | } | ||
| 11380 | |||
| 11381 | # Prepare the list of tabs | ||
| 11382 | $tabListRef = [ | ||
| 11383 | 'Display buffer' => '_Display buffer', | ||
| 11384 | ]; | ||
| 11385 | |||
| 11386 | # Prepare the list of column headings | ||
| 11387 | $columnListRef = [ | ||
| 11388 | 'Line' => 'int', | ||
| 11389 | 'Time' => 'int', | ||
| 11390 | 'Text' => 'text', | ||
| 11391 | ]; | ||
| 11392 | |||
| 11393 | # Prepare the list of buttons | ||
| 11394 | $buttonListRef = [ | ||
| 11395 | 'Dump 20', 'Display the most recent 20 lines in the \'main\' window', | ||
| 11396 | 'buttonDump20_displayBuffer', | ||
| 11397 | 'Dump all', 'Display all lines in the \'main\' window', 'buttonDumpAll_displayBuffer', | ||
| 11398 | 'Status', 'Display the display buffer\'s status in the \'main\' window', | ||
| 11399 | 'buttonStatus_displayBuffer', | ||
| 11400 | 'View line', 'View the selected line in an \'edit\' window', 'buttonView_displayBuffer', | ||
| 11401 | 'Test pattern', 'Test a pattern (regex) against this line', 'buttonTest_displayBuffer', | ||
| 11402 | 'Save buffer', 'Save lines from the display buffer to file', 'buttonSave_displayBuffer', | ||
| 11403 | 'Save both', 'Save lines from the display and command buffers to file', | ||
| 11404 | 'buttonSaveBoth_displayBuffer', | ||
| 11405 | ]; | ||
| 11406 | |||
| 11407 | # Prepare the data to be displayed (there is only one tab). Rather than sort the buffer | ||
| 11408 | # objects by number (which might take a while), check every number between | ||
| 11409 | # GA::Session->displayBufferFirst and ->displayBufferLast | ||
| 11410 | if (defined $self->session->displayBufferLast) { | ||
| 11411 | |||
| 11412 | for ( | ||
| 11413 | my $count = $self->session->displayBufferFirst; | ||
| 11414 | $count <= $self->session->displayBufferLast; | ||
| 11415 | $count++ | ||
| 11416 | ) { | ||
| 11417 | # There shouldn't be any missing buffer objects, but just in case... | ||
| 11418 | if (exists $self->session->{'displayBufferHash'}{$count}) { | ||
| 11419 | |||
| 11420 | push (@objList, $self->session->{'displayBufferHash'}{$count}); | ||
| 11421 | } | ||
| 11422 | } | ||
| 11423 | } | ||
| 11424 | |||
| 11425 | foreach my $bufferObj (@objList) { | ||
| 11426 | |||
| 11427 | my $listRef = [ | ||
| 11428 | $bufferObj->number, | ||
| 11429 | int ($bufferObj->time), | ||
| 11430 | $bufferObj->modLine, | ||
| 11431 | ]; | ||
| 11432 | push (@dataList, $listRef); | ||
| 11433 | } | ||
| 11434 | |||
| 11435 | $dataHash{'Display buffer'} = \@dataList; | ||
| 11436 | $dataHashRef = \%dataHash; | ||
| 11437 | |||
| 11438 | # (Do nothing when a line is double-clicked) | ||
| 11439 | |||
| 11440 | # Display all of this in the notebook | ||
| 11441 | return $self->refreshNotebook( | ||
| 11442 | $tabListRef, | ||
| 11443 | $columnListRef, | ||
| 11444 | $dataHashRef, | ||
| 11445 | $buttonListRef, | ||
| 11446 | TRUE, # Scroll to bottom | ||
| 11447 | ); | ||
| 11448 | } | ||
| 11449 | |||
| 11450 | sub instructBufferHeader { | ||
| 11451 | |||
| 11452 | # Called by ->treeViewChanged when the user clicks on the 'Instruction buffer' header in the | ||
| 11453 | # treeview | ||
| 11454 | # | ||
| 11455 | # Expected arguments | ||
| 11456 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11457 | # | ||
| 11458 | # Return values | ||
| 11459 | # 'undef' on improper arguments | ||
| 11460 | # 1 otherwise | ||
| 11461 | |||
| 11462 | my ($self, $item, $check) = @_; | ||
| 11463 | |||
| 11464 | # Local variables | ||
| 11465 | my ( | ||
| 11466 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11467 | @objList, @dataList, | ||
| 11468 | %dataHash, | ||
| 11469 | ); | ||
| 11470 | |||
| 11471 | # Check for improper arguments | ||
| 11472 | if (! defined $item || defined $check) { | ||
| 11473 | |||
| 11474 | return $axmud::CLIENT->writeImproper($self->_objClass . '->instructBufferHeader', @_); | ||
| 11475 | } | ||
| 11476 | |||
| 11477 | # Prepare the list of tabs | ||
| 11478 | $tabListRef = [ | ||
| 11479 | 'Instruction buffer' => '_Instruction buffer', | ||
| 11480 | ]; | ||
| 11481 | |||
| 11482 | # Prepare the list of column headings | ||
| 11483 | $columnListRef = [ | ||
| 11484 | 'Line' => 'int', | ||
| 11485 | 'Type' => 'text', | ||
| 11486 | 'Time' => 'int', | ||
| 11487 | 'Instruction' => 'text', | ||
| 11488 | ]; | ||
| 11489 | |||
| 11490 | # Prepare the list of buttons | ||
| 11491 | $buttonListRef = [ | ||
| 11492 | 'Dump 20', 'Display the most recent 20 instructions in the \'main\' window', | ||
| 11493 | 'buttonDump20_instructBuffer', | ||
| 11494 | 'Dump all', 'Display all instructions in the \'main\' window', | ||
| 11495 | 'buttonDumpAll_instructBuffer', | ||
| 11496 | 'Status', 'Display the instruction buffer\'s status in the \'main\' window', | ||
| 11497 | 'buttonStatus_instructBuffer', | ||
| 11498 | 'View line', 'View the selected line in an \'edit\' window', | ||
| 11499 | 'buttonView_instructBuffer', | ||
| 11500 | ]; | ||
| 11501 | |||
| 11502 | # Prepare the data to be displayed (there is only one tab). Rather than sort the buffer | ||
| 11503 | # objects by number (which might take a while), check every number between | ||
| 11504 | # GA::Session->instructBufferFirst and ->instructBufferLast | ||
| 11505 | if ($self->session->instructBufferCount) { | ||
| 11506 | |||
| 11507 | for ( | ||
| 11508 | my $count = $self->session->instructBufferFirst; | ||
| 11509 | $count <= $self->session->instructBufferLast; | ||
| 11510 | $count++ | ||
| 11511 | ) { | ||
| 11512 | # There shouldn't be any missing buffer objects, but just in case... | ||
| 11513 | if (exists $self->session->{'instructBufferHash'}{$count}) { | ||
| 11514 | |||
| 11515 | push (@objList, $self->session->{'instructBufferHash'}{$count}); | ||
| 11516 | } | ||
| 11517 | } | ||
| 11518 | } | ||
| 11519 | |||
| 11520 | foreach my $bufferObj (@objList) { | ||
| 11521 | |||
| 11522 | my ($listRef, $time); | ||
| 11523 | |||
| 11524 | # During the session's setup, client commands (notably ';setguild', ';setrace', | ||
| 11525 | # ';setchar') might be executed before GA::Session->sessionTime has been initialised | ||
| 11526 | $time = $bufferObj->time; | ||
| 11527 | if (! defined $time) { | ||
| 11528 | |||
| 11529 | $time = 0; | ||
| 11530 | } | ||
| 11531 | |||
| 11532 | $listRef = [ | ||
| 11533 | $bufferObj->number, | ||
| 11534 | $bufferObj->type, | ||
| 11535 | int ($time), | ||
| 11536 | $bufferObj->instruct, | ||
| 11537 | ]; | ||
| 11538 | |||
| 11539 | push (@dataList, $listRef); | ||
| 11540 | } | ||
| 11541 | |||
| 11542 | $dataHash{'Instruction buffer'} = \@dataList; | ||
| 11543 | $dataHashRef = \%dataHash; | ||
| 11544 | |||
| 11545 | # (Do nothing when a line is double-clicked) | ||
| 11546 | |||
| 11547 | # Display all of this in the notebook | ||
| 11548 | return $self->refreshNotebook( | ||
| 11549 | $tabListRef, | ||
| 11550 | $columnListRef, | ||
| 11551 | $dataHashRef, | ||
| 11552 | $buttonListRef, | ||
| 11553 | TRUE, # Scroll to bottom | ||
| 11554 | ); | ||
| 11555 | } | ||
| 11556 | |||
| 11557 | sub cmdBufferHeader { | ||
| 11558 | |||
| 11559 | # Called by ->treeViewChanged when the user clicks on the 'Command buffer' header in the | ||
| 11560 | # treeview | ||
| 11561 | # | ||
| 11562 | # Expected arguments | ||
| 11563 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11564 | # | ||
| 11565 | # Return values | ||
| 11566 | # 'undef' on improper arguments | ||
| 11567 | # 1 otherwise | ||
| 11568 | |||
| 11569 | my ($self, $item, $check) = @_; | ||
| 11570 | |||
| 11571 | # Local variables | ||
| 11572 | my ( | ||
| 11573 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11574 | @objList, @dataList, | ||
| 11575 | %dataHash, | ||
| 11576 | ); | ||
| 11577 | |||
| 11578 | # Check for improper arguments | ||
| 11579 | if (! defined $item || defined $check) { | ||
| 11580 | |||
| 11581 | return $axmud::CLIENT->writeImproper($self->_objClass . '->cmdBufferHeader', @_); | ||
| 11582 | } | ||
| 11583 | |||
| 11584 | # Prepare the list of tabs | ||
| 11585 | $tabListRef = [ | ||
| 11586 | 'Command buffer' => '_Command buffer', | ||
| 11587 | ]; | ||
| 11588 | |||
| 11589 | # Prepare the list of column headings | ||
| 11590 | $columnListRef = [ | ||
| 11591 | 'Line' => 'int', | ||
| 11592 | 'Time' => 'int', | ||
| 11593 | 'Command' => 'text', | ||
| 11594 | ]; | ||
| 11595 | |||
| 11596 | # Prepare the list of buttons | ||
| 11597 | $buttonListRef = [ | ||
| 11598 | 'Dump 20', 'Display the most recent 20 commands in the \'main\' window', | ||
| 11599 | 'buttonDump20_cmdBuffer', | ||
| 11600 | 'Dump all', 'Display all commands in the \'main\' window', 'buttonDumpAll_cmdBuffer', | ||
| 11601 | 'Status', 'Display the command buffer\'s status in the \'main\' window', | ||
| 11602 | 'buttonStatus_cmdBuffer', | ||
| 11603 | 'View line', 'View the selected line in an \'edit\' window', 'buttonView_cmdBuffer', | ||
| 11604 | 'Save buffer', 'Save lines from the command buffer to file', 'buttonSave_cmdBuffer', | ||
| 11605 | 'Save both', 'Save lines from the text and command buffers to file', | ||
| 11606 | 'buttonSaveBoth_displayBuffer', | ||
| 11607 | ]; | ||
| 11608 | |||
| 11609 | # Prepare the data to be displayed (there is only one tab). Rather than sort the buffer | ||
| 11610 | # objects by number (which might take a while), check every number between | ||
| 11611 | # GA::Session->cmdBufferFirst and ->cmdBufferLast | ||
| 11612 | if ($self->session->cmdBufferCount) { | ||
| 11613 | |||
| 11614 | for ( | ||
| 11615 | my $count = $self->session->cmdBufferFirst; | ||
| 11616 | $count <= $self->session->cmdBufferLast; | ||
| 11617 | $count++ | ||
| 11618 | ) { | ||
| 11619 | # There shouldn't be any missing buffer objects, but just in case... | ||
| 11620 | if (exists $self->session->{'cmdBufferHash'}{$count}) { | ||
| 11621 | |||
| 11622 | push (@objList, $self->session->{'cmdBufferHash'}{$count}); | ||
| 11623 | } | ||
| 11624 | } | ||
| 11625 | } | ||
| 11626 | |||
| 11627 | foreach my $bufferObj (@objList) { | ||
| 11628 | |||
| 11629 | my $listRef = [ | ||
| 11630 | $bufferObj->number, | ||
| 11631 | int ($bufferObj->time), | ||
| 11632 | $bufferObj->cmd, | ||
| 11633 | ]; | ||
| 11634 | push (@dataList, $listRef); | ||
| 11635 | } | ||
| 11636 | |||
| 11637 | $dataHash{'Command buffer'} = \@dataList; | ||
| 11638 | $dataHashRef = \%dataHash; | ||
| 11639 | |||
| 11640 | # (Do nothing when a line is double-clicked) | ||
| 11641 | |||
| 11642 | # Display all of this in the notebook | ||
| 11643 | return $self->refreshNotebook( | ||
| 11644 | $tabListRef, | ||
| 11645 | $columnListRef, | ||
| 11646 | $dataHashRef, | ||
| 11647 | $buttonListRef, | ||
| 11648 | TRUE, # Scroll to bottom | ||
| 11649 | ); | ||
| 11650 | } | ||
| 11651 | |||
| 11652 | # Treeview header responses - other objects | ||
| 11653 | |||
| 11654 | sub chatContactHeader { | ||
| 11655 | |||
| 11656 | # Called by ->treeViewChanged when the user clicks on the 'Chat contacts' header in the | ||
| 11657 | # treeview | ||
| 11658 | # | ||
| 11659 | # Expected arguments | ||
| 11660 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11661 | # | ||
| 11662 | # Return values | ||
| 11663 | # 'undef' on improper arguments | ||
| 11664 | # 1 otherwise | ||
| 11665 | |||
| 11666 | my ($self, $item, $check) = @_; | ||
| 11667 | |||
| 11668 | # Local variables | ||
| 11669 | my ( | ||
| 11670 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11671 | @list, @dataList, | ||
| 11672 | %dataHash, | ||
| 11673 | ); | ||
| 11674 | |||
| 11675 | # Check for improper arguments | ||
| 11676 | if (! defined $item || defined $check) { | ||
| 11677 | |||
| 11678 | return $axmud::CLIENT->writeImproper($self->_objClass . '->chatContactHeader', @_); | ||
| 11679 | } | ||
| 11680 | |||
| 11681 | # Prepare the list of tabs | ||
| 11682 | $tabListRef = [ | ||
| 11683 | 'Chat contact' => '_Chat contact', | ||
| 11684 | ]; | ||
| 11685 | |||
| 11686 | # Prepare the list of column headings | ||
| 11687 | $columnListRef = [ | ||
| 11688 | 'Name' => 'text', | ||
| 11689 | ]; | ||
| 11690 | |||
| 11691 | # Prepare the list of buttons | ||
| 11692 | $buttonListRef = [ | ||
| 11693 | 'Add', 'Add a new chat contact', 'buttonAdd_chatContact', | ||
| 11694 | 'Edit', 'Edit the selected chat contact', 'buttonEdit_chatContact', | ||
| 11695 | 'Delete', 'Delete the selected chat contact', 'buttonDelete_chatContact', | ||
| 11696 | 'Dump', 'Display a list of chat contacts in the \'main\' window', | ||
| 11697 | 'buttonDump_chatContact', | ||
| 11698 | ]; | ||
| 11699 | |||
| 11700 | # Prepare the data to be displayed (there is only one tab) | ||
| 11701 | @list = sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('chatContactHash')); | ||
| 11702 | OUTER: foreach my $obj (@list) { | ||
| 11703 | |||
| 11704 | push (@dataList, [$obj->name]); | ||
| 11705 | } | ||
| 11706 | |||
| 11707 | $dataHash{'Chat contact'} = \@dataList; | ||
| 11708 | $dataHashRef = \%dataHash; | ||
| 11709 | |||
| 11710 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 11711 | # equivalent to the edit button | ||
| 11712 | $self->ivPoke('notebookSelectRef', sub { | ||
| 11713 | |||
| 11714 | $self->buttonEdit_chatContact(); | ||
| 11715 | }); | ||
| 11716 | |||
| 11717 | # Display all of this in the notebook | ||
| 11718 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 11719 | } | ||
| 11720 | |||
| 11721 | sub colourSchemeHeader { | ||
| 11722 | |||
| 11723 | # Called by ->treeViewChanged when the user clicks on the 'Colour schemes' header in the | ||
| 11724 | # treeview | ||
| 11725 | # | ||
| 11726 | # Expected arguments | ||
| 11727 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11728 | # | ||
| 11729 | # Return values | ||
| 11730 | # 'undef' on improper arguments | ||
| 11731 | # 1 otherwise | ||
| 11732 | |||
| 11733 | my ($self, $item, $check) = @_; | ||
| 11734 | |||
| 11735 | # Local variables | ||
| 11736 | my ( | ||
| 11737 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11738 | @list, @dataList, | ||
| 11739 | %dataHash, | ||
| 11740 | ); | ||
| 11741 | |||
| 11742 | # Check for improper arguments | ||
| 11743 | if (! defined $item || defined $check) { | ||
| 11744 | |||
| 11745 | return $axmud::CLIENT->writeImproper($self->_objClass . '->colourSchemeHeader', @_); | ||
| 11746 | } | ||
| 11747 | |||
| 11748 | # Prepare the list of tabs | ||
| 11749 | $tabListRef = [ | ||
| 11750 | 'Colour scheme' => '_Colour scheme', | ||
| 11751 | ]; | ||
| 11752 | |||
| 11753 | # Prepare the list of column headings | ||
| 11754 | $columnListRef = [ | ||
| 11755 | 'Standard' => 'bool', | ||
| 11756 | 'Name' => 'text', | ||
| 11757 | ]; | ||
| 11758 | |||
| 11759 | # Prepare the list of buttons | ||
| 11760 | $buttonListRef = [ | ||
| 11761 | 'Add', 'Add a new colour scheme object', 'buttonAdd_colourScheme', | ||
| 11762 | 'Edit', 'Edit the selected colour scheme object', 'buttonEdit_colourScheme', | ||
| 11763 | 'Delete', 'Delete the selected colour scheme object', 'buttonDelete_colourScheme', | ||
| 11764 | 'Dump', 'Display a list of colour scheme objects in the \'main\' window', | ||
| 11765 | 'buttonDump_colourScheme', | ||
| 11766 | ]; | ||
| 11767 | |||
| 11768 | # Prepare the data to be displayed (there is only one tab) | ||
| 11769 | @list = sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('colourSchemeHash')); | ||
| 11770 | OUTER: foreach my $obj (@list) { | ||
| 11771 | |||
| 11772 | my ($flag, $listRef); | ||
| 11773 | |||
| 11774 | if ( | ||
| 11775 | $axmud::CLIENT->ivExists('constGridWinTypeHash', $obj->name) | ||
| 11776 | || $axmud::CLIENT->ivExists('constFreeWinTypeHash', $obj->name) | ||
| 11777 | ) { | ||
| 11778 | $flag = TRUE; | ||
| 11779 | } else { | ||
| 11780 | $flag = FALSE; | ||
| 11781 | } | ||
| 11782 | |||
| 11783 | $listRef = [$flag, $obj->name]; | ||
| 11784 | push (@dataList, $listRef); | ||
| 11785 | } | ||
| 11786 | |||
| 11787 | $dataHash{'Colour scheme'} = \@dataList; | ||
| 11788 | $dataHashRef = \%dataHash; | ||
| 11789 | |||
| 11790 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 11791 | # equivalent to the edit button | ||
| 11792 | $self->ivPoke('notebookSelectRef', sub { | ||
| 11793 | |||
| 11794 | $self->buttonEdit_colourScheme(); | ||
| 11795 | }); | ||
| 11796 | |||
| 11797 | # Display all of this in the notebook | ||
| 11798 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 11799 | } | ||
| 11800 | |||
| 11801 | sub mapLabelStyleHeader { | ||
| 11802 | |||
| 11803 | # Called by ->treeViewChanged when the user clicks on the 'Map label styles' header in the | ||
| 11804 | # treeview | ||
| 11805 | # | ||
| 11806 | # Expected arguments | ||
| 11807 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11808 | # | ||
| 11809 | # Return values | ||
| 11810 | # 'undef' on improper arguments | ||
| 11811 | # 1 otherwise | ||
| 11812 | |||
| 11813 | my ($self, $item, $check) = @_; | ||
| 11814 | |||
| 11815 | # Local variables | ||
| 11816 | my ( | ||
| 11817 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11818 | @list, @dataList, | ||
| 11819 | %dataHash, | ||
| 11820 | ); | ||
| 11821 | |||
| 11822 | # Check for improper arguments | ||
| 11823 | if (! defined $item || defined $check) { | ||
| 11824 | |||
| 11825 | return $axmud::CLIENT->writeImproper($self->_objClass . '->mapLabelStyleHeader', @_); | ||
| 11826 | } | ||
| 11827 | |||
| 11828 | # Prepare the list of tabs | ||
| 11829 | $tabListRef = [ | ||
| 11830 | 'Map label style' => '_Map label style', | ||
| 11831 | ]; | ||
| 11832 | |||
| 11833 | # Prepare the list of column headings | ||
| 11834 | $columnListRef = [ | ||
| 11835 | 'Default' => 'bool', | ||
| 11836 | 'Name' => 'text', | ||
| 11837 | ]; | ||
| 11838 | |||
| 11839 | # Prepare the list of buttons | ||
| 11840 | $buttonListRef = [ | ||
| 11841 | 'Add', 'Add a new map label style object', 'buttonAdd_mapLabelStyle', | ||
| 11842 | 'Edit', 'Edit the selected map label style object', 'buttonEdit_mapLabelStyle', | ||
| 11843 | 'Rename', 'Rename the selected map label style object', 'buttonRename_mapLabelStyle', | ||
| 11844 | 'Delete', 'Delete the selected map label style object', 'buttonDelete_mapLabelStyle', | ||
| 11845 | 'Dump', 'Display a list of map label style objects in the \'main\' window', | ||
| 11846 | 'buttonDump_mapLabelStyle', | ||
| 11847 | ]; | ||
| 11848 | |||
| 11849 | # Prepare the data to be displayed (there is only one tab) | ||
| 11850 | @list = sort {lc($a->name) cmp lc($b->name)} | ||
| 11851 | ($self->session->worldModelObj->ivValues('mapLabelStyleHash')); | ||
| 11852 | |||
| 11853 | OUTER: foreach my $obj (@list) { | ||
| 11854 | |||
| 11855 | my ($flag, $listRef); | ||
| 11856 | |||
| 11857 | if ($self->session->worldModelObj->mapLabelStyle eq $obj->name) { | ||
| 11858 | $flag = TRUE; | ||
| 11859 | } else { | ||
| 11860 | $flag = FALSE; | ||
| 11861 | } | ||
| 11862 | |||
| 11863 | $listRef = [$flag, $obj->name]; | ||
| 11864 | push (@dataList, $listRef); | ||
| 11865 | } | ||
| 11866 | |||
| 11867 | $dataHash{'Map label style'} = \@dataList; | ||
| 11868 | $dataHashRef = \%dataHash; | ||
| 11869 | |||
| 11870 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 11871 | # equivalent to the edit button | ||
| 11872 | $self->ivPoke('notebookSelectRef', sub { | ||
| 11873 | |||
| 11874 | $self->buttonEdit_mapLabelStyle(); | ||
| 11875 | }); | ||
| 11876 | |||
| 11877 | # Display all of this in the notebook | ||
| 11878 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 11879 | } | ||
| 11880 | |||
| 11881 | sub regionSchemeHeader { | ||
| 11882 | |||
| 11883 | # Called by ->treeViewChanged when the user clicks on the 'Region colour schemes' header in | ||
| 11884 | # the treeview | ||
| 11885 | # | ||
| 11886 | # Expected arguments | ||
| 11887 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11888 | # | ||
| 11889 | # Return values | ||
| 11890 | # 'undef' on improper arguments | ||
| 11891 | # 1 otherwise | ||
| 11892 | |||
| 11893 | my ($self, $item, $check) = @_; | ||
| 11894 | |||
| 11895 | # Local variables | ||
| 11896 | my ( | ||
| 11897 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11898 | @list, @dataList, | ||
| 11899 | %dataHash, | ||
| 11900 | ); | ||
| 11901 | |||
| 11902 | # Check for improper arguments | ||
| 11903 | if (! defined $item || defined $check) { | ||
| 11904 | |||
| 11905 | return $axmud::CLIENT->writeImproper($self->_objClass . '->regionSchemeHeader', @_); | ||
| 11906 | } | ||
| 11907 | |||
| 11908 | # Prepare the list of tabs | ||
| 11909 | $tabListRef = [ | ||
| 11910 | 'Region colour scheme' => '_Region colour scheme', | ||
| 11911 | ]; | ||
| 11912 | |||
| 11913 | # Prepare the list of column headings | ||
| 11914 | $columnListRef = [ | ||
| 11915 | 'Default' => 'bool', | ||
| 11916 | 'Name' => 'text', | ||
| 11917 | ]; | ||
| 11918 | |||
| 11919 | # Prepare the list of buttons | ||
| 11920 | $buttonListRef = [ | ||
| 11921 | 'Add', 'Add a new region colour scheme object', 'buttonAdd_regionScheme', | ||
| 11922 | 'Edit', 'Edit the selected region colour scheme object', 'buttonEdit_regionScheme', | ||
| 11923 | 'Rename', 'Rename the selected region colour scheme object', | ||
| 11924 | 'buttonRename_regionScheme', | ||
| 11925 | 'Delete', 'Delete the selected region colour scheme object', | ||
| 11926 | 'buttonDelete_regionScheme', | ||
| 11927 | 'Dump', 'Display a list of region colour scheme objects in the \'main\' window', | ||
| 11928 | 'buttonDump_regionScheme', | ||
| 11929 | ]; | ||
| 11930 | |||
| 11931 | # Prepare the data to be displayed (there is only one tab) | ||
| 11932 | @list = sort {lc($a->name) cmp lc($b->name)} | ||
| 11933 | ($self->session->worldModelObj->ivValues('regionSchemeHash')); | ||
| 11934 | |||
| 11935 | OUTER: foreach my $obj (@list) { | ||
| 11936 | |||
| 11937 | my ($flag, $listRef); | ||
| 11938 | |||
| 11939 | if ($obj->name eq 'default') { | ||
| 11940 | $flag = TRUE; | ||
| 11941 | } else { | ||
| 11942 | $flag = FALSE; | ||
| 11943 | } | ||
| 11944 | |||
| 11945 | $listRef = [$flag, $obj->name]; | ||
| 11946 | push (@dataList, $listRef); | ||
| 11947 | } | ||
| 11948 | |||
| 11949 | $dataHash{'Region colour scheme'} = \@dataList; | ||
| 11950 | $dataHashRef = \%dataHash; | ||
| 11951 | |||
| 11952 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 11953 | # equivalent to the edit button | ||
| 11954 | $self->ivPoke('notebookSelectRef', sub { | ||
| 11955 | |||
| 11956 | $self->buttonEdit_regionScheme(); | ||
| 11957 | }); | ||
| 11958 | |||
| 11959 | # Display all of this in the notebook | ||
| 11960 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 11961 | } | ||
| 11962 | |||
| 11963 | sub ttsHeader { | ||
| 11964 | |||
| 11965 | # Called by ->treeViewChanged when the user clicks on the 'TTS configurations' header in the | ||
| 11966 | # treeview | ||
| 11967 | # | ||
| 11968 | # Expected arguments | ||
| 11969 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 11970 | # | ||
| 11971 | # Return values | ||
| 11972 | # 'undef' on improper arguments | ||
| 11973 | # 1 otherwise | ||
| 11974 | |||
| 11975 | my ($self, $item, $check) = @_; | ||
| 11976 | |||
| 11977 | # Local variables | ||
| 11978 | my ( | ||
| 11979 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 11980 | @list, @dataList, | ||
| 11981 | %dataHash, | ||
| 11982 | ); | ||
| 11983 | |||
| 11984 | # Check for improper arguments | ||
| 11985 | if (! defined $item || defined $check) { | ||
| 11986 | |||
| 11987 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsHeader', @_); | ||
| 11988 | } | ||
| 11989 | |||
| 11990 | # Prepare the list of tabs | ||
| 11991 | $tabListRef = [ | ||
| 11992 | 'TTS configuration' => '_TTS configuration', | ||
| 11993 | ]; | ||
| 11994 | |||
| 11995 | # Prepare the list of column headings | ||
| 11996 | $columnListRef = [ | ||
| 11997 | 'Name' => 'text', | ||
| 11998 | 'Engine' => 'text', | ||
| 11999 | 'Voice' => 'text', | ||
| 12000 | ]; | ||
| 12001 | |||
| 12002 | # Prepare the list of buttons | ||
| 12003 | $buttonListRef = [ | ||
| 12004 | 'Add', 'Add a new TTS configuration', 'buttonAdd_tts', | ||
| 12005 | 'Clone', 'Clone the selected TTS configuration', 'buttonClone_tts', | ||
| 12006 | 'Edit', 'Edit the selected TTS configuration', 'buttonEdit_tts', | ||
| 12007 | 'Delete', 'Delete the selected TTS configuration', 'buttonDelete_tts', | ||
| 12008 | 'Dump', 'Display a list of TTS configurations in the \'main\' window', 'buttonDump_tts', | ||
| 12009 | ]; | ||
| 12010 | |||
| 12011 | # Prepare the data to be displayed (there is only one tab) | ||
| 12012 | @list = sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('ttsObjHash')); | ||
| 12013 | OUTER: foreach my $obj (@list) { | ||
| 12014 | |||
| 12015 | my $listRef = [$obj->name, $obj->engine, $obj->voice]; | ||
| 12016 | push (@dataList, $listRef); | ||
| 12017 | } | ||
| 12018 | |||
| 12019 | $dataHash{'TTS configuration'} = \@dataList; | ||
| 12020 | $dataHashRef = \%dataHash; | ||
| 12021 | |||
| 12022 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 12023 | # equivalent to the edit button | ||
| 12024 | $self->ivPoke('notebookSelectRef', sub { | ||
| 12025 | |||
| 12026 | $self->buttonEdit_tts(); | ||
| 12027 | }); | ||
| 12028 | |||
| 12029 | # Display all of this in the notebook | ||
| 12030 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 12031 | } | ||
| 12032 | |||
| 12033 | sub winmapHeader { | ||
| 12034 | |||
| 12035 | # Called by ->treeViewChanged when the user clicks on the 'Winmaps' header in the treeview | ||
| 12036 | # | ||
| 12037 | # Expected arguments | ||
| 12038 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12039 | # | ||
| 12040 | # Return values | ||
| 12041 | # 'undef' on improper arguments | ||
| 12042 | # 1 otherwise | ||
| 12043 | |||
| 12044 | my ($self, $item, $check) = @_; | ||
| 12045 | |||
| 12046 | # Local variables | ||
| 12047 | my ( | ||
| 12048 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 12049 | @list, @dataList, | ||
| 12050 | %dataHash, | ||
| 12051 | ); | ||
| 12052 | |||
| 12053 | # Check for improper arguments | ||
| 12054 | if (! defined $item || defined $check) { | ||
| 12055 | |||
| 12056 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winmapHeader', @_); | ||
| 12057 | } | ||
| 12058 | |||
| 12059 | # Prepare the list of tabs | ||
| 12060 | $tabListRef = [ | ||
| 12061 | 'Winmap' => '_Winmap', | ||
| 12062 | ]; | ||
| 12063 | |||
| 12064 | # Prepare the list of column headings | ||
| 12065 | $columnListRef = [ | ||
| 12066 | 'Standard' => 'bool', | ||
| 12067 | 'Full' => 'bool', | ||
| 12068 | 'Name' => 'text', | ||
| 12069 | ]; | ||
| 12070 | |||
| 12071 | # Prepare the list of buttons | ||
| 12072 | $buttonListRef = [ | ||
| 12073 | 'Add', 'Add a new winmap', 'buttonAdd_winmap', | ||
| 12074 | 'Clone', 'Clone the selected winmap', 'buttonClone_winmap', | ||
| 12075 | 'Edit', 'Edit the selected winmap', 'buttonEdit_winmap', | ||
| 12076 | 'Delete', 'Delete the selected winmap', 'buttonDelete_winmap', | ||
| 12077 | 'Dump', 'Display a list of winmaps in the \'main\' window', 'buttonDump_winmap', | ||
| 12078 | ]; | ||
| 12079 | |||
| 12080 | # Prepare the data to be displayed (there is only one tab) | ||
| 12081 | @list = sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('winmapHash')); | ||
| 12082 | OUTER: foreach my $obj (@list) { | ||
| 12083 | |||
| 12084 | my ($flag, $listRef); | ||
| 12085 | |||
| 12086 | if ($axmud::CLIENT->ivExists('standardWinmapHash', $obj->name)) { | ||
| 12087 | $flag = TRUE; | ||
| 12088 | } else { | ||
| 12089 | $flag = FALSE; | ||
| 12090 | } | ||
| 12091 | |||
| 12092 | $listRef = [$flag, $obj->fullFlag, $obj->name]; | ||
| 12093 | push (@dataList, $listRef); | ||
| 12094 | } | ||
| 12095 | |||
| 12096 | $dataHash{'Winmap'} = \@dataList; | ||
| 12097 | $dataHashRef = \%dataHash; | ||
| 12098 | |||
| 12099 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 12100 | # equivalent to the edit button | ||
| 12101 | $self->ivPoke('notebookSelectRef', sub { | ||
| 12102 | |||
| 12103 | $self->buttonEdit_winmap(); | ||
| 12104 | }); | ||
| 12105 | |||
| 12106 | # Display all of this in the notebook | ||
| 12107 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 12108 | } | ||
| 12109 | |||
| 12110 | sub zonemapHeader { | ||
| 12111 | |||
| 12112 | # Called by ->treeViewChanged when the user clicks on the 'Zonemaps' header in the treeview | ||
| 12113 | # | ||
| 12114 | # Expected arguments | ||
| 12115 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12116 | # | ||
| 12117 | # Return values | ||
| 12118 | # 'undef' on improper arguments | ||
| 12119 | # 1 otherwise | ||
| 12120 | |||
| 12121 | my ($self, $item, $check) = @_; | ||
| 12122 | |||
| 12123 | # Local variables | ||
| 12124 | my ( | ||
| 12125 | $tabListRef, $columnListRef, $dataHashRef, $buttonListRef, | ||
| 12126 | @list, @dataList, | ||
| 12127 | %dataHash, | ||
| 12128 | ); | ||
| 12129 | |||
| 12130 | # Check for improper arguments | ||
| 12131 | if (! defined $item || defined $check) { | ||
| 12132 | |||
| 12133 | return $axmud::CLIENT->writeImproper($self->_objClass . '->zonemapHeader', @_); | ||
| 12134 | } | ||
| 12135 | |||
| 12136 | # Prepare the list of tabs | ||
| 12137 | $tabListRef = [ | ||
| 12138 | 'Zonemap' => '_Zonemap', | ||
| 12139 | ]; | ||
| 12140 | |||
| 12141 | # Prepare the list of column headings | ||
| 12142 | $columnListRef = [ | ||
| 12143 | 'Standard' => 'bool', | ||
| 12144 | 'Full' => 'bool', | ||
| 12145 | 'Temporary' => 'bool', | ||
| 12146 | 'Name' => 'text', | ||
| 12147 | ]; | ||
| 12148 | |||
| 12149 | # Prepare the list of buttons | ||
| 12150 | $buttonListRef = [ | ||
| 12151 | 'Add', 'Add a new zonemap', 'buttonAdd_zonemap', | ||
| 12152 | 'Clone', 'Clone the selected zonemap', 'buttonClone_zonemap', | ||
| 12153 | 'Edit', 'Edit the selected zonemap', 'buttonEdit_zonemap', | ||
| 12154 | 'Delete', 'Delete the selected zonemap', 'buttonDelete_zonemap', | ||
| 12155 | 'Dump', 'Display a list of zonemaps in the \'main\' window', 'buttonDump_zonemap', | ||
| 12156 | ]; | ||
| 12157 | |||
| 12158 | # Prepare the data to be displayed (there is only one tab) | ||
| 12159 | @list = sort {lc($a->name) cmp lc($b->name)} ($axmud::CLIENT->ivValues('zonemapHash')); | ||
| 12160 | OUTER: foreach my $obj (@list) { | ||
| 12161 | |||
| 12162 | my ($flag, $listRef); | ||
| 12163 | |||
| 12164 | if ($axmud::CLIENT->ivExists('standardZonemapHash', $obj->name)) { | ||
| 12165 | $flag = TRUE; | ||
| 12166 | } else { | ||
| 12167 | $flag = FALSE; | ||
| 12168 | } | ||
| 12169 | |||
| 12170 | $listRef = [$flag, $obj->fullFlag, $obj->tempFlag, $obj->name]; | ||
| 12171 | push (@dataList, $listRef); | ||
| 12172 | } | ||
| 12173 | |||
| 12174 | $dataHash{'Zonemap'} = \@dataList; | ||
| 12175 | $dataHashRef = \%dataHash; | ||
| 12176 | |||
| 12177 | # Which function to call if the user double-clicks on a row in the list - in this case, it's | ||
| 12178 | # equivalent to the edit button | ||
| 12179 | $self->ivPoke('notebookSelectRef', sub { | ||
| 12180 | |||
| 12181 | $self->buttonEdit_zonemap(); | ||
| 12182 | }); | ||
| 12183 | |||
| 12184 | # Display all of this in the notebook | ||
| 12185 | return $self->refreshNotebook($tabListRef, $columnListRef, $dataHashRef, $buttonListRef); | ||
| 12186 | } | ||
| 12187 | |||
| 12188 | # Treeview header responses - help | ||
| 12189 | |||
| 12190 | sub quickHelpHeader { | ||
| 12191 | |||
| 12192 | # Called by ->treeViewChanged when the user clicks on one of the quick help item in the | ||
| 12193 | # treeview | ||
| 12194 | # | ||
| 12195 | # Expected arguments | ||
| 12196 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12197 | # | ||
| 12198 | # Return values | ||
| 12199 | # 'undef' on improper arguments | ||
| 12200 | # 1 otherwise | ||
| 12201 | |||
| 12202 | my ($self, $item, $check) = @_; | ||
| 12203 | |||
| 12204 | # Local variables | ||
| 12205 | my ( | ||
| 12206 | $file, $fileHandle, | ||
| 12207 | @list, | ||
| 12208 | ); | ||
| 12209 | |||
| 12210 | # Check for improper arguments | ||
| 12211 | if (! defined $item || defined $check) { | ||
| 12212 | |||
| 12213 | return $axmud::CLIENT->writeImproper($self->_objClass . '->quickHelpHeader', @_); | ||
| 12214 | } | ||
| 12215 | |||
| 12216 | # Load the quick help file | ||
| 12217 | $file = $axmud::SHARE_DIR . '/help/misc/quickhelp'; | ||
| 12218 | if (-e $file && open($fileHandle, $file)) { | ||
| 12219 | |||
| 12220 | @list = <$fileHandle>; | ||
| 12221 | close($fileHandle); | ||
| 12222 | |||
| 12223 | foreach my $item (@list) { | ||
| 12224 | |||
| 12225 | chomp $item; | ||
| 12226 | } | ||
| 12227 | } | ||
| 12228 | |||
| 12229 | # Display the help in the notebook | ||
| 12230 | return $self->refreshTextView($item, @list); | ||
| 12231 | } | ||
| 12232 | |||
| 12233 | sub peekPokeHelpHeader { | ||
| 12234 | |||
| 12235 | # Called by ->treeViewChanged when the user clicks on one of the peek/poke help item in the | ||
| 12236 | # treeview | ||
| 12237 | # | ||
| 12238 | # Expected arguments | ||
| 12239 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12240 | # | ||
| 12241 | # Return values | ||
| 12242 | # 'undef' on improper arguments | ||
| 12243 | # 1 otherwise | ||
| 12244 | |||
| 12245 | my ($self, $item, $check) = @_; | ||
| 12246 | |||
| 12247 | # Local variables | ||
| 12248 | my ( | ||
| 12249 | $file, $fileHandle, | ||
| 12250 | @list, | ||
| 12251 | ); | ||
| 12252 | |||
| 12253 | # Check for improper arguments | ||
| 12254 | if (! defined $item || defined $check) { | ||
| 12255 | |||
| 12256 | return $axmud::CLIENT->writeImproper($self->_objClass . '->peekPokeHelpHeader', @_); | ||
| 12257 | } | ||
| 12258 | |||
| 12259 | # Load the quick help file | ||
| 12260 | $file = $axmud::SHARE_DIR . '/help/misc/peekpoke'; | ||
| 12261 | if (-e $file && open($fileHandle, $file)) { | ||
| 12262 | |||
| 12263 | @list = <$fileHandle>; | ||
| 12264 | close($fileHandle); | ||
| 12265 | |||
| 12266 | foreach my $item (@list) { | ||
| 12267 | |||
| 12268 | chomp $item; | ||
| 12269 | } | ||
| 12270 | } | ||
| 12271 | |||
| 12272 | # Display the help in the notebook | ||
| 12273 | return $self->refreshTextView($item, @list); | ||
| 12274 | } | ||
| 12275 | |||
| 12276 | sub cmdHeader { | ||
| 12277 | |||
| 12278 | # Called by ->treeViewChanged when the user clicks on one of the client commands in the | ||
| 12279 | # treeview | ||
| 12280 | # | ||
| 12281 | # Expected arguments | ||
| 12282 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12283 | # | ||
| 12284 | # Return values | ||
| 12285 | # 'undef' on improper arguments | ||
| 12286 | # 1 otherwise | ||
| 12287 | |||
| 12288 | my ($self, $item, $check) = @_; | ||
| 12289 | |||
| 12290 | # Local variables | ||
| 12291 | my ( | ||
| 12292 | $cmd, $obj, | ||
| 12293 | @list, | ||
| 12294 | ); | ||
| 12295 | |||
| 12296 | # Check for improper arguments | ||
| 12297 | if (! defined $item || defined $check) { | ||
| 12298 | |||
| 12299 | return $axmud::CLIENT->writeImproper($self->_objClass . '->cmdHeader', @_); | ||
| 12300 | } | ||
| 12301 | |||
| 12302 | # Remove the command sigil from the beginning of $item | ||
| 12303 | $cmd = substr($item, length($axmud::CLIENT->cmdSep)); | ||
| 12304 | # Get the blessed reference of the command object for this command | ||
| 12305 | $obj = $axmud::CLIENT->ivShow('clientCmdHash', $cmd); | ||
| 12306 | |||
| 12307 | # Get the first three lines of the help text | ||
| 12308 | push (@list, $obj->getHelpStart()); | ||
| 12309 | # Call the help function for the command to fetch the command-specific text | ||
| 12310 | push (@list, $obj->help($self->session)); | ||
| 12311 | # Fetch the final three lines of the help text; add an extra blank line | ||
| 12312 | push (@list, $obj->getHelpEnd(), ' '); | ||
| 12313 | |||
| 12314 | # (Do nothing when a line is double-clicked) | ||
| 12315 | |||
| 12316 | # Display the help in the notebook | ||
| 12317 | return $self->refreshTextView($item, @list); | ||
| 12318 | } | ||
| 12319 | |||
| 12320 | sub axbasicKeywordHeader { | ||
| 12321 | |||
| 12322 | # Called by ->treeViewChanged when the user clicks on one of the Axbasic keyword help topics | ||
| 12323 | # in the treeview | ||
| 12324 | # | ||
| 12325 | # Expected arguments | ||
| 12326 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12327 | # | ||
| 12328 | # Return values | ||
| 12329 | # 'undef' on improper arguments | ||
| 12330 | # 1 otherwise | ||
| 12331 | |||
| 12332 | my ($self, $item, $check) = @_; | ||
| 12333 | |||
| 12334 | # Local variables | ||
| 12335 | my ( | ||
| 12336 | $obj, | ||
| 12337 | @list, | ||
| 12338 | ); | ||
| 12339 | |||
| 12340 | # Check for improper arguments | ||
| 12341 | if (! defined $item || defined $check) { | ||
| 12342 | |||
| 12343 | return $axmud::CLIENT->writeImproper($self->_objClass . '->axbasicKeywordHeader', @_); | ||
| 12344 | } | ||
| 12345 | |||
| 12346 | # Get the ';axbasichelp' command object (rather than going through GA::Generic::Cmd) | ||
| 12347 | $obj = $axmud::CLIENT->ivShow('clientCmdHash', 'axbasichelp'); | ||
| 12348 | # If $item is a weak keyword, then we use the help file for the equivalent strong keyword | ||
| 12349 | # (e.g. use help for OPEN rather than ACCESS) | ||
| 12350 | if ($self->dummyScriptObj->ivExists('weakKeywordHash', $item)) { | ||
| 12351 | |||
| 12352 | $item = $self->dummyScriptObj->ivShow('weakKeywordHash', $item); | ||
| 12353 | } | ||
| 12354 | |||
| 12355 | # Get the help for the keyword $item | ||
| 12356 | @list = $obj->abHelp($self->session, $item, 'keyword'); | ||
| 12357 | |||
| 12358 | # (Do nothing when a line is double-clicked) | ||
| 12359 | |||
| 12360 | # Display the help in the notebook | ||
| 12361 | return $self->refreshTextView($item, @list); | ||
| 12362 | } | ||
| 12363 | |||
| 12364 | sub axbasicFuncHeader { | ||
| 12365 | |||
| 12366 | # Called by ->treeViewChanged when the user clicks on one of the Axbasic intrinsic function | ||
| 12367 | # help topics in the treeview | ||
| 12368 | # | ||
| 12369 | # Expected arguments | ||
| 12370 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12371 | # | ||
| 12372 | # Return values | ||
| 12373 | # 'undef' on improper arguments | ||
| 12374 | # 1 otherwise | ||
| 12375 | |||
| 12376 | my ($self, $item, $check) = @_; | ||
| 12377 | |||
| 12378 | # Local variables | ||
| 12379 | my ( | ||
| 12380 | $obj, | ||
| 12381 | @list, | ||
| 12382 | ); | ||
| 12383 | |||
| 12384 | # Check for improper arguments | ||
| 12385 | if (! defined $item || defined $check) { | ||
| 12386 | |||
| 12387 | return $axmud::CLIENT->writeImproper($self->_objClass . '->axbasicFuncHeader', @_); | ||
| 12388 | } | ||
| 12389 | |||
| 12390 | # Get the ';axbasichelp' command object (rather than going through GA::Generic::Cmd) | ||
| 12391 | $obj = $axmud::CLIENT->ivShow('clientCmdHash', 'axbasichelp'); | ||
| 12392 | # Get the help for the keyword $item | ||
| 12393 | @list = $obj->abHelp($self->session, $item, 'func'); | ||
| 12394 | |||
| 12395 | # (Do nothing when a line is double-clicked) | ||
| 12396 | |||
| 12397 | # Display the help in the notebook | ||
| 12398 | return $self->refreshTextView($item, @list); | ||
| 12399 | } | ||
| 12400 | |||
| 12401 | sub taskHeader { | ||
| 12402 | |||
| 12403 | # Called by ->treeViewChanged when the user clicks on one of the tasks in the treeview | ||
| 12404 | # | ||
| 12405 | # Expected arguments | ||
| 12406 | # $item - The treeview item that was clicked (i.e. the text it contains) | ||
| 12407 | # | ||
| 12408 | # Return values | ||
| 12409 | # 'undef' on improper arguments | ||
| 12410 | # 1 otherwise | ||
| 12411 | |||
| 12412 | my ($self, $item, $check) = @_; | ||
| 12413 | |||
| 12414 | # Local variables | ||
| 12415 | my ( | ||
| 12416 | $cmdObj, $packageName, | ||
| 12417 | @list, | ||
| 12418 | ); | ||
| 12419 | |||
| 12420 | # Check for improper arguments | ||
| 12421 | if (! defined $item || defined $check) { | ||
| 12422 | |||
| 12423 | return $axmud::CLIENT->writeImproper($self->_objClass . '->taskHeader', @_); | ||
| 12424 | } | ||
| 12425 | |||
| 12426 | # Get the ';taskhelp' command object (rather than going through GA::Generic::Cmd) | ||
| 12427 | $cmdObj = $axmud::CLIENT->ivShow('clientCmdHash', 'taskhelp'); | ||
| 12428 | |||
| 12429 | # Get the package name for the task | ||
| 12430 | $packageName = $cmdObj->findTaskPackageName($self->session, $item); | ||
| 12431 | # Remove the 'Games::Axmud::Task::' bit... | ||
| 12432 | $packageName =~ s/^Games\:\:Axmud\:\:Task\:\://; | ||
| 12433 | # Get the help for the task | ||
| 12434 | @list = $cmdObj->taskHelp($self->session, $packageName); | ||
| 12435 | |||
| 12436 | # (Do nothing when a line is double-clicked) | ||
| 12437 | |||
| 12438 | # Display the help in the notebook | ||
| 12439 | return $self->refreshTextView($packageName, @list); | ||
| 12440 | } | ||
| 12441 | |||
| 12442 | # Header support functions | ||
| 12443 | |||
| 12444 | sub setTabList_prof { | ||
| 12445 | |||
| 12446 | # Called by $self->allProfHeader and ->currentProfHeader | ||
| 12447 | # Sets up the list of tabs appropriate for displaying profiles in the notebook list, in the | ||
| 12448 | # form | ||
| 12449 | # [ | ||
| 12450 | # 'tab_name' => 'tab_mnemonic', | ||
| 12451 | # 'tab_name' => 'tab_mnemonic', | ||
| 12452 | # 'tab_name' => 'tab_mnemonic', | ||
| 12453 | # ... | ||
| 12454 | # ] | ||
| 12455 | # | ||
| 12456 | # Expected arguments | ||
| 12457 | # (none besides $self) | ||
| 12458 | # | ||
| 12459 | # Return values | ||
| 12460 | # An empty list on improper arguments | ||
| 12461 | # Otherwise returns a list containing two list references: | ||
| 12462 | # - the first is the list described above | ||
| 12463 | # - the second is a list of 'tab_name's | ||
| 12464 | |||
| 12465 | my ($self, $check) = @_; | ||
| 12466 | |||
| 12467 | # Local variables | ||
| 12468 | my ( | ||
| 12469 | @emptyList, @categoryList, @tabList, | ||
| 12470 | %mnemonicHash, | ||
| 12471 | ); | ||
| 12472 | |||
| 12473 | # Check for improper arguments | ||
| 12474 | if (defined $check) { | ||
| 12475 | |||
| 12476 | $axmud::CLIENT->writeImproper($self->_objClass . '->setTabList_prof', @_); | ||
| 12477 | return @emptyList; | ||
| 12478 | } | ||
| 12479 | |||
| 12480 | # Display the tabs in reverse priority order (i.e. so that 'world' is always first) | ||
| 12481 | @categoryList = reverse $self->session->profPriorityList; | ||
| 12482 | foreach my $category (@categoryList) { | ||
| 12483 | |||
| 12484 | # Add to the list the pair 'world' and 'W_orld', the pair 'char' and 'C_har', etc | ||
| 12485 | push ( | ||
| 12486 | @tabList, | ||
| 12487 | $category, | ||
| 12488 | $self->getMnemonic(ucfirst($category), \%mnemonicHash), | ||
| 12489 | ); | ||
| 12490 | } | ||
| 12491 | |||
| 12492 | return (\@tabList, \@categoryList); | ||
| 12493 | } | ||
| 12494 | |||
| 12495 | sub setColumnList_prof { | ||
| 12496 | |||
| 12497 | # Called by $self->allProfHeader and ->currentProfHeader | ||
| 12498 | # Sets up the list of column titles appropriate for displaying profiles in the notebook | ||
| 12499 | # list, in the form | ||
| 12500 | # [ | ||
| 12501 | # 'column_name' => 'type', | ||
| 12502 | # 'column_name' => 'type', | ||
| 12503 | # 'column_name' => 'type', | ||
| 12504 | # ... | ||
| 12505 | # ] | ||
| 12506 | # | ||
| 12507 | # Expected arguments | ||
| 12508 | # (none besides $self) | ||
| 12509 | # | ||
| 12510 | # Return values | ||
| 12511 | # 'undef' on improper arguments | ||
| 12512 | # Otherwise returns a reference to the list described above | ||
| 12513 | |||
| 12514 | my ($self, $check) = @_; | ||
| 12515 | |||
| 12516 | # Local variables | ||
| 12517 | my @list; | ||
| 12518 | |||
| 12519 | # Check for improper arguments | ||
| 12520 | if (defined $check) { | ||
| 12521 | |||
| 12522 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setColumnList_prof', @_); | ||
| 12523 | } | ||
| 12524 | |||
| 12525 | @list = ( | ||
| 12526 | 'Current' => 'bool', | ||
| 12527 | 'Profile Name' => 'text', | ||
| 12528 | 'Category' => 'text', | ||
| 12529 | ); | ||
| 12530 | |||
| 12531 | return \@list; | ||
| 12532 | } | ||
| 12533 | |||
| 12534 | sub setButtonList_prof { | ||
| 12535 | |||
| 12536 | # Called by $self->allProfHeader and ->currentProfHeader | ||
| 12537 | # Sets up the list of buttons appropriate for manipulating profiles in the notebook list, | ||
| 12538 | # in the form | ||
| 12539 | # [ | ||
| 12540 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12541 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12542 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12543 | # ... | ||
| 12544 | # ] | ||
| 12545 | # | ||
| 12546 | # Expected arguments | ||
| 12547 | # (none besides $self) | ||
| 12548 | # | ||
| 12549 | # Return values | ||
| 12550 | # 'undef' on improper arguments | ||
| 12551 | # Otherwise returns a reference to the list described above | ||
| 12552 | |||
| 12553 | my ($self, $check) = @_; | ||
| 12554 | |||
| 12555 | # Local variables | ||
| 12556 | my @list; | ||
| 12557 | |||
| 12558 | # Check for improper arguments | ||
| 12559 | if (defined $check) { | ||
| 12560 | |||
| 12561 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setButtonList_prof', @_); | ||
| 12562 | } | ||
| 12563 | |||
| 12564 | @list = ( | ||
| 12565 | 'Add', 'Add a new profile', 'buttonAdd_prof', | ||
| 12566 | 'Edit', 'Edit the selected profile', 'buttonEdit_prof', | ||
| 12567 | 'Set current', 'Set a current profile', 'buttonSet_prof', | ||
| 12568 | 'Unset current', 'Unset the current profile', 'buttonUnset_prof', | ||
| 12569 | 'Clone', 'Clone the selected profile', 'buttonClone_prof', | ||
| 12570 | 'Delete', 'Delete the selected profile', 'buttonDelete_prof', | ||
| 12571 | 'Dump', 'Display this list of profiles in the \'main\' window', 'buttonDump_prof', | ||
| 12572 | 'Dump all', 'Display a list of all profiles in the \'main\' window', | ||
| 12573 | 'buttonDumpAll_prof', | ||
| 12574 | ); | ||
| 12575 | |||
| 12576 | return \@list; | ||
| 12577 | } | ||
| 12578 | |||
| 12579 | sub compileList_profPriority { | ||
| 12580 | |||
| 12581 | # Called by $self->profPriorityHeader | ||
| 12582 | # Compiles the data to be displayed in a Gtk3::SimpleList, and converts it into a reference | ||
| 12583 | # to a hash | ||
| 12584 | # | ||
| 12585 | # Expected arguments | ||
| 12586 | # (none besides $self) | ||
| 12587 | # | ||
| 12588 | # Return values | ||
| 12589 | # 'undef' on improper arguments | ||
| 12590 | # Otherwise returns a reference to the has described above | ||
| 12591 | |||
| 12592 | my ($self, $check) = @_; | ||
| 12593 | |||
| 12594 | # Local variables | ||
| 12595 | my ( | ||
| 12596 | $count, $dataHashRef, | ||
| 12597 | @dataList, @otherList, | ||
| 12598 | %dataHash, | ||
| 12599 | ); | ||
| 12600 | |||
| 12601 | # Check for improper arguments | ||
| 12602 | if (defined $check) { | ||
| 12603 | |||
| 12604 | return $axmud::CLIENT->writeImproper( | ||
| 12605 | $self->_objClass . '->compileList_profPriority', | ||
| 12606 | @_, | ||
| 12607 | ); | ||
| 12608 | } | ||
| 12609 | |||
| 12610 | # A numbered list of categories comes first, containing everything in | ||
| 12611 | # $self->session->profPriorityList | ||
| 12612 | # Then follows an unnumbered list of any remaining categories which aren't in the priority | ||
| 12613 | # list | ||
| 12614 | |||
| 12615 | # Numbered categories (in priority list) | ||
| 12616 | $count = 0; | ||
| 12617 | OUTER: foreach my $category ($self->session->profPriorityList) { | ||
| 12618 | |||
| 12619 | my $listRef; | ||
| 12620 | |||
| 12621 | $count++; | ||
| 12622 | $listRef = [$count, $category]; | ||
| 12623 | push (@dataList, $listRef); | ||
| 12624 | } | ||
| 12625 | |||
| 12626 | # Unnumbered categories (not in priority list). Compile a list of unnumbered categories. | ||
| 12627 | # First check the default priority list | ||
| 12628 | OUTER: foreach my $defaultCategory ($axmud::CLIENT->constProfPriorityList) { | ||
| 12629 | |||
| 12630 | INNER: foreach my $numberedCategory ($self->session->profPriorityList) { | ||
| 12631 | |||
| 12632 | if ($defaultCategory eq $numberedCategory) { | ||
| 12633 | |||
| 12634 | next OUTER; | ||
| 12635 | } | ||
| 12636 | } | ||
| 12637 | |||
| 12638 | # One of the default categories (world, guild, race, char) is missing from the priority | ||
| 12639 | # list | ||
| 12640 | push (@otherList, $defaultCategory); | ||
| 12641 | } | ||
| 12642 | |||
| 12643 | # Next check profile template categories | ||
| 12644 | OUTER: foreach my $category ($self->session->ivKeys('templateHash')) { | ||
| 12645 | |||
| 12646 | INNER: foreach my $numberedCategory ($self->session->profPriorityList) { | ||
| 12647 | |||
| 12648 | if ($category eq $numberedCategory) { | ||
| 12649 | |||
| 12650 | next OUTER; | ||
| 12651 | } | ||
| 12652 | } | ||
| 12653 | |||
| 12654 | # This template category is missing from the priority list | ||
| 12655 | push (@otherList, $category); | ||
| 12656 | } | ||
| 12657 | |||
| 12658 | # Add the unnumbered categories to the displayed list | ||
| 12659 | @otherList = sort {lc($a) cmp lc($b)} (@otherList); | ||
| 12660 | foreach my $category (@otherList) { | ||
| 12661 | |||
| 12662 | my $listRef = ['-', $category]; | ||
| 12663 | push (@dataList, $listRef); | ||
| 12664 | } | ||
| 12665 | |||
| 12666 | # Display the list | ||
| 12667 | $dataHash{'Profile priority list'} = \@dataList; | ||
| 12668 | $dataHashRef = \%dataHash; | ||
| 12669 | |||
| 12670 | return $dataHashRef; | ||
| 12671 | } | ||
| 12672 | |||
| 12673 | sub setTabList_cage { | ||
| 12674 | |||
| 12675 | # Called by $self->allCageHeader and ->currentCageHeader | ||
| 12676 | # Sets up the list of tabs appropriate for displaying cages in the notebook list, in the | ||
| 12677 | # form | ||
| 12678 | # [ | ||
| 12679 | # 'tab_name' => 'tab_mnemonic', | ||
| 12680 | # 'tab_name' => 'tab_mnemonic', | ||
| 12681 | # 'tab_name' => 'tab_mnemonic', | ||
| 12682 | # ... | ||
| 12683 | # ] | ||
| 12684 | # | ||
| 12685 | # Expected arguments | ||
| 12686 | # (none besides $self) | ||
| 12687 | # | ||
| 12688 | # Return values | ||
| 12689 | # An empty list on improper arguments | ||
| 12690 | # Otherwise returns a list containing two list references: | ||
| 12691 | # - the first is the list described above | ||
| 12692 | # - the second is a list of 'tab_name's | ||
| 12693 | |||
| 12694 | my ($self, $check) = @_; | ||
| 12695 | |||
| 12696 | # Local variables | ||
| 12697 | my ( | ||
| 12698 | @emptyList, @tabList, @typeList, | ||
| 12699 | %mnemonicHash, | ||
| 12700 | ); | ||
| 12701 | |||
| 12702 | # Check for improper arguments | ||
| 12703 | if (defined $check) { | ||
| 12704 | |||
| 12705 | $axmud::CLIENT->writeImproper($self->_objClass . '->setTabList_cage', @_); | ||
| 12706 | return @emptyList; | ||
| 12707 | } | ||
| 12708 | |||
| 12709 | foreach my $type ($axmud::CLIENT->cageTypeList) { | ||
| 12710 | |||
| 12711 | # Add to the list the pair 'trigger' and 't_rigger', the pair 'alias' and 'a_lias', etc | ||
| 12712 | push ( | ||
| 12713 | @tabList, | ||
| 12714 | lc($type), | ||
| 12715 | $self->getMnemonic($type, \%mnemonicHash), | ||
| 12716 | ); | ||
| 12717 | |||
| 12718 | # Everything in @list is upper-case, so reduce it to lower-case | ||
| 12719 | push (@typeList, lc($type)); | ||
| 12720 | } | ||
| 12721 | |||
| 12722 | return (\@tabList, \@typeList); | ||
| 12723 | } | ||
| 12724 | |||
| 12725 | sub setColumnList_cage { | ||
| 12726 | |||
| 12727 | # Called by $self->allCageHeader and ->currentCageHeader | ||
| 12728 | # Sets up the list of column titles appropriate for displaying cages in the notebook list, | ||
| 12729 | # in the form | ||
| 12730 | # [ | ||
| 12731 | # 'column_name' => 'type', | ||
| 12732 | # 'column_name' => 'type', | ||
| 12733 | # 'column_name' => 'type', | ||
| 12734 | # ... | ||
| 12735 | # ] | ||
| 12736 | # | ||
| 12737 | # Expected arguments | ||
| 12738 | # (none besides $self) | ||
| 12739 | # | ||
| 12740 | # Return values | ||
| 12741 | # 'undef' on improper arguments | ||
| 12742 | # Otherwise returns a reference to the list described above | ||
| 12743 | |||
| 12744 | my ($self, $check) = @_; | ||
| 12745 | |||
| 12746 | # Local variables | ||
| 12747 | my @list; | ||
| 12748 | |||
| 12749 | # Check for improper arguments | ||
| 12750 | if (defined $check) { | ||
| 12751 | |||
| 12752 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setColumnList_cage', @_); | ||
| 12753 | } | ||
| 12754 | |||
| 12755 | @list = ( | ||
| 12756 | 'Current' => 'bool', | ||
| 12757 | 'Cage Name' => 'text', | ||
| 12758 | ); | ||
| 12759 | |||
| 12760 | return \@list; | ||
| 12761 | } | ||
| 12762 | |||
| 12763 | sub setButtonList_cage { | ||
| 12764 | |||
| 12765 | # Called by $self->allCageHeader and ->currentCageHeader | ||
| 12766 | # Sets up the list of buttons appropriate for manipulating cages in the notebook list, in | ||
| 12767 | # the form | ||
| 12768 | # [ | ||
| 12769 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12770 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12771 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12772 | # ... | ||
| 12773 | # ] | ||
| 12774 | # | ||
| 12775 | # Expected arguments | ||
| 12776 | # (none besides $self) | ||
| 12777 | # | ||
| 12778 | # Return values | ||
| 12779 | # 'undef' on improper arguments | ||
| 12780 | # Otherwise returns a reference to the list described above | ||
| 12781 | |||
| 12782 | my ($self, $check) = @_; | ||
| 12783 | |||
| 12784 | # Local variables | ||
| 12785 | my @list; | ||
| 12786 | |||
| 12787 | # Check for improper arguments | ||
| 12788 | |||
| 12789 | if (defined $check) { | ||
| 12790 | |||
| 12791 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setButtonList_cage', @_); | ||
| 12792 | } | ||
| 12793 | |||
| 12794 | @list = ( | ||
| 12795 | 'Edit', 'Edit the selected cage', 'buttonEdit_cage', | ||
| 12796 | 'Dump', 'Display this list of cages in the \'main\' window', 'buttonDump_cage', | ||
| 12797 | 'Dump all', 'Display a list of all cages in the \'main\' window', 'buttonDumpAll_cage', | ||
| 12798 | ); | ||
| 12799 | |||
| 12800 | return \@list; | ||
| 12801 | } | ||
| 12802 | |||
| 12803 | sub getSortedCages { | ||
| 12804 | |||
| 12805 | # Called by $self->allCageHeader and $self->currentCageHeader | ||
| 12806 | # Returns a list of cages to be displayed in a single tab, sorted in the priority order of | ||
| 12807 | # each cage's associated profile | ||
| 12808 | # | ||
| 12809 | # Expected arguments | ||
| 12810 | # $tab - The name of the tab, which corresponds to a profile category ('world', 'char', | ||
| 12811 | # etc) | ||
| 12812 | # | ||
| 12813 | # Return values | ||
| 12814 | # An empty list on improper arguments | ||
| 12815 | # The sorted list of cages otherwise | ||
| 12816 | |||
| 12817 | my ($self, $tab, $check) = @_; | ||
| 12818 | |||
| 12819 | # Local variables | ||
| 12820 | my ( | ||
| 12821 | @emptyList, @cageList, @spareList, @lonelyList, @sortedList, | ||
| 12822 | %cageHash, | ||
| 12823 | ); | ||
| 12824 | |||
| 12825 | # Check for improper arguments | ||
| 12826 | if (! defined $tab || defined $check) { | ||
| 12827 | |||
| 12828 | $axmud::CLIENT->writeImproper($self->_objClass . '->getSortedCages', @_); | ||
| 12829 | return @emptyList; | ||
| 12830 | } | ||
| 12831 | |||
| 12832 | # Get a hash of cages belonging to this tab | ||
| 12833 | foreach my $cageObj ($self->session->ivValues('cageHash')) { | ||
| 12834 | |||
| 12835 | if ($cageObj->cageType eq $tab) { | ||
| 12836 | |||
| 12837 | if ( | ||
| 12838 | defined $cageObj->profCategory | ||
| 12839 | && $self->session->ivExists('currentCageHash', $cageObj->name) | ||
| 12840 | ) { | ||
| 12841 | $cageHash{$cageObj->profCategory} = $cageObj; | ||
| 12842 | |||
| 12843 | } else { | ||
| 12844 | |||
| 12845 | # Not a current cage - leave it until the end | ||
| 12846 | push (@spareList, $cageObj); | ||
| 12847 | } | ||
| 12848 | } | ||
| 12849 | } | ||
| 12850 | |||
| 12851 | # Sort the list in priority order | ||
| 12852 | foreach my $category ($self->session->profPriorityList) { | ||
| 12853 | |||
| 12854 | if (exists $cageHash{$category}) { | ||
| 12855 | |||
| 12856 | push (@cageList, $cageHash{$category}); | ||
| 12857 | delete $cageHash{$category}; | ||
| 12858 | } | ||
| 12859 | } | ||
| 12860 | |||
| 12861 | if (%cageHash) { | ||
| 12862 | |||
| 12863 | # These cages are associated with profiles which aren't in the profile priority list | ||
| 12864 | @lonelyList = sort {lc($a->name) cmp lc($b->name)} (values %cageHash); | ||
| 12865 | push (@cageList, @lonelyList); | ||
| 12866 | } | ||
| 12867 | |||
| 12868 | # Add all the cages for non-current profiles | ||
| 12869 | @sortedList = sort {lc($a->name) cmp lc($b->name)} (@spareList); | ||
| 12870 | push (@cageList, @sortedList); | ||
| 12871 | |||
| 12872 | return @cageList; | ||
| 12873 | } | ||
| 12874 | |||
| 12875 | sub setColumnList_model { | ||
| 12876 | |||
| 12877 | # Called by $self->allModelHeader, $self->regionModelHeader, etc | ||
| 12878 | # Sets up the list of column titles appropriate for displaying model objects in the notebook | ||
| 12879 | # list, in the form | ||
| 12880 | # [ | ||
| 12881 | # 'column_name' => 'type', | ||
| 12882 | # 'column_name' => 'type', | ||
| 12883 | # 'column_name' => 'type', | ||
| 12884 | # ... | ||
| 12885 | # ] | ||
| 12886 | # | ||
| 12887 | # Expected arguments | ||
| 12888 | # (none besides $self) | ||
| 12889 | # | ||
| 12890 | # Return values | ||
| 12891 | # 'undef' on improper arguments | ||
| 12892 | # Otherwise returns a reference to the list described above | ||
| 12893 | |||
| 12894 | my ($self, $check) = @_; | ||
| 12895 | |||
| 12896 | # Local variables | ||
| 12897 | my @list; | ||
| 12898 | |||
| 12899 | # Check for improper arguments | ||
| 12900 | if (defined $check) { | ||
| 12901 | |||
| 12902 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setColumnList_model', @_); | ||
| 12903 | } | ||
| 12904 | |||
| 12905 | @list = ( | ||
| 12906 | 'Model #' => 'int', | ||
| 12907 | 'Category' => 'text', | ||
| 12908 | 'Name' => 'text', | ||
| 12909 | ); | ||
| 12910 | |||
| 12911 | return \@list; | ||
| 12912 | } | ||
| 12913 | |||
| 12914 | sub setButtonList_model { | ||
| 12915 | |||
| 12916 | # Called by $self->allModelHeader, $self->regionModelHeader, etc (most world model object | ||
| 12917 | # tabs use this function, but a few - such as the tab for characters - specify their own | ||
| 12918 | # buttons) | ||
| 12919 | # Sets up the list of buttons appropriate for manipulating model objects in the notebook | ||
| 12920 | # list, in the form | ||
| 12921 | # [ | ||
| 12922 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12923 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12924 | # 'button_name', 'tooltip', 'callback_sub_ref', | ||
| 12925 | # ... | ||
| 12926 | # ] | ||
| 12927 | # | ||
| 12928 | # Expected arguments | ||
| 12929 | # (none besides $self) | ||
| 12930 | # | ||
| 12931 | # Return values | ||
| 12932 | # 'undef' on improper arguments | ||
| 12933 | # Otherwise returns a reference to the list described above | ||
| 12934 | |||
| 12935 | my ($self, $check) = @_; | ||
| 12936 | |||
| 12937 | # Local variables | ||
| 12938 | my @list; | ||
| 12939 | |||
| 12940 | # Check for improper arguments | ||
| 12941 | if (defined $check) { | ||
| 12942 | |||
| 12943 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setButtonList_model', @_); | ||
| 12944 | } | ||
| 12945 | |||
| 12946 | @list = ( | ||
| 12947 | 'Add', 'Add an object to the world model', 'buttonAdd_model', | ||
| 12948 | 'Edit', 'Edit the selected world model object', 'buttonEdit_model', | ||
| 12949 | 'Delete', 'Delete the selected world model object', 'buttonDelete_model', | ||
| 12950 | 'Dump', 'Displays a list of all world model objects in the \'main\' window', | ||
| 12951 | 'buttonDump_model', | ||
| 12952 | ); | ||
| 12953 | |||
| 12954 | return \@list; | ||
| 12955 | } | ||
| 12956 | |||
| 12957 | # Treeview callbacks | ||
| 12958 | |||
| 12959 | sub treeViewRowActivated { | ||
| 12960 | |||
| 12961 | # Treeview's 'row_activated' callback - expands and collapses parts of the tree | ||
| 12962 | # Defined in $self->enable | ||
| 12963 | # | ||
| 12964 | # Expected arguments | ||
| 12965 | # $tree - The Gtk3::TreeView widget | ||
| 12966 | # $path, $column - The clicked cell | ||
| 12967 | # $self - This Perl object | ||
| 12968 | # | ||
| 12969 | # Return values | ||
| 12970 | # 'undef' on improper arguments | ||
| 12971 | # 1 otherwise | ||
| 12972 | |||
| 12973 | my ($tree, $path, $column, $self, $check) = @_; | ||
| 12974 | |||
| 12975 | # Check for improper arguments | ||
| 12976 | if ( | ||
| 12977 | ! defined $tree || ! defined $path || ! defined $column || ! defined $self | ||
| 12978 | || defined $check | ||
| 12979 | ) { | ||
| 12980 | return $axmud::CLIENT->writeImproper($self->_objClass . '->treeViewRowActivated', @_); | ||
| 12981 | } | ||
| 12982 | |||
| 12983 | if ($tree->row_expanded($path)) { | ||
| 12984 | |||
| 12985 | $tree->collapse_row($path); | ||
| 12986 | |||
| 12987 | } else { | ||
| 12988 | |||
| 12989 | $tree->expand_row($path, FALSE); | ||
| 12990 | } | ||
| 12991 | |||
| 12992 | return 1; | ||
| 12993 | } | ||
| 12994 | |||
| 12995 | sub treeViewChanged { | ||
| 12996 | |||
| 12997 | # Treeview's 'changed' callback - responds to clicks on the tree | ||
| 12998 | # Defined in $self->winEnable | ||
| 12999 | # | ||
| 13000 | # Expected arguments | ||
| 13001 | # $selection - Gtk3::Selection | ||
| 13002 | # $self - This Perl object | ||
| 13003 | # | ||
| 13004 | # Return values | ||
| 13005 | # 'undef' on improper arguments | ||
| 13006 | # 1 otherwise | ||
| 13007 | |||
| 13008 | my ($selection, $self, $check) = @_; | ||
| 13009 | |||
| 13010 | # Local variables | ||
| 13011 | my ($model, $iter, $type, $method); | ||
| 13012 | |||
| 13013 | # Check for improper arguments | ||
| 13014 | if (! defined $selection || ! defined $self || defined $check) { | ||
| 13015 | |||
| 13016 | return $axmud::CLIENT->writeImproper($self->_objClass . '->treeViewChanged', @_); | ||
| 13017 | } | ||
| 13018 | |||
| 13019 | ($model, $iter) = $selection->get_selected(); | ||
| 13020 | if (! $iter) { | ||
| 13021 | |||
| 13022 | return undef; | ||
| 13023 | |||
| 13024 | } else { | ||
| 13025 | |||
| 13026 | $type = $model->get($iter, 0); | ||
| 13027 | } | ||
| 13028 | |||
| 13029 | # Is the clicked item a header? If so, call its function | ||
| 13030 | if ($self->ivExists('headerHash', $type)) { | ||
| 13031 | |||
| 13032 | # ->notebookSelectRef's default value is 'undef'; the function we're about to call will | ||
| 13033 | # set it, if need be | ||
| 13034 | $self->ivPoke('notebookSelectRef', undef); | ||
| 13035 | # Remember which type of notebook we're about to display | ||
| 13036 | $self->ivPoke('notebookCurrentHeader', $type); | ||
| 13037 | |||
| 13038 | # Call the function to create this type of notebook | ||
| 13039 | $method = $self->ivShow('headerHash', $type); | ||
| 13040 | $self->$method($type); | ||
| 13041 | } | ||
| 13042 | |||
| 13043 | return 1; | ||
| 13044 | } | ||
| 13045 | |||
| 13046 | # Profile button callbacks | ||
| 13047 | |||
| 13048 | sub buttonAdd_prof { | ||
| 13049 | |||
| 13050 | # Callback: Adds a profile (equivalent to ';addworld', ';addchar', etc) | ||
| 13051 | # | ||
| 13052 | # Expected arguments | ||
| 13053 | # (none besides $self) | ||
| 13054 | # | ||
| 13055 | # Return values | ||
| 13056 | # 'undef' on improper arguments or if a temporary profile object can't be created | ||
| 13057 | # 1 otherwise | ||
| 13058 | |||
| 13059 | my ($self, $check) = @_; | ||
| 13060 | |||
| 13061 | # Local variables | ||
| 13062 | my ($tab, $slWidget, $world, $profObj, $templObj); | ||
| 13063 | |||
| 13064 | # Check for improper arguments | ||
| 13065 | if (defined $check) { | ||
| 13066 | |||
| 13067 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_prof', @_); | ||
| 13068 | } | ||
| 13069 | |||
| 13070 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 13071 | $tab = $self->notebookGetTab(); | ||
| 13072 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 13073 | |||
| 13074 | # Unselect everything in the list, because we're creating a new profile | ||
| 13075 | $slWidget->get_selection->unselect_all(); | ||
| 13076 | |||
| 13077 | # Create a temporary profile, to store the changes the user will make | ||
| 13078 | $world = $self->session->currentWorld->name; | ||
| 13079 | |||
| 13080 | if ($tab eq 'world') { | ||
| 13081 | $profObj = Games::Axmud::Profile::World->new($self->session, '<temp>', TRUE); | ||
| 13082 | } elsif ($tab eq 'guild') { | ||
| 13083 | $profObj = Games::Axmud::Profile::Guild->new($self->session, '<temp>', $world, TRUE); | ||
| 13084 | } elsif ($tab eq 'race') { | ||
| 13085 | $profObj = Games::Axmud::Profile::Race->new($self->session, '<temp>', $world, TRUE); | ||
| 13086 | } elsif ($tab eq 'char') { | ||
| 13087 | $profObj = Games::Axmud::Profile::Char->new($self->session, '<temp>', $world, TRUE); | ||
| 13088 | } else { | ||
| 13089 | |||
| 13090 | # Find the matching template profile | ||
| 13091 | if ($self->session->ivExists('templateHash', $tab)) { | ||
| 13092 | |||
| 13093 | $templObj = $self->session->ivShow('templateHash', $tab); | ||
| 13094 | |||
| 13095 | # Spawn a new custom profile | ||
| 13096 | $profObj = $templObj->spawn( | ||
| 13097 | $self->session, | ||
| 13098 | '<temp>', | ||
| 13099 | $self->session->currentWorld->name, | ||
| 13100 | TRUE, | ||
| 13101 | ); | ||
| 13102 | } | ||
| 13103 | } | ||
| 13104 | |||
| 13105 | if (! $profObj) { | ||
| 13106 | |||
| 13107 | # Can't edit anything | ||
| 13108 | return undef; | ||
| 13109 | |||
| 13110 | } else { | ||
| 13111 | |||
| 13112 | # Open up an 'edit' window to create the new object, replacing the temporary one we've | ||
| 13113 | # just created | ||
| 13114 | if ($tab eq 'world') { | ||
| 13115 | |||
| 13116 | $self->createFreeWin( | ||
| 13117 | 'Games::Axmud::EditWin::Profile::World', | ||
| 13118 | $self, | ||
| 13119 | $self->session, | ||
| 13120 | 'Edit world profile \'' . $profObj->name . '\'', | ||
| 13121 | $profObj, | ||
| 13122 | TRUE, # Temporary object | ||
| 13123 | ); | ||
| 13124 | |||
| 13125 | } elsif ($tab eq 'guild') { | ||
| 13126 | |||
| 13127 | $self->createFreeWin( | ||
| 13128 | 'Games::Axmud::EditWin::Profile::Guild', | ||
| 13129 | $self, | ||
| 13130 | $self->session, | ||
| 13131 | 'Edit guild profile \'' . $profObj->name . '\'', | ||
| 13132 | $profObj, | ||
| 13133 | TRUE, # Temporary object | ||
| 13134 | ); | ||
| 13135 | |||
| 13136 | } elsif ($tab eq 'race') { | ||
| 13137 | |||
| 13138 | $self->createFreeWin( | ||
| 13139 | 'Games::Axmud::EditWin::Profile::Race', | ||
| 13140 | $self, | ||
| 13141 | $self->session, | ||
| 13142 | 'Edit race profile \'' . $profObj->name . '\'', | ||
| 13143 | $profObj, | ||
| 13144 | TRUE, # Temporary object | ||
| 13145 | ); | ||
| 13146 | |||
| 13147 | } elsif ($tab eq 'char') { | ||
| 13148 | |||
| 13149 | $self->createFreeWin( | ||
| 13150 | 'Games::Axmud::EditWin::Profile::Char', | ||
| 13151 | $self, | ||
| 13152 | $self->session, | ||
| 13153 | 'Edit character profile \'' . $profObj->name . '\'', | ||
| 13154 | $profObj, | ||
| 13155 | TRUE, # Temporary object | ||
| 13156 | ); | ||
| 13157 | |||
| 13158 | } else { | ||
| 13159 | |||
| 13160 | $self->createFreeWin( | ||
| 13161 | 'Games::Axmud::EditWin::Profile::Custom', | ||
| 13162 | $self, | ||
| 13163 | $self->session, | ||
| 13164 | 'Edit ' . $profObj->category . ' profile \'' . $profObj->name . '\'', | ||
| 13165 | $profObj, | ||
| 13166 | TRUE, # Temporary object | ||
| 13167 | ); | ||
| 13168 | } | ||
| 13169 | } | ||
| 13170 | |||
| 13171 | return 1; | ||
| 13172 | } | ||
| 13173 | |||
| 13174 | sub buttonEdit_prof { | ||
| 13175 | |||
| 13176 | # Callback: Edits a profile (equivalent to ';editworld', ';editchar', etc) | ||
| 13177 | # | ||
| 13178 | # Expected arguments | ||
| 13179 | # (none besides $self) | ||
| 13180 | # | ||
| 13181 | # Return values | ||
| 13182 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13183 | # object no longer exists | ||
| 13184 | # 1 otherwise | ||
| 13185 | |||
| 13186 | my ($self, $check) = @_; | ||
| 13187 | |||
| 13188 | # Local variables | ||
| 13189 | my ( | ||
| 13190 | $tab, $dataRef, $profName, $profObj, | ||
| 13191 | @list, @dataList, | ||
| 13192 | ); | ||
| 13193 | |||
| 13194 | # Check for improper arguments | ||
| 13195 | if (defined $check) { | ||
| 13196 | |||
| 13197 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_prof', @_); | ||
| 13198 | } | ||
| 13199 | |||
| 13200 | # Get the selected tab | ||
| 13201 | $tab = $self->notebookGetTab(); | ||
| 13202 | # Import the currently selected portions of the notebook list | ||
| 13203 | @list = $self->notebookGetSelectedData(); | ||
| 13204 | if (! @list) { | ||
| 13205 | |||
| 13206 | # Nothing selected | ||
| 13207 | return undef; | ||
| 13208 | } | ||
| 13209 | |||
| 13210 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13211 | # a single row of the list | ||
| 13212 | $dataRef = $list[0]; | ||
| 13213 | @dataList = @$dataRef; | ||
| 13214 | # The profile name is the second item of data | ||
| 13215 | $profName = $dataList[1]; | ||
| 13216 | if (! $profName) { | ||
| 13217 | |||
| 13218 | # Can't continue | ||
| 13219 | return undef; | ||
| 13220 | } | ||
| 13221 | |||
| 13222 | # Get the profile itself | ||
| 13223 | if ($tab eq 'world') { | ||
| 13224 | $profObj = $axmud::CLIENT->ivShow('worldProfHash', $profName); | ||
| 13225 | } else { | ||
| 13226 | $profObj = $self->session->ivShow('profHash', $profName); | ||
| 13227 | } | ||
| 13228 | |||
| 13229 | if (! $profObj) { | ||
| 13230 | |||
| 13231 | # Can't continue | ||
| 13232 | return undef; | ||
| 13233 | |||
| 13234 | } else { | ||
| 13235 | |||
| 13236 | # Open up an 'edit' window to edit the object | ||
| 13237 | if ($tab eq 'world') { | ||
| 13238 | |||
| 13239 | $self->createFreeWin( | ||
| 13240 | 'Games::Axmud::EditWin::Profile::World', | ||
| 13241 | $self, | ||
| 13242 | $self->session, | ||
| 13243 | 'Edit world profile \'' . $profName . '\'', | ||
| 13244 | $profObj, | ||
| 13245 | FALSE, # Not temporary | ||
| 13246 | ); | ||
| 13247 | |||
| 13248 | } elsif ($tab eq 'guild') { | ||
| 13249 | |||
| 13250 | $self->createFreeWin( | ||
| 13251 | 'Games::Axmud::EditWin::Profile::Guild', | ||
| 13252 | $self, | ||
| 13253 | $self->session, | ||
| 13254 | 'Edit guild profile \'' . $profName . '\'', | ||
| 13255 | $profObj, | ||
| 13256 | FALSE, # Not temporary | ||
| 13257 | ); | ||
| 13258 | |||
| 13259 | } elsif ($tab eq 'race') { | ||
| 13260 | |||
| 13261 | $self->createFreeWin( | ||
| 13262 | 'Games::Axmud::EditWin::Profile::Race', | ||
| 13263 | $self, | ||
| 13264 | $self->session, | ||
| 13265 | 'Edit race profile \'' . $profName . '\'', | ||
| 13266 | $profObj, | ||
| 13267 | FALSE, # Not temporary | ||
| 13268 | ); | ||
| 13269 | |||
| 13270 | } elsif ($tab eq 'char') { | ||
| 13271 | |||
| 13272 | $self->createFreeWin( | ||
| 13273 | 'Games::Axmud::EditWin::Profile::Char', | ||
| 13274 | $self, | ||
| 13275 | $self->session, | ||
| 13276 | 'Edit char profile \'' . $profName . '\'', | ||
| 13277 | $profObj, | ||
| 13278 | FALSE, # Not temporary | ||
| 13279 | ); | ||
| 13280 | |||
| 13281 | } else { | ||
| 13282 | |||
| 13283 | $self->createFreeWin( | ||
| 13284 | 'Games::Axmud::EditWin::Profile::Custom', | ||
| 13285 | $self, | ||
| 13286 | $self->session, | ||
| 13287 | 'Edit ' . $profObj->category . ' profile \'' . $profName . '\'', | ||
| 13288 | $profObj, | ||
| 13289 | FALSE, # Not temporary | ||
| 13290 | ); | ||
| 13291 | } | ||
| 13292 | |||
| 13293 | return 1; | ||
| 13294 | } | ||
| 13295 | } | ||
| 13296 | |||
| 13297 | sub buttonSet_prof { | ||
| 13298 | |||
| 13299 | # Callback: Sets a current profile (equivalent to ';setworld', ';setchar', etc) | ||
| 13300 | # | ||
| 13301 | # Expected arguments | ||
| 13302 | # (none besides $self) | ||
| 13303 | # | ||
| 13304 | # Return values | ||
| 13305 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13306 | # object no longer exists | ||
| 13307 | # 1 otherwise | ||
| 13308 | |||
| 13309 | my ($self, $check) = @_; | ||
| 13310 | |||
| 13311 | # Local variables | ||
| 13312 | my ( | ||
| 13313 | $tab, $dataRef, $profName, $profObj, | ||
| 13314 | @list, @dataList, | ||
| 13315 | ); | ||
| 13316 | |||
| 13317 | # Check for improper arguments | ||
| 13318 | if (defined $check) { | ||
| 13319 | |||
| 13320 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonSet_prof', @_); | ||
| 13321 | } | ||
| 13322 | |||
| 13323 | # Get the selected tab | ||
| 13324 | $tab = $self->notebookGetTab(); | ||
| 13325 | # Import the currently selected portions of the notebook list | ||
| 13326 | @list = $self->notebookGetSelectedData(); | ||
| 13327 | if (! @list) { | ||
| 13328 | |||
| 13329 | # Nothing selected | ||
| 13330 | return undef; | ||
| 13331 | } | ||
| 13332 | |||
| 13333 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13334 | # a single row of the list | ||
| 13335 | $dataRef = $list[0]; | ||
| 13336 | @dataList = @$dataRef; | ||
| 13337 | # The profile name is the second item of data | ||
| 13338 | $profName = $dataList[1]; | ||
| 13339 | if (! $profName) { | ||
| 13340 | |||
| 13341 | # Can't continue | ||
| 13342 | return undef; | ||
| 13343 | } | ||
| 13344 | |||
| 13345 | # Get the profile itself (to check it still exists) | ||
| 13346 | if ($tab eq 'world') { | ||
| 13347 | $profObj = $axmud::CLIENT->ivShow('worldProfHash', $profName); | ||
| 13348 | } else { | ||
| 13349 | $profObj = $self->session->ivShow('profHash', $profName); | ||
| 13350 | } | ||
| 13351 | |||
| 13352 | if (! $profObj) { | ||
| 13353 | |||
| 13354 | # Can't continue | ||
| 13355 | return undef; | ||
| 13356 | } | ||
| 13357 | |||
| 13358 | # Set the profile | ||
| 13359 | if ($profObj->category eq 'world') { | ||
| 13360 | $self->session->pseudoCmd('setworld ' . $profName, $self->pseudoCmdMode); | ||
| 13361 | } elsif ($profObj->category eq 'guild') { | ||
| 13362 | $self->session->pseudoCmd('setguild ' . $profName, $self->pseudoCmdMode); | ||
| 13363 | } elsif ($profObj->category eq 'race') { | ||
| 13364 | $self->session->pseudoCmd('setrace ' . $profName, $self->pseudoCmdMode); | ||
| 13365 | } elsif ($profObj->category eq 'char') { | ||
| 13366 | $self->session->pseudoCmd('setchar ' . $profName, $self->pseudoCmdMode); | ||
| 13367 | } else { | ||
| 13368 | $self->session->pseudoCmd('setcustomprofile ' . $profName, $self->pseudoCmdMode); | ||
| 13369 | } | ||
| 13370 | |||
| 13371 | # Update the notebook | ||
| 13372 | $self->updateNotebook(); | ||
| 13373 | |||
| 13374 | return 1; | ||
| 13375 | } | ||
| 13376 | |||
| 13377 | sub buttonUnset_prof { | ||
| 13378 | |||
| 13379 | # Callback: Unsets a current profile (equivalent to ';unsetguild', ';unsetchar', etc) | ||
| 13380 | # | ||
| 13381 | # Expected arguments | ||
| 13382 | # (none besides $self) | ||
| 13383 | # | ||
| 13384 | # Return values | ||
| 13385 | # 'undef' on improper arguments or if the user tries to unset a current world profile | ||
| 13386 | # 1 otherwise | ||
| 13387 | |||
| 13388 | my ($self, $check) = @_; | ||
| 13389 | |||
| 13390 | # Local variables | ||
| 13391 | my ($tab, $profObj); | ||
| 13392 | |||
| 13393 | # Check for improper arguments | ||
| 13394 | if (defined $check) { | ||
| 13395 | |||
| 13396 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonUnset_prof', @_); | ||
| 13397 | } | ||
| 13398 | |||
| 13399 | # Get the selected tab | ||
| 13400 | $tab = $self->notebookGetTab(); | ||
| 13401 | |||
| 13402 | # There is no ';unsetworld' command | ||
| 13403 | if ($tab eq 'world') { | ||
| 13404 | |||
| 13405 | $self->showMsgDialogue( | ||
| 13406 | 'Unset profile', | ||
| 13407 | 'warning', | ||
| 13408 | 'Current world profiles can\'t be unset', | ||
| 13409 | 'ok', | ||
| 13410 | ); | ||
| 13411 | |||
| 13412 | return undef; | ||
| 13413 | } | ||
| 13414 | |||
| 13415 | # Unset the current profile for the category displayed in this tab | ||
| 13416 | if ($tab eq 'guild') { | ||
| 13417 | $self->session->pseudoCmd('unsetguild', $self->pseudoCmdMode); | ||
| 13418 | } elsif ($tab eq 'race') { | ||
| 13419 | $self->session->pseudoCmd('unsetrace', $self->pseudoCmdMode); | ||
| 13420 | } elsif ($tab eq 'char') { | ||
| 13421 | $self->session->pseudoCmd('unsetchar', $self->pseudoCmdMode); | ||
| 13422 | } else { | ||
| 13423 | |||
| 13424 | $profObj = $self->session->ivShow('currentProfHash', $tab); | ||
| 13425 | if ($profObj) { | ||
| 13426 | |||
| 13427 | $self->session->pseudoCmd( | ||
| 13428 | 'unsetcustomprofile ' . $profObj->name, | ||
| 13429 | $self->pseudoCmdMode, | ||
| 13430 | ); | ||
| 13431 | } | ||
| 13432 | } | ||
| 13433 | |||
| 13434 | # Update the notebook | ||
| 13435 | $self->updateNotebook(); | ||
| 13436 | |||
| 13437 | return 1; | ||
| 13438 | } | ||
| 13439 | |||
| 13440 | sub buttonClone_prof { | ||
| 13441 | |||
| 13442 | # Callback: Clones the selected profile (equivalent to ';cloneworld', ';clonechar', etc) | ||
| 13443 | # | ||
| 13444 | # Expected arguments | ||
| 13445 | # (none besides $self) | ||
| 13446 | # | ||
| 13447 | # Return values | ||
| 13448 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13449 | # object no longer exists | ||
| 13450 | # 1 otherwise | ||
| 13451 | |||
| 13452 | my ($self, $check) = @_; | ||
| 13453 | |||
| 13454 | # Local variables | ||
| 13455 | my ( | ||
| 13456 | $tab, $dataRef, $profName, $profObj, $cloneName, | ||
| 13457 | @list, @dataList, | ||
| 13458 | ); | ||
| 13459 | |||
| 13460 | # Check for improper arguments | ||
| 13461 | if (defined $check) { | ||
| 13462 | |||
| 13463 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonClone_prof', @_); | ||
| 13464 | } | ||
| 13465 | |||
| 13466 | # Get the selected tab | ||
| 13467 | $tab = $self->notebookGetTab(); | ||
| 13468 | # Import the currently selected portions of the notebook list | ||
| 13469 | @list = $self->notebookGetSelectedData(); | ||
| 13470 | if (! @list) { | ||
| 13471 | |||
| 13472 | # Nothing selected | ||
| 13473 | return undef; | ||
| 13474 | } | ||
| 13475 | |||
| 13476 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13477 | # a single row of the list | ||
| 13478 | $dataRef = $list[0]; | ||
| 13479 | @dataList = @$dataRef; | ||
| 13480 | # The profile name is the second item of data | ||
| 13481 | $profName = $dataList[1]; | ||
| 13482 | if (! $profName) { | ||
| 13483 | |||
| 13484 | # Can't continue | ||
| 13485 | return undef; | ||
| 13486 | } | ||
| 13487 | |||
| 13488 | # Get the profile itself | ||
| 13489 | if ($tab eq 'world') { | ||
| 13490 | $profObj = $axmud::CLIENT->ivShow('worldProfHash', $profName); | ||
| 13491 | } else { | ||
| 13492 | $profObj = $self->session->ivShow('profHash', $profName); | ||
| 13493 | } | ||
| 13494 | |||
| 13495 | if (! $profObj) { | ||
| 13496 | |||
| 13497 | # Can't continue | ||
| 13498 | return undef; | ||
| 13499 | } | ||
| 13500 | |||
| 13501 | # Prompt the user for the name of the clone (max 16 chars) | ||
| 13502 | $cloneName = $self->showEntryDialogue( | ||
| 13503 | 'Clone profile', | ||
| 13504 | 'Enter a name for the clone (max 16 chars: A-Z a-z _ 0-9)', | ||
| 13505 | 16, # Max chars | ||
| 13506 | ); | ||
| 13507 | |||
| 13508 | if ($cloneName) { | ||
| 13509 | |||
| 13510 | # Clone the profile | ||
| 13511 | if ($profObj->category eq 'world') { | ||
| 13512 | |||
| 13513 | $self->session->pseudoCmd( | ||
| 13514 | 'cloneworld ' . $profName . ' ' . $cloneName, | ||
| 13515 | $self->pseudoCmdMode, | ||
| 13516 | ); | ||
| 13517 | |||
| 13518 | } elsif ($profObj->category eq 'guild') { | ||
| 13519 | |||
| 13520 | $self->session->pseudoCmd( | ||
| 13521 | 'cloneguild ' . $profName . ' ' . $cloneName, | ||
| 13522 | $self->pseudoCmdMode, | ||
| 13523 | ); | ||
| 13524 | |||
| 13525 | } elsif ($profObj->category eq 'race') { | ||
| 13526 | |||
| 13527 | $self->session->pseudoCmd( | ||
| 13528 | 'clonerace ' . $profName . ' ' . $cloneName, | ||
| 13529 | $self->pseudoCmdMode, | ||
| 13530 | ); | ||
| 13531 | |||
| 13532 | } elsif ($profObj->category eq 'char') { | ||
| 13533 | |||
| 13534 | $self->session->pseudoCmd( | ||
| 13535 | 'clonechar ' . $profName . ' ' . $cloneName, | ||
| 13536 | $self->pseudoCmdMode, | ||
| 13537 | ); | ||
| 13538 | |||
| 13539 | } else { | ||
| 13540 | |||
| 13541 | $self->session->pseudoCmd( | ||
| 13542 | 'clonecustomprofile ' . $profName . ' ' . $cloneName, | ||
| 13543 | $self->pseudoCmdMode, | ||
| 13544 | ); | ||
| 13545 | } | ||
| 13546 | |||
| 13547 | # Update the notebook | ||
| 13548 | $self->updateNotebook(); | ||
| 13549 | } | ||
| 13550 | |||
| 13551 | return 1; | ||
| 13552 | } | ||
| 13553 | |||
| 13554 | sub buttonDelete_prof { | ||
| 13555 | |||
| 13556 | # Callback: Deletes a profile (equivalent to ';deleteworld', ';deletechar', etc) | ||
| 13557 | # | ||
| 13558 | # Expected arguments | ||
| 13559 | # (none besides $self) | ||
| 13560 | # | ||
| 13561 | # Return values | ||
| 13562 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13563 | # object no longer exists | ||
| 13564 | # 1 otherwise | ||
| 13565 | |||
| 13566 | my ($self, $check) = @_; | ||
| 13567 | |||
| 13568 | # Local variables | ||
| 13569 | my ( | ||
| 13570 | $tab, $dataRef, $profName, $profObj, | ||
| 13571 | @list, @dataList, | ||
| 13572 | ); | ||
| 13573 | |||
| 13574 | # Check for improper arguments | ||
| 13575 | if (defined $check) { | ||
| 13576 | |||
| 13577 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_prof', @_); | ||
| 13578 | } | ||
| 13579 | |||
| 13580 | # Get the selected tab | ||
| 13581 | $tab = $self->notebookGetTab(); | ||
| 13582 | # Import the currently selected portions of the notebook list | ||
| 13583 | @list = $self->notebookGetSelectedData(); | ||
| 13584 | if (! @list) { | ||
| 13585 | |||
| 13586 | # Nothing selected | ||
| 13587 | return undef; | ||
| 13588 | } | ||
| 13589 | |||
| 13590 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13591 | # a single row of the list | ||
| 13592 | $dataRef = $list[0]; | ||
| 13593 | @dataList = @$dataRef; | ||
| 13594 | # The profile name is the second item of data | ||
| 13595 | $profName = $dataList[1]; | ||
| 13596 | if (! $profName) { | ||
| 13597 | |||
| 13598 | # Can't continue | ||
| 13599 | return undef; | ||
| 13600 | } | ||
| 13601 | |||
| 13602 | # Get the profile itself (to check it still exists) | ||
| 13603 | if ($tab eq 'world') { | ||
| 13604 | $profObj = $axmud::CLIENT->ivShow('worldProfHash', $profName); | ||
| 13605 | } else { | ||
| 13606 | $profObj = $self->session->ivShow('profHash', $profName); | ||
| 13607 | } | ||
| 13608 | |||
| 13609 | if (! $profObj) { | ||
| 13610 | |||
| 13611 | # Can't continue | ||
| 13612 | return undef; | ||
| 13613 | } | ||
| 13614 | |||
| 13615 | # Delete the profile | ||
| 13616 | if ($profObj->category eq 'world') { | ||
| 13617 | $self->session->pseudoCmd('deleteworld ' . $profName, $self->pseudoCmdMode); | ||
| 13618 | } elsif ($profObj->category eq 'guild') { | ||
| 13619 | $self->session->pseudoCmd('deleteguild ' . $profName, $self->pseudoCmdMode); | ||
| 13620 | } elsif ($profObj->category eq 'race') { | ||
| 13621 | $self->session->pseudoCmd('deleterace ' . $profName, $self->pseudoCmdMode); | ||
| 13622 | } elsif ($profObj->category eq 'char') { | ||
| 13623 | $self->session->pseudoCmd('deletechar ' . $profName, $self->pseudoCmdMode); | ||
| 13624 | } else { | ||
| 13625 | $self->session->pseudoCmd('deletecustomprofile ' . $profName, $self->pseudoCmdMode); | ||
| 13626 | } | ||
| 13627 | |||
| 13628 | # Update the notebook | ||
| 13629 | $self->updateNotebook(); | ||
| 13630 | |||
| 13631 | return 1; | ||
| 13632 | } | ||
| 13633 | |||
| 13634 | sub buttonDump_prof { | ||
| 13635 | |||
| 13636 | # Callback: Displays profiles in the 'main' window (equivalent to ';listword', | ||
| 13637 | # ';listchar' etc) | ||
| 13638 | # | ||
| 13639 | # Expected arguments | ||
| 13640 | # (none besides $self) | ||
| 13641 | # | ||
| 13642 | # Return values | ||
| 13643 | # 'undef' on improper arguments | ||
| 13644 | # 1 otherwise | ||
| 13645 | |||
| 13646 | my ($self, $check) = @_; | ||
| 13647 | |||
| 13648 | # Local variables | ||
| 13649 | my $tab; | ||
| 13650 | |||
| 13651 | # Check for improper arguments | ||
| 13652 | if (defined $check) { | ||
| 13653 | |||
| 13654 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_prof', @_); | ||
| 13655 | } | ||
| 13656 | |||
| 13657 | # Get the selected tab | ||
| 13658 | $tab = $self->notebookGetTab(); | ||
| 13659 | |||
| 13660 | # Display the list | ||
| 13661 | if ($tab eq 'world') { | ||
| 13662 | $self->session->pseudoCmd('listworld', $self->pseudoCmdMode); | ||
| 13663 | } elsif ($tab eq 'guild') { | ||
| 13664 | $self->session->pseudoCmd('listguild', $self->pseudoCmdMode); | ||
| 13665 | } elsif ($tab eq 'race') { | ||
| 13666 | $self->session->pseudoCmd('listrace', $self->pseudoCmdMode); | ||
| 13667 | } elsif ($tab eq 'char') { | ||
| 13668 | $self->session->pseudoCmd('listchar', $self->pseudoCmdMode); | ||
| 13669 | } else { | ||
| 13670 | |||
| 13671 | # (Actually lists all custom profiles based on the same template) | ||
| 13672 | $self->session->pseudoCmd('listcustomprofile ' . $tab, $self->pseudoCmdMode); | ||
| 13673 | } | ||
| 13674 | |||
| 13675 | return 1; | ||
| 13676 | } | ||
| 13677 | |||
| 13678 | sub buttonDumpAll_prof { | ||
| 13679 | |||
| 13680 | # Callback: Displays all profiles in the 'main' window (equivalent to ';listprofile') | ||
| 13681 | # | ||
| 13682 | # Expected arguments | ||
| 13683 | # (none besides $self) | ||
| 13684 | # | ||
| 13685 | # Return values | ||
| 13686 | # 'undef' on improper arguments | ||
| 13687 | # 1 otherwise | ||
| 13688 | |||
| 13689 | my ($self, $check) = @_; | ||
| 13690 | |||
| 13691 | # Check for improper arguments | ||
| 13692 | if (defined $check) { | ||
| 13693 | |||
| 13694 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDumpAll_prof', @_); | ||
| 13695 | } | ||
| 13696 | |||
| 13697 | # Display the list of profiles | ||
| 13698 | $self->session->pseudoCmd('listprofile', $self->pseudoCmdMode); | ||
| 13699 | |||
| 13700 | return 1; | ||
| 13701 | } | ||
| 13702 | |||
| 13703 | # Template button callbacks | ||
| 13704 | |||
| 13705 | sub buttonAdd_template { | ||
| 13706 | |||
| 13707 | # Callback: Adds a profile template (equivalent to ';addtemplate') | ||
| 13708 | # | ||
| 13709 | # Expected arguments | ||
| 13710 | # (none besides $self) | ||
| 13711 | # | ||
| 13712 | # Return values | ||
| 13713 | # 'undef' on improper arguments or if a temporary profile template object can't be created | ||
| 13714 | # 1 otherwise | ||
| 13715 | |||
| 13716 | my ($self, $check) = @_; | ||
| 13717 | |||
| 13718 | # Local variables | ||
| 13719 | my ($tab, $slWidget, $templObj); | ||
| 13720 | |||
| 13721 | # Check for improper arguments | ||
| 13722 | if (defined $check) { | ||
| 13723 | |||
| 13724 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_template', @_); | ||
| 13725 | } | ||
| 13726 | |||
| 13727 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 13728 | $tab = $self->notebookGetTab(); | ||
| 13729 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 13730 | |||
| 13731 | # Unselect everything in the list, because we're creating a new profile template | ||
| 13732 | $slWidget->get_selection->unselect_all(); | ||
| 13733 | |||
| 13734 | # Create a temporary template | ||
| 13735 | $templObj = Games::Axmud::Profile::Template->new($self->session, '<temp>', TRUE); | ||
| 13736 | if (! $templObj) { | ||
| 13737 | |||
| 13738 | # Can't edit anything | ||
| 13739 | return undef; | ||
| 13740 | |||
| 13741 | } else { | ||
| 13742 | |||
| 13743 | # Open up an 'edit' window to create the new object, replacing the temporary one we've | ||
| 13744 | # just created | ||
| 13745 | $self->createFreeWin( | ||
| 13746 | 'Games::Axmud::EditWin::Profile::Template', | ||
| 13747 | $self, | ||
| 13748 | $self->session, | ||
| 13749 | 'Edit \'' . $templObj->category . '\' profile template', | ||
| 13750 | $templObj, | ||
| 13751 | TRUE, # Temporary object | ||
| 13752 | ); | ||
| 13753 | } | ||
| 13754 | |||
| 13755 | return 1; | ||
| 13756 | } | ||
| 13757 | |||
| 13758 | sub buttonEdit_template { | ||
| 13759 | |||
| 13760 | # Callback: Edits a profile template (equivalent to ';edittemplate') | ||
| 13761 | # | ||
| 13762 | # Expected arguments | ||
| 13763 | # (none besides $self) | ||
| 13764 | # | ||
| 13765 | # Return values | ||
| 13766 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13767 | # object no longer exists | ||
| 13768 | # 1 otherwise | ||
| 13769 | |||
| 13770 | my ($self, $check) = @_; | ||
| 13771 | |||
| 13772 | # Local variables | ||
| 13773 | my ( | ||
| 13774 | $dataRef, $category, $templObj, | ||
| 13775 | @list, @dataList, | ||
| 13776 | ); | ||
| 13777 | |||
| 13778 | # Check for improper arguments | ||
| 13779 | if (defined $check) { | ||
| 13780 | |||
| 13781 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_template', @_); | ||
| 13782 | } | ||
| 13783 | |||
| 13784 | # Import the currently selected portions of the notebook list | ||
| 13785 | @list = $self->notebookGetSelectedData(); | ||
| 13786 | if (! @list) { | ||
| 13787 | |||
| 13788 | # Nothing selected | ||
| 13789 | return undef; | ||
| 13790 | } | ||
| 13791 | |||
| 13792 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13793 | # a single row of the list | ||
| 13794 | $dataRef = $list[0]; | ||
| 13795 | @dataList = @$dataRef; | ||
| 13796 | # The template category is the second item of data | ||
| 13797 | $category = $dataList[1]; | ||
| 13798 | if (! $category) { | ||
| 13799 | |||
| 13800 | # Can't continue | ||
| 13801 | return undef; | ||
| 13802 | } | ||
| 13803 | |||
| 13804 | # Get the template itself | ||
| 13805 | $templObj = $self->session->ivShow('templateHash', $category); | ||
| 13806 | if (! $templObj) { | ||
| 13807 | |||
| 13808 | # Can't continue | ||
| 13809 | return undef; | ||
| 13810 | |||
| 13811 | } else { | ||
| 13812 | |||
| 13813 | # Open up an 'edit' window to edit the object | ||
| 13814 | $self->createFreeWin( | ||
| 13815 | 'Games::Axmud::EditWin::Profile::Template', | ||
| 13816 | $self, | ||
| 13817 | $self->session, | ||
| 13818 | 'Edit \'' . $category . '\' profile template', | ||
| 13819 | $templObj, | ||
| 13820 | FALSE, # Not temporary | ||
| 13821 | ); | ||
| 13822 | |||
| 13823 | return 1; | ||
| 13824 | } | ||
| 13825 | } | ||
| 13826 | |||
| 13827 | sub buttonClone_template { | ||
| 13828 | |||
| 13829 | # Callback: Clones the selected profile template (equivalent to ';clonetemplate') | ||
| 13830 | # | ||
| 13831 | # Expected arguments | ||
| 13832 | # (none besides $self) | ||
| 13833 | # | ||
| 13834 | # Return values | ||
| 13835 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13836 | # object no longer exists | ||
| 13837 | # 1 otherwise | ||
| 13838 | |||
| 13839 | my ($self, $check) = @_; | ||
| 13840 | |||
| 13841 | # Local variables | ||
| 13842 | my ( | ||
| 13843 | $dataRef, $category, $templObj, $cloneCategory, | ||
| 13844 | @list, @dataList, | ||
| 13845 | ); | ||
| 13846 | |||
| 13847 | # Check for improper arguments | ||
| 13848 | if (defined $check) { | ||
| 13849 | |||
| 13850 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonClone_template', @_); | ||
| 13851 | } | ||
| 13852 | |||
| 13853 | # Import the currently selected portions of the notebook list | ||
| 13854 | @list = $self->notebookGetSelectedData(); | ||
| 13855 | if (! @list) { | ||
| 13856 | |||
| 13857 | # Nothing selected | ||
| 13858 | return undef; | ||
| 13859 | } | ||
| 13860 | |||
| 13861 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13862 | # a single row of the list | ||
| 13863 | $dataRef = $list[0]; | ||
| 13864 | @dataList = @$dataRef; | ||
| 13865 | # The template category is the second item of data | ||
| 13866 | $category = $dataList[1]; | ||
| 13867 | if (! $category) { | ||
| 13868 | |||
| 13869 | # Can't continue | ||
| 13870 | return undef; | ||
| 13871 | } | ||
| 13872 | |||
| 13873 | # Get the template itself | ||
| 13874 | $templObj = $self->session->ivShow('templateHash', $category); | ||
| 13875 | if (! $templObj) { | ||
| 13876 | |||
| 13877 | # Can't continue | ||
| 13878 | return undef; | ||
| 13879 | } | ||
| 13880 | |||
| 13881 | # Prompt the user for the category of the clone (max 16 chars) | ||
| 13882 | $cloneCategory = $self->showEntryDialogue( | ||
| 13883 | 'Clone template', | ||
| 13884 | 'Enter a category for the clone (max 16 chars: A-Z a-z _ 0-9)', | ||
| 13885 | 16, # Max chars | ||
| 13886 | ); | ||
| 13887 | |||
| 13888 | if ($cloneCategory) { | ||
| 13889 | |||
| 13890 | # Clone the template | ||
| 13891 | $self->session->pseudoCmd( | ||
| 13892 | 'clonetemplate ' . $category . ' ' . $cloneCategory, | ||
| 13893 | $self->pseudoCmdMode, | ||
| 13894 | ); | ||
| 13895 | |||
| 13896 | # Update the notebook | ||
| 13897 | $self->updateNotebook(); | ||
| 13898 | } | ||
| 13899 | |||
| 13900 | return 1; | ||
| 13901 | } | ||
| 13902 | |||
| 13903 | sub buttonDelete_template { | ||
| 13904 | |||
| 13905 | # Callback: Deletes a profile template (equivalent to ';deletetemplate') | ||
| 13906 | # | ||
| 13907 | # Expected arguments | ||
| 13908 | # (none besides $self) | ||
| 13909 | # | ||
| 13910 | # Return values | ||
| 13911 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 13912 | # object no longer exists | ||
| 13913 | # 1 otherwise | ||
| 13914 | |||
| 13915 | my ($self, $check) = @_; | ||
| 13916 | |||
| 13917 | # Local variables | ||
| 13918 | my ( | ||
| 13919 | $dataRef, $category, $templObj, | ||
| 13920 | @list, @dataList, | ||
| 13921 | ); | ||
| 13922 | |||
| 13923 | # Check for improper arguments | ||
| 13924 | if (defined $check) { | ||
| 13925 | |||
| 13926 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_template', @_); | ||
| 13927 | } | ||
| 13928 | |||
| 13929 | # Import the currently selected portions of the notebook list | ||
| 13930 | @list = $self->notebookGetSelectedData(); | ||
| 13931 | if (! @list) { | ||
| 13932 | |||
| 13933 | # Nothing selected | ||
| 13934 | return undef; | ||
| 13935 | } | ||
| 13936 | |||
| 13937 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 13938 | # a single row of the list | ||
| 13939 | $dataRef = $list[0]; | ||
| 13940 | @dataList = @$dataRef; | ||
| 13941 | # The template category is the second item of data | ||
| 13942 | $category = $dataList[1]; | ||
| 13943 | if (! $category) { | ||
| 13944 | |||
| 13945 | # Can't continue | ||
| 13946 | return undef; | ||
| 13947 | } | ||
| 13948 | |||
| 13949 | # Get the template itself (to check it still exists) | ||
| 13950 | $templObj = $self->session->ivShow('templateHash', $category); | ||
| 13951 | if (! $templObj) { | ||
| 13952 | |||
| 13953 | # Can't continue | ||
| 13954 | return undef; | ||
| 13955 | } | ||
| 13956 | |||
| 13957 | # Delete the template | ||
| 13958 | $self->session->pseudoCmd('deletetemplate ' . $category, $self->pseudoCmdMode); | ||
| 13959 | |||
| 13960 | # Update the notebook | ||
| 13961 | $self->updateNotebook(); | ||
| 13962 | |||
| 13963 | return 1; | ||
| 13964 | } | ||
| 13965 | |||
| 13966 | sub buttonDump_template { | ||
| 13967 | |||
| 13968 | # Callback: Displays profile templates in the 'main' window (equivalent to ';listtemplate') | ||
| 13969 | # | ||
| 13970 | # Expected arguments | ||
| 13971 | # (none besides $self) | ||
| 13972 | # | ||
| 13973 | # Return values | ||
| 13974 | # 'undef' on improper arguments | ||
| 13975 | # 1 otherwise | ||
| 13976 | |||
| 13977 | my ($self, $check) = @_; | ||
| 13978 | |||
| 13979 | # Check for improper arguments | ||
| 13980 | if (defined $check) { | ||
| 13981 | |||
| 13982 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_template', @_); | ||
| 13983 | } | ||
| 13984 | |||
| 13985 | # Display the list of profile templates | ||
| 13986 | $self->session->pseudoCmd('listtemplate', $self->pseudoCmdMode); | ||
| 13987 | |||
| 13988 | return 1; | ||
| 13989 | } | ||
| 13990 | |||
| 13991 | # Profile priority button callbacks | ||
| 13992 | |||
| 13993 | sub buttonMoveTop_profPriority { | ||
| 13994 | |||
| 13995 | # Callback: Moves a category of profile to the top of the priority list (comparable to | ||
| 13996 | # ';setprofilepriority') | ||
| 13997 | # | ||
| 13998 | # Expected arguments | ||
| 13999 | # (none besides $self) | ||
| 14000 | # | ||
| 14001 | # Return values | ||
| 14002 | # 'undef' on improper arguments, if no line is selected or if the selected item can't be | ||
| 14003 | # moved to the top | ||
| 14004 | # 1 otherwise | ||
| 14005 | |||
| 14006 | my ($self, $check) = @_; | ||
| 14007 | |||
| 14008 | # Local variables | ||
| 14009 | my ( | ||
| 14010 | $index, $priority, $category, | ||
| 14011 | @priorityList, | ||
| 14012 | ); | ||
| 14013 | |||
| 14014 | # Check for improper arguments | ||
| 14015 | if (defined $check) { | ||
| 14016 | |||
| 14017 | return $axmud::CLIENT->writeImproper( | ||
| 14018 | $self->_objClass . '->buttonMoveTop_profPriority', | ||
| 14019 | @_, | ||
| 14020 | ); | ||
| 14021 | } | ||
| 14022 | |||
| 14023 | # Import the priority list | ||
| 14024 | @priorityList = $self->session->profPriorityList; | ||
| 14025 | |||
| 14026 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 14027 | # contains | ||
| 14028 | ($index, $priority, $category) = $self->profPriorityData(); | ||
| 14029 | if (! defined $index) { | ||
| 14030 | |||
| 14031 | return undef; | ||
| 14032 | } | ||
| 14033 | |||
| 14034 | # $index must be at least 2nd in the list (element 1), else it can't be moved up | ||
| 14035 | if ($index) { | ||
| 14036 | |||
| 14037 | # Move the item to the top of the priority list | ||
| 14038 | splice(@priorityList, $index, 1); | ||
| 14039 | unshift(@priorityList, $category); | ||
| 14040 | } | ||
| 14041 | |||
| 14042 | # Now, try using the client command ';setprofilepriority' with @priorityList as the | ||
| 14043 | # argument. The command checks whether the new arrangement is allowed | ||
| 14044 | if ( | ||
| 14045 | ! $self->session->pseudoCmd( | ||
| 14046 | 'setprofilepriority ' . join(' ', @priorityList), | ||
| 14047 | $self->pseudoCmdMode, | ||
| 14048 | ) | ||
| 14049 | ) { | ||
| 14050 | return undef; | ||
| 14051 | |||
| 14052 | } else { | ||
| 14053 | |||
| 14054 | # Update the notebook (if the priority list has actually changed) | ||
| 14055 | # The single argument makes sure the same item is selected | ||
| 14056 | $self->updateNotebook(0); | ||
| 14057 | return 1; | ||
| 14058 | } | ||
| 14059 | } | ||
| 14060 | |||
| 14061 | sub buttonMoveUp_profPriority { | ||
| 14062 | |||
| 14063 | # Callback: Moves a category of profile up the priority list (comparable to | ||
| 14064 | # ';setprofilepriority') | ||
| 14065 | # | ||
| 14066 | # Expected arguments | ||
| 14067 | # (none besides $self) | ||
| 14068 | # | ||
| 14069 | # Return values | ||
| 14070 | # 'undef' on improper arguments, if no line is selected or if the selected item can't be | ||
| 14071 | # moved up | ||
| 14072 | # 1 otherwise | ||
| 14073 | |||
| 14074 | my ($self, $check) = @_; | ||
| 14075 | |||
| 14076 | # Local variables | ||
| 14077 | my ( | ||
| 14078 | $index, $priority, $category, | ||
| 14079 | @priorityList, | ||
| 14080 | ); | ||
| 14081 | |||
| 14082 | # Check for improper arguments | ||
| 14083 | if (defined $check) { | ||
| 14084 | |||
| 14085 | return $axmud::CLIENT->writeImproper( | ||
| 14086 | $self->_objClass . '->buttonMoveUp_profPriority', | ||
| 14087 | @_, | ||
| 14088 | ); | ||
| 14089 | } | ||
| 14090 | |||
| 14091 | # Import the priority list | ||
| 14092 | @priorityList = $self->session->profPriorityList; | ||
| 14093 | |||
| 14094 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 14095 | # contains | ||
| 14096 | ($index, $priority, $category) = $self->profPriorityData(); | ||
| 14097 | if (! defined $index) { | ||
| 14098 | |||
| 14099 | return undef; | ||
| 14100 | } | ||
| 14101 | |||
| 14102 | # $index must be at least 2nd in the list (element 1), else it can't be moved up | ||
| 14103 | if ($index) { | ||
| 14104 | |||
| 14105 | # Move the item up in the priority list | ||
| 14106 | splice(@priorityList, $index, 1); | ||
| 14107 | splice(@priorityList, ($index - 1), 0, $category); | ||
| 14108 | } | ||
| 14109 | |||
| 14110 | # Now, try using the client command ';setprofilepriority' with @priorityList as the | ||
| 14111 | # argument. The command checks whether the new arrangement is allowed | ||
| 14112 | if ( | ||
| 14113 | ! $self->session->pseudoCmd( | ||
| 14114 | 'setprofilepriority ' . join(' ', @priorityList), | ||
| 14115 | $self->pseudoCmdMode, | ||
| 14116 | ) | ||
| 14117 | ) { | ||
| 14118 | return undef; | ||
| 14119 | |||
| 14120 | } else { | ||
| 14121 | |||
| 14122 | # Update the notebook (if the priority list has actually changed) | ||
| 14123 | # The single argument makes sure the same item is selected | ||
| 14124 | $self->updateNotebook($index - 1); | ||
| 14125 | return 1; | ||
| 14126 | } | ||
| 14127 | } | ||
| 14128 | |||
| 14129 | sub buttonMoveDown_profPriority { | ||
| 14130 | |||
| 14131 | # Callback: Moves a category of profile down the priority list (comparable to | ||
| 14132 | # ';setprofilepriority') | ||
| 14133 | # | ||
| 14134 | # Expected arguments | ||
| 14135 | # (none besides $self) | ||
| 14136 | # | ||
| 14137 | # Return values | ||
| 14138 | # 'undef' on improper arguments, if no line is selected or if the selected item can't be | ||
| 14139 | # moved down | ||
| 14140 | # 1 otherwise | ||
| 14141 | |||
| 14142 | my ($self, $check) = @_; | ||
| 14143 | |||
| 14144 | # Local variables | ||
| 14145 | my ( | ||
| 14146 | $index, $priority, $category, | ||
| 14147 | @priorityList, | ||
| 14148 | ); | ||
| 14149 | |||
| 14150 | # Check for improper arguments | ||
| 14151 | if (defined $check) { | ||
| 14152 | |||
| 14153 | return $axmud::CLIENT->writeImproper( | ||
| 14154 | $self->_objClass . '->buttonMoveDown_profPriority', | ||
| 14155 | @_, | ||
| 14156 | ); | ||
| 14157 | } | ||
| 14158 | |||
| 14159 | # Import the priority list | ||
| 14160 | @priorityList = $self->session->profPriorityList; | ||
| 14161 | |||
| 14162 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 14163 | # contains | ||
| 14164 | ($index, $priority, $category) = $self->profPriorityData(); | ||
| 14165 | if (! defined $index) { | ||
| 14166 | |||
| 14167 | return undef; | ||
| 14168 | } | ||
| 14169 | |||
| 14170 | # Move the item down in the priority list | ||
| 14171 | splice(@priorityList, $index, 1); | ||
| 14172 | splice(@priorityList, ($index + 1), 0, $category); | ||
| 14173 | |||
| 14174 | # Now, try using the client command ';setprofilepriority' with @priorityList as the | ||
| 14175 | # argument. The command checks whether the new arrangement is allowed | ||
| 14176 | if ( | ||
| 14177 | ! $self->session->pseudoCmd( | ||
| 14178 | 'setprofilepriority ' . join(' ', @priorityList), | ||
| 14179 | $self->pseudoCmdMode, | ||
| 14180 | ) | ||
| 14181 | ) { | ||
| 14182 | return undef; | ||
| 14183 | |||
| 14184 | } else { | ||
| 14185 | |||
| 14186 | # Update the notebook (if the priority list has actually changed) | ||
| 14187 | # The single argument makes sure the same item is selected | ||
| 14188 | $self->updateNotebook($index + 1); | ||
| 14189 | return 1; | ||
| 14190 | } | ||
| 14191 | } | ||
| 14192 | |||
| 14193 | sub buttonGivePriority_profPriority { | ||
| 14194 | |||
| 14195 | # Callback: Takes a category of profile which isn't in the priority list and moves it into | ||
| 14196 | # the priority list (comparable to ';setprofilepriority') | ||
| 14197 | # | ||
| 14198 | # Expected arguments | ||
| 14199 | # (none besides $self) | ||
| 14200 | # | ||
| 14201 | # Return values | ||
| 14202 | # 'undef' on improper arguments, if no line is selected, if the selected item is already | ||
| 14203 | # in the priority list or if the 'give priority' operation fails | ||
| 14204 | # 1 otherwise | ||
| 14205 | |||
| 14206 | my ($self, $check) = @_; | ||
| 14207 | |||
| 14208 | # Local variables | ||
| 14209 | my ( | ||
| 14210 | $index, $priority, $category, | ||
| 14211 | @priorityList, | ||
| 14212 | ); | ||
| 14213 | |||
| 14214 | # Check for improper arguments | ||
| 14215 | if (defined $check) { | ||
| 14216 | |||
| 14217 | return $axmud::CLIENT->writeImproper( | ||
| 14218 | $self->_objClass . '->buttonGivePriority_profPriority', | ||
| 14219 | @_, | ||
| 14220 | ); | ||
| 14221 | } | ||
| 14222 | |||
| 14223 | # Import the priority list | ||
| 14224 | @priorityList = $self->session->profPriorityList; | ||
| 14225 | |||
| 14226 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 14227 | # contains | ||
| 14228 | ($index, $priority, $category) = $self->profPriorityData(); | ||
| 14229 | # If the category is already marked as being in the priority list, do nothing | ||
| 14230 | if (! defined $priority || $priority ne '-') { | ||
| 14231 | |||
| 14232 | return undef; | ||
| 14233 | } | ||
| 14234 | |||
| 14235 | # Add the category to the top of the priority list | ||
| 14236 | unshift (@priorityList, $category); | ||
| 14237 | |||
| 14238 | # Now, try using the client command ';setprofilepriority' with @priorityList as the | ||
| 14239 | # argument. The command checks whether the new arrangement is allowed | ||
| 14240 | if ( | ||
| 14241 | ! $self->session->pseudoCmd( | ||
| 14242 | 'setprofilepriority ' . join(' ', @priorityList), | ||
| 14243 | $self->pseudoCmdMode, | ||
| 14244 | ) | ||
| 14245 | ) { | ||
| 14246 | return undef; | ||
| 14247 | |||
| 14248 | } else { | ||
| 14249 | |||
| 14250 | # Update the notebook (if the priority list has actually changed) | ||
| 14251 | # The single argument makes sure the same item is selected | ||
| 14252 | $self->updateNotebook(0); | ||
| 14253 | return 1; | ||
| 14254 | } | ||
| 14255 | } | ||
| 14256 | |||
| 14257 | sub buttonLosePriority_profPriority { | ||
| 14258 | |||
| 14259 | # Callback: Moves a category of profile out of the priority list entirely (comparable to | ||
| 14260 | # ';setprofilepriority') | ||
| 14261 | # | ||
| 14262 | # Expected arguments | ||
| 14263 | # (none besides $self) | ||
| 14264 | # | ||
| 14265 | # Return values | ||
| 14266 | # 'undef' on improper arguments, if no line is selected or if the selected item isn't | ||
| 14267 | # already in the priority list | ||
| 14268 | # 1 otherwise | ||
| 14269 | |||
| 14270 | my ($self, $check) = @_; | ||
| 14271 | |||
| 14272 | # Local variables | ||
| 14273 | my ( | ||
| 14274 | $index, $priority, $category, | ||
| 14275 | @priorityList, | ||
| 14276 | ); | ||
| 14277 | |||
| 14278 | # Check for improper arguments | ||
| 14279 | if (defined $check) { | ||
| 14280 | |||
| 14281 | return $axmud::CLIENT->writeImproper( | ||
| 14282 | $self->_objClass . '->buttonLosePriority_profPriority', | ||
| 14283 | @_, | ||
| 14284 | ); | ||
| 14285 | } | ||
| 14286 | |||
| 14287 | # Import the priority list | ||
| 14288 | @priorityList = $self->session->profPriorityList; | ||
| 14289 | |||
| 14290 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 14291 | # contains | ||
| 14292 | ($index, $priority, $category) = $self->profPriorityData(); | ||
| 14293 | # If the category is already marked as not being in the priority list, do nothing | ||
| 14294 | if (! defined $priority || $priority eq '-') { | ||
| 14295 | |||
| 14296 | return undef; | ||
| 14297 | } | ||
| 14298 | |||
| 14299 | # Remove the category from the priority list | ||
| 14300 | splice (@priorityList, $index, 1); | ||
| 14301 | |||
| 14302 | # Now, try using the client command ';setprofilepriority' with @priorityList as the | ||
| 14303 | # argument. The command checks whether the new arrangement is allowed | ||
| 14304 | if ( | ||
| 14305 | ! $self->session->pseudoCmd( | ||
| 14306 | 'setprofilepriority ' . join(' ', @priorityList), | ||
| 14307 | $self->pseudoCmdMode, | ||
| 14308 | ) | ||
| 14309 | ) { | ||
| 14310 | return undef; | ||
| 14311 | |||
| 14312 | } else { | ||
| 14313 | |||
| 14314 | # Update the notebook (if the priority list has actually changed) | ||
| 14315 | # Use no arguments, so that no item is selected (can't easily predict where in the list | ||
| 14316 | # the profile will now occur) | ||
| 14317 | $self->updateNotebook(); | ||
| 14318 | return 1; | ||
| 14319 | } | ||
| 14320 | } | ||
| 14321 | |||
| 14322 | sub buttonResetList_profPriority { | ||
| 14323 | |||
| 14324 | # Callback: Resets the profile priority list to the default list (comparable to | ||
| 14325 | # ';setprofilepriority', with no arguments) | ||
| 14326 | # | ||
| 14327 | # Expected arguments | ||
| 14328 | # (none besides $self) | ||
| 14329 | # | ||
| 14330 | # Return values | ||
| 14331 | # 'undef' on improper arguments | ||
| 14332 | # 1 otherwise | ||
| 14333 | |||
| 14334 | my ($self, $check) = @_; | ||
| 14335 | |||
| 14336 | # Check for improper arguments | ||
| 14337 | if (defined $check) { | ||
| 14338 | |||
| 14339 | return $axmud::CLIENT->writeImproper( | ||
| 14340 | $self->_objClass . '->buttonResetList_profPriority', | ||
| 14341 | @_, | ||
| 14342 | ); | ||
| 14343 | } | ||
| 14344 | |||
| 14345 | $self->session->pseudoCmd('setprofilepriority', $self->pseudoCmdMode); | ||
| 14346 | $self->updateNotebook(); | ||
| 14347 | |||
| 14348 | return 1; | ||
| 14349 | } | ||
| 14350 | |||
| 14351 | # Cage button callbacks | ||
| 14352 | |||
| 14353 | sub buttonEdit_cage { | ||
| 14354 | |||
| 14355 | # Callback: Edits a cage (equivalent to ';editcage') | ||
| 14356 | # | ||
| 14357 | # Expected arguments | ||
| 14358 | # (none besides $self) | ||
| 14359 | # | ||
| 14360 | # Return values | ||
| 14361 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 14362 | # object no longer exists | ||
| 14363 | # 1 otherwise | ||
| 14364 | |||
| 14365 | my ($self, $check) = @_; | ||
| 14366 | |||
| 14367 | # Local variables | ||
| 14368 | my ( | ||
| 14369 | $dataRef, $cageNamee, $cageObj, $package, | ||
| 14370 | @list, @dataList, | ||
| 14371 | ); | ||
| 14372 | |||
| 14373 | # Check for improper arguments | ||
| 14374 | if (defined $check) { | ||
| 14375 | |||
| 14376 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_cage', @_); | ||
| 14377 | } | ||
| 14378 | |||
| 14379 | # Import the currently selected portions of the notebook list | ||
| 14380 | @list = $self->notebookGetSelectedData(); | ||
| 14381 | if (! @list) { | ||
| 14382 | |||
| 14383 | # Nothing selected | ||
| 14384 | return undef; | ||
| 14385 | } | ||
| 14386 | |||
| 14387 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14388 | # a single row of the list | ||
| 14389 | $dataRef = $list[0]; | ||
| 14390 | @dataList = @$dataRef; | ||
| 14391 | # The cage's name is the second item of data | ||
| 14392 | $cageNamee = $dataList[1]; | ||
| 14393 | if (! $cageNamee) { | ||
| 14394 | |||
| 14395 | # Can't continue | ||
| 14396 | return undef; | ||
| 14397 | } | ||
| 14398 | |||
| 14399 | # Get the cage object itself | ||
| 14400 | $cageObj = $self->session->ivShow('cageHash', $cageNamee); | ||
| 14401 | if (! $cageObj) { | ||
| 14402 | |||
| 14403 | # Can't continue | ||
| 14404 | return undef; | ||
| 14405 | |||
| 14406 | } else { | ||
| 14407 | |||
| 14408 | # Work out the package name of the correct cage 'edit' window | ||
| 14409 | if ($axmud::CLIENT->ivExists('pluginCageEditWinHash', $cageObj->cageType)) { | ||
| 14410 | |||
| 14411 | # Cage 'edit' window added by a plugin | ||
| 14412 | $package = $axmud::CLIENT->ivShow('pluginCageEditWinHash', $cageObj->cageType); | ||
| 14413 | |||
| 14414 | } else { | ||
| 14415 | |||
| 14416 | # Built-in cage 'edit' window | ||
| 14417 | $package = 'Games::Axmud::EditWin::Cage::' . ucfirst($cageObj->cageType); | ||
| 14418 | } | ||
| 14419 | |||
| 14420 | # Open up an 'edit' window to edit the object | ||
| 14421 | $self->createFreeWin( | ||
| 14422 | $package, | ||
| 14423 | $self, | ||
| 14424 | $self->session, | ||
| 14425 | 'Edit ' . $cageObj->cageType . ' cage \'' . $cageObj->name . '\'', | ||
| 14426 | $cageObj, | ||
| 14427 | FALSE, # Not temporary | ||
| 14428 | ); | ||
| 14429 | |||
| 14430 | return 1; | ||
| 14431 | } | ||
| 14432 | } | ||
| 14433 | |||
| 14434 | sub buttonDump_cage { | ||
| 14435 | |||
| 14436 | # Callback: Displays the list of cages to the 'main' window (equivalent to | ||
| 14437 | # ';listcage <switch>') | ||
| 14438 | # | ||
| 14439 | # Expected arguments | ||
| 14440 | # (none besides $self) | ||
| 14441 | # | ||
| 14442 | # Return values | ||
| 14443 | # 'undef' on improper arguments | ||
| 14444 | # 1 otherwise | ||
| 14445 | |||
| 14446 | my ($self, $check) = @_; | ||
| 14447 | |||
| 14448 | # Local variables | ||
| 14449 | my ($tab, $slWidget); | ||
| 14450 | |||
| 14451 | # Check for improper arguments | ||
| 14452 | if (defined $check) { | ||
| 14453 | |||
| 14454 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_cage', @_); | ||
| 14455 | } | ||
| 14456 | |||
| 14457 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 14458 | $tab = $self->notebookGetTab(); | ||
| 14459 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 14460 | |||
| 14461 | # Unselect everything in the list | ||
| 14462 | $slWidget->get_selection->unselect_all(); | ||
| 14463 | |||
| 14464 | # Dump the data | ||
| 14465 | if ($tab eq 'cmd') { | ||
| 14466 | $self->session->pseudoCmd('listcage -c', $self->pseudoCmdMode); | ||
| 14467 | } elsif ($tab eq 'trigger') { | ||
| 14468 | $self->session->pseudoCmd('listcage -t', $self->pseudoCmdMode); | ||
| 14469 | } elsif ($tab eq 'alias') { | ||
| 14470 | $self->session->pseudoCmd('listcage -a', $self->pseudoCmdMode); | ||
| 14471 | } elsif ($tab eq 'macro') { | ||
| 14472 | $self->session->pseudoCmd('listcage -m', $self->pseudoCmdMode); | ||
| 14473 | } elsif ($tab eq 'timer') { | ||
| 14474 | $self->session->pseudoCmd('listcage -i', $self->pseudoCmdMode); | ||
| 14475 | } elsif ($tab eq 'hook') { | ||
| 14476 | $self->session->pseudoCmd('listcage -h', $self->pseudoCmdMode); | ||
| 14477 | } elsif ($tab eq 'route') { | ||
| 14478 | $self->session->pseudoCmd('listcage -r', $self->pseudoCmdMode); | ||
| 14479 | } else { | ||
| 14480 | |||
| 14481 | # Non-standard cages - list them all together | ||
| 14482 | $self->session->pseudoCmd('listcage -x', $self->pseudoCmdMode); | ||
| 14483 | } | ||
| 14484 | |||
| 14485 | # Update the notebook | ||
| 14486 | $self->updateNotebook(); | ||
| 14487 | |||
| 14488 | return 1; | ||
| 14489 | } | ||
| 14490 | |||
| 14491 | sub buttonDumpAll_cage { | ||
| 14492 | |||
| 14493 | # Callback: Displays a list of all cages to the 'main' window (equivalent to | ||
| 14494 | # ';listcage') | ||
| 14495 | # | ||
| 14496 | # Expected arguments | ||
| 14497 | # (none besides $self) | ||
| 14498 | # | ||
| 14499 | # Return values | ||
| 14500 | # 'undef' on improper arguments | ||
| 14501 | # 1 otherwise | ||
| 14502 | |||
| 14503 | my ($self, $check) = @_; | ||
| 14504 | |||
| 14505 | # Local variables | ||
| 14506 | my ($tab, $slWidget, $standard, $package); | ||
| 14507 | |||
| 14508 | # Check for improper arguments | ||
| 14509 | if (defined $check) { | ||
| 14510 | |||
| 14511 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDumpAll_cage', @_); | ||
| 14512 | } | ||
| 14513 | |||
| 14514 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 14515 | $tab = $self->notebookGetTab(); | ||
| 14516 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 14517 | |||
| 14518 | # Unselect everything in the list | ||
| 14519 | $slWidget->get_selection->unselect_all(); | ||
| 14520 | |||
| 14521 | # Dump the data | ||
| 14522 | $self->session->pseudoCmd('listcage', $self->pseudoCmdMode); | ||
| 14523 | |||
| 14524 | # Update the notebook | ||
| 14525 | $self->updateNotebook(); | ||
| 14526 | |||
| 14527 | return 1; | ||
| 14528 | } | ||
| 14529 | |||
| 14530 | # Dictionary button callbacks | ||
| 14531 | |||
| 14532 | sub buttonAdd_dict { | ||
| 14533 | |||
| 14534 | # Callback: Adds a dictionary (equivalent to ';adddictionary') | ||
| 14535 | # | ||
| 14536 | # Expected arguments | ||
| 14537 | # (none besides $self) | ||
| 14538 | # | ||
| 14539 | # Return values | ||
| 14540 | # 'undef' on improper arguments or if a temporary dictionary object can't be created | ||
| 14541 | # 1 otherwise | ||
| 14542 | |||
| 14543 | my ($self, $check) = @_; | ||
| 14544 | |||
| 14545 | # Local variables | ||
| 14546 | my ($tab, $slWidget, $dictObj); | ||
| 14547 | |||
| 14548 | # Check for improper arguments | ||
| 14549 | if (defined $check) { | ||
| 14550 | |||
| 14551 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_dict', @_); | ||
| 14552 | } | ||
| 14553 | |||
| 14554 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 14555 | $tab = $self->notebookGetTab(); | ||
| 14556 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 14557 | |||
| 14558 | # Unselect everything in the list, because we're creating a new dictionary | ||
| 14559 | $slWidget->get_selection->unselect_all(); | ||
| 14560 | |||
| 14561 | # Create a temporary dictionary | ||
| 14562 | $dictObj = Games::Axmud::Obj::Dict->new($self->session, '<temp>', 'English', TRUE); | ||
| 14563 | if (! $dictObj) { | ||
| 14564 | |||
| 14565 | # Can't edit anything | ||
| 14566 | return undef; | ||
| 14567 | |||
| 14568 | } else { | ||
| 14569 | |||
| 14570 | # Open up an 'edit' window to create the new object, replacing the temporary one we've | ||
| 14571 | # just created | ||
| 14572 | $self->createFreeWin( | ||
| 14573 | 'Games::Axmud::EditWin::Dict', | ||
| 14574 | $self, | ||
| 14575 | $self->session, | ||
| 14576 | 'Edit dictionary \'' . $dictObj->name . '\'', | ||
| 14577 | $dictObj, | ||
| 14578 | TRUE, # Temporary object | ||
| 14579 | ); | ||
| 14580 | } | ||
| 14581 | |||
| 14582 | return 1; | ||
| 14583 | } | ||
| 14584 | |||
| 14585 | sub buttonEdit_dict { | ||
| 14586 | |||
| 14587 | # Callback: Edits a dictionary (equivalent to ';editdictionary') | ||
| 14588 | # | ||
| 14589 | # Expected arguments | ||
| 14590 | # (none besides $self) | ||
| 14591 | # | ||
| 14592 | # Return values | ||
| 14593 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 14594 | # object no longer exists | ||
| 14595 | # 1 otherwise | ||
| 14596 | |||
| 14597 | my ($self, $check) = @_; | ||
| 14598 | |||
| 14599 | # Local variables | ||
| 14600 | my ( | ||
| 14601 | $dataRef, $dictName, $dictObj, | ||
| 14602 | @list, @dataList, | ||
| 14603 | ); | ||
| 14604 | |||
| 14605 | # Check for improper arguments | ||
| 14606 | if (defined $check) { | ||
| 14607 | |||
| 14608 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_dict', @_); | ||
| 14609 | } | ||
| 14610 | |||
| 14611 | # Import the currently selected portions of the notebook list | ||
| 14612 | @list = $self->notebookGetSelectedData(); | ||
| 14613 | if (! @list) { | ||
| 14614 | |||
| 14615 | # Nothing selected | ||
| 14616 | return undef; | ||
| 14617 | } | ||
| 14618 | |||
| 14619 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14620 | # a single row of the list | ||
| 14621 | $dataRef = $list[0]; | ||
| 14622 | @dataList = @$dataRef; | ||
| 14623 | # The dictionary name is the second item of data | ||
| 14624 | $dictName = $dataList[1]; | ||
| 14625 | if (! $dictName) { | ||
| 14626 | |||
| 14627 | # Can't continue | ||
| 14628 | return undef; | ||
| 14629 | } | ||
| 14630 | |||
| 14631 | # Get the dictionary itself | ||
| 14632 | $dictObj = $axmud::CLIENT->ivShow('dictHash', $dictName); | ||
| 14633 | if (! $dictObj) { | ||
| 14634 | |||
| 14635 | # Can't continue | ||
| 14636 | return undef; | ||
| 14637 | |||
| 14638 | } else { | ||
| 14639 | |||
| 14640 | # Open up an 'edit' window to edit the object | ||
| 14641 | $self->createFreeWin( | ||
| 14642 | 'Games::Axmud::EditWin::Dict', | ||
| 14643 | $self, | ||
| 14644 | $self->session, | ||
| 14645 | 'Edit dictionary \'' . $dictName . '\'', | ||
| 14646 | $dictObj, | ||
| 14647 | FALSE, # Not temporary | ||
| 14648 | ); | ||
| 14649 | |||
| 14650 | return 1; | ||
| 14651 | } | ||
| 14652 | } | ||
| 14653 | |||
| 14654 | sub buttonSet_dict { | ||
| 14655 | |||
| 14656 | # Callback: Sets the current dictionary (equivalent to ';setdictionary') | ||
| 14657 | # | ||
| 14658 | # Expected arguments | ||
| 14659 | # (none besides $self) | ||
| 14660 | # | ||
| 14661 | # Return values | ||
| 14662 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 14663 | # object no longer exists | ||
| 14664 | # 1 otherwise | ||
| 14665 | |||
| 14666 | my ($self, $check) = @_; | ||
| 14667 | |||
| 14668 | # Local variables | ||
| 14669 | my ( | ||
| 14670 | $dataRef, $dictName, $dictObj, | ||
| 14671 | @list, @dataList, | ||
| 14672 | ); | ||
| 14673 | |||
| 14674 | # Check for improper arguments | ||
| 14675 | if (defined $check) { | ||
| 14676 | |||
| 14677 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonSet_dict', @_); | ||
| 14678 | } | ||
| 14679 | |||
| 14680 | # Import the currently selected portions of the notebook list | ||
| 14681 | @list = $self->notebookGetSelectedData(); | ||
| 14682 | if (! @list) { | ||
| 14683 | |||
| 14684 | # Nothing selected | ||
| 14685 | return undef; | ||
| 14686 | } | ||
| 14687 | |||
| 14688 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14689 | # a single row of the list | ||
| 14690 | $dataRef = $list[0]; | ||
| 14691 | @dataList = @$dataRef; | ||
| 14692 | # The dictionary name is the second item of data | ||
| 14693 | $dictName = $dataList[1]; | ||
| 14694 | if (! $dictName) { | ||
| 14695 | |||
| 14696 | # Can't continue | ||
| 14697 | return undef; | ||
| 14698 | } | ||
| 14699 | |||
| 14700 | # Get the dictionary itself | ||
| 14701 | $dictObj = $axmud::CLIENT->ivShow('dictHash', $dictName); | ||
| 14702 | if (! $dictObj) { | ||
| 14703 | |||
| 14704 | # Can't continue | ||
| 14705 | return undef; | ||
| 14706 | } | ||
| 14707 | |||
| 14708 | # Set the dictionary | ||
| 14709 | $self->session->pseudoCmd('setdictionary ' . $dictName, $self->pseudoCmdMode); | ||
| 14710 | |||
| 14711 | # Update the notebook | ||
| 14712 | $self->updateNotebook(); | ||
| 14713 | |||
| 14714 | return 1; | ||
| 14715 | } | ||
| 14716 | |||
| 14717 | sub buttonClone_dict { | ||
| 14718 | |||
| 14719 | # Callback: Clones the selected dictionary (equivalent to ';clonedictionary') | ||
| 14720 | # | ||
| 14721 | # Expected arguments | ||
| 14722 | # (none besides $self) | ||
| 14723 | # | ||
| 14724 | # Return values | ||
| 14725 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 14726 | # object no longer exists | ||
| 14727 | # 1 otherwise | ||
| 14728 | |||
| 14729 | my ($self, $check) = @_; | ||
| 14730 | |||
| 14731 | # Local variables | ||
| 14732 | my ( | ||
| 14733 | $dataRef, $dictName, $dictObj, $cloneName, | ||
| 14734 | @list, @dataList, | ||
| 14735 | ); | ||
| 14736 | |||
| 14737 | # Check for improper arguments | ||
| 14738 | if (defined $check) { | ||
| 14739 | |||
| 14740 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonClone_dict', @_); | ||
| 14741 | } | ||
| 14742 | |||
| 14743 | # Import the currently selected portions of the notebook list | ||
| 14744 | @list = $self->notebookGetSelectedData(); | ||
| 14745 | if (! @list) { | ||
| 14746 | |||
| 14747 | # Nothing selected | ||
| 14748 | return undef; | ||
| 14749 | } | ||
| 14750 | |||
| 14751 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14752 | # a single row of the list | ||
| 14753 | $dataRef = $list[0]; | ||
| 14754 | @dataList = @$dataRef; | ||
| 14755 | # The dictionary name is the second item of data | ||
| 14756 | $dictName = $dataList[1]; | ||
| 14757 | if (! $dictName) { | ||
| 14758 | |||
| 14759 | # Can't continue | ||
| 14760 | return undef; | ||
| 14761 | } | ||
| 14762 | |||
| 14763 | # Get the dictionary itself | ||
| 14764 | $dictObj = $axmud::CLIENT->ivShow('dictHash', $dictName); | ||
| 14765 | if (! $dictObj) { | ||
| 14766 | |||
| 14767 | # Can't continue | ||
| 14768 | return undef; | ||
| 14769 | } | ||
| 14770 | |||
| 14771 | # Prompt the user for the name of the clone (max 16 chars) | ||
| 14772 | $cloneName = $self->showEntryDialogue( | ||
| 14773 | 'Clone dictionary', | ||
| 14774 | 'Enter a name for the clone (max 16 chars: A-Z a-z _ 0-9)', | ||
| 14775 | 16, # Max chars | ||
| 14776 | ); | ||
| 14777 | |||
| 14778 | if ($cloneName) { | ||
| 14779 | |||
| 14780 | # Clone the dictionary | ||
| 14781 | $self->session->pseudoCmd( | ||
| 14782 | 'clonedictionary ' . $dictName . ' ' . $cloneName, | ||
| 14783 | $self->pseudoCmdMode, | ||
| 14784 | ); | ||
| 14785 | |||
| 14786 | # Update the notebook | ||
| 14787 | $self->updateNotebook(); | ||
| 14788 | } | ||
| 14789 | |||
| 14790 | return 1; | ||
| 14791 | } | ||
| 14792 | |||
| 14793 | sub buttonDelete_dict { | ||
| 14794 | |||
| 14795 | # Callback: Deletes a dictionary (equivalent to ';deletedictionary') | ||
| 14796 | # | ||
| 14797 | # Expected arguments | ||
| 14798 | # (none besides $self) | ||
| 14799 | # | ||
| 14800 | # Return values | ||
| 14801 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 14802 | # object no longer exists | ||
| 14803 | # 1 otherwise | ||
| 14804 | |||
| 14805 | my ($self, $check) = @_; | ||
| 14806 | |||
| 14807 | # Local variables | ||
| 14808 | my ( | ||
| 14809 | $dataRef, $dictName, $dictObj, | ||
| 14810 | @list, @dataList, | ||
| 14811 | ); | ||
| 14812 | |||
| 14813 | # Check for improper arguments | ||
| 14814 | if (defined $check) { | ||
| 14815 | |||
| 14816 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_dict', @_); | ||
| 14817 | } | ||
| 14818 | |||
| 14819 | # Import the currently selected portions of the notebook list | ||
| 14820 | @list = $self->notebookGetSelectedData(); | ||
| 14821 | if (! @list) { | ||
| 14822 | |||
| 14823 | # Nothing selected | ||
| 14824 | return undef; | ||
| 14825 | } | ||
| 14826 | |||
| 14827 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14828 | # a single row of the list | ||
| 14829 | $dataRef = $list[0]; | ||
| 14830 | @dataList = @$dataRef; | ||
| 14831 | # The dictionary name is the second item of data | ||
| 14832 | $dictName = $dataList[1]; | ||
| 14833 | if (! $dictName) { | ||
| 14834 | |||
| 14835 | # Can't continue | ||
| 14836 | return undef; | ||
| 14837 | } | ||
| 14838 | |||
| 14839 | # Get the dictionary itself | ||
| 14840 | $dictObj = $axmud::CLIENT->ivShow('dictHash', $dictName); | ||
| 14841 | if (! $dictObj) { | ||
| 14842 | |||
| 14843 | # Can't continue | ||
| 14844 | return undef; | ||
| 14845 | } | ||
| 14846 | |||
| 14847 | # Delete the dictionary | ||
| 14848 | $self->session->pseudoCmd('deletedictionary ' . $dictName, $self->pseudoCmdMode); | ||
| 14849 | |||
| 14850 | # Update the notebook | ||
| 14851 | $self->updateNotebook(); | ||
| 14852 | |||
| 14853 | return 1; | ||
| 14854 | } | ||
| 14855 | |||
| 14856 | sub buttonDump_dict { | ||
| 14857 | |||
| 14858 | # Callback: Displays a list of dictionaries in the 'main' window (equivalent to | ||
| 14859 | # ';listdictionary') | ||
| 14860 | # | ||
| 14861 | # Expected arguments | ||
| 14862 | # (none besides $self) | ||
| 14863 | # | ||
| 14864 | # Return values | ||
| 14865 | # 'undef' on improper arguments | ||
| 14866 | # 1 otherwise | ||
| 14867 | |||
| 14868 | my ($self, $check) = @_; | ||
| 14869 | |||
| 14870 | # Local variables | ||
| 14871 | my ($tab, $slWidget, $ref); | ||
| 14872 | |||
| 14873 | # Check for improper arguments | ||
| 14874 | if (defined $check) { | ||
| 14875 | |||
| 14876 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_dict', @_); | ||
| 14877 | } | ||
| 14878 | |||
| 14879 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 14880 | $tab = $self->notebookGetTab(); | ||
| 14881 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 14882 | |||
| 14883 | # Unselect everything in the list | ||
| 14884 | $slWidget->get_selection->unselect_all(); | ||
| 14885 | |||
| 14886 | # Display the list of dictionaries | ||
| 14887 | $self->session->pseudoCmd('listdictionary', $self->pseudoCmdMode); | ||
| 14888 | |||
| 14889 | return 1; | ||
| 14890 | } | ||
| 14891 | |||
| 14892 | # Tasklist button callbacks - Available tasks | ||
| 14893 | |||
| 14894 | sub buttonStart_availableTask { | ||
| 14895 | |||
| 14896 | # Callback: Starts the selected task (equivalent to ';starttask') | ||
| 14897 | # | ||
| 14898 | # Expected arguments | ||
| 14899 | # (none besides $self) | ||
| 14900 | # | ||
| 14901 | # Return values | ||
| 14902 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 14903 | # 1 otherwise | ||
| 14904 | |||
| 14905 | my ($self, $check) = @_; | ||
| 14906 | |||
| 14907 | # Local variables | ||
| 14908 | my ( | ||
| 14909 | $dataRef, $taskName, | ||
| 14910 | @list, @dataList, | ||
| 14911 | ); | ||
| 14912 | |||
| 14913 | # Check for improper arguments | ||
| 14914 | if (defined $check) { | ||
| 14915 | |||
| 14916 | return $axmud::CLIENT->writeImproper( | ||
| 14917 | $self->_objClass . '->buttonStart_availableTask', | ||
| 14918 | @_, | ||
| 14919 | ); | ||
| 14920 | } | ||
| 14921 | |||
| 14922 | # Import the currently selected portions of the notebook list | ||
| 14923 | @list = $self->notebookGetSelectedData(); | ||
| 14924 | if (! @list) { | ||
| 14925 | |||
| 14926 | # Nothing selected | ||
| 14927 | return undef; | ||
| 14928 | } | ||
| 14929 | |||
| 14930 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14931 | # a single row of the list | ||
| 14932 | $dataRef = $list[0]; | ||
| 14933 | @dataList = @$dataRef; | ||
| 14934 | # The standard task name is the second item of data | ||
| 14935 | $taskName = $dataList[1]; | ||
| 14936 | if (! $taskName) { | ||
| 14937 | |||
| 14938 | # Can't continue | ||
| 14939 | return undef; | ||
| 14940 | |||
| 14941 | } else { | ||
| 14942 | |||
| 14943 | $self->session->pseudoCmd('starttask ' . $taskName, $self->pseudoCmdMode); | ||
| 14944 | } | ||
| 14945 | |||
| 14946 | return 1; | ||
| 14947 | } | ||
| 14948 | |||
| 14949 | sub buttonStartOptions_availableTask { | ||
| 14950 | |||
| 14951 | # Callback: Starts the selected task after prompting the user to specify task settings | ||
| 14952 | # using a GA::PrefWin::TaskStart window (equivalent to ';starttask <task> <switches>') | ||
| 14953 | # | ||
| 14954 | # Expected arguments | ||
| 14955 | # (none besides $self) | ||
| 14956 | # | ||
| 14957 | # Return values | ||
| 14958 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 14959 | # 1 otherwise | ||
| 14960 | |||
| 14961 | my ($self, $check) = @_; | ||
| 14962 | |||
| 14963 | # Local variables | ||
| 14964 | my ( | ||
| 14965 | $dataRef, $taskName, | ||
| 14966 | @list, @dataList, | ||
| 14967 | ); | ||
| 14968 | |||
| 14969 | # Check for improper arguments | ||
| 14970 | if (defined $check) { | ||
| 14971 | |||
| 14972 | return $axmud::CLIENT->writeImproper( | ||
| 14973 | $self->_objClass . '->buttonStartOptions_availableTask', | ||
| 14974 | @_, | ||
| 14975 | ); | ||
| 14976 | } | ||
| 14977 | |||
| 14978 | # Import the currently selected portions of the notebook list | ||
| 14979 | @list = $self->notebookGetSelectedData(); | ||
| 14980 | if (! @list) { | ||
| 14981 | |||
| 14982 | # Nothing selected | ||
| 14983 | return undef; | ||
| 14984 | } | ||
| 14985 | |||
| 14986 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 14987 | # a single row of the list | ||
| 14988 | $dataRef = $list[0]; | ||
| 14989 | @dataList = @$dataRef; | ||
| 14990 | # The standard task name is the second item of data | ||
| 14991 | $taskName = $dataList[1]; | ||
| 14992 | if (! $taskName) { | ||
| 14993 | |||
| 14994 | # Can't continue | ||
| 14995 | return undef; | ||
| 14996 | |||
| 14997 | } else { | ||
| 14998 | |||
| 14999 | # Open up a task start 'pref' window to specify task settings | ||
| 15000 | $self->createFreeWin( | ||
| 15001 | 'Games::Axmud::PrefWin::TaskStart', | ||
| 15002 | $self, | ||
| 15003 | $self->session, | ||
| 15004 | '\'' . $taskName . '\' task preferences', | ||
| 15005 | undef, # No ->editObj | ||
| 15006 | FALSE, # Not temporary | ||
| 15007 | # Config | ||
| 15008 | 'type' => 'current', # Current tasklist | ||
| 15009 | 'task_name' => $taskName, | ||
| 15010 | ); | ||
| 15011 | } | ||
| 15012 | |||
| 15013 | return 1; | ||
| 15014 | } | ||
| 15015 | |||
| 15016 | sub buttonAddInitial_availableTask { | ||
| 15017 | |||
| 15018 | # Callback: Adds a new task to the global initial tasklist after prompting the user to | ||
| 15019 | # specify task settings using a GA::PrefWin::TaskStar window (equivalent to | ||
| 15020 | # ';addinitialtask <task> <switches>') | ||
| 15021 | # | ||
| 15022 | # Expected arguments | ||
| 15023 | # (none besides $self) | ||
| 15024 | # | ||
| 15025 | # Return values | ||
| 15026 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15027 | # 1 otherwise | ||
| 15028 | |||
| 15029 | my ($self, $check) = @_; | ||
| 15030 | |||
| 15031 | # Local variables | ||
| 15032 | my ( | ||
| 15033 | $dataRef, $taskName, | ||
| 15034 | @list, @dataList, | ||
| 15035 | ); | ||
| 15036 | |||
| 15037 | # Check for improper arguments | ||
| 15038 | if (defined $check) { | ||
| 15039 | |||
| 15040 | return $axmud::CLIENT->writeImproper( | ||
| 15041 | $self->_objClass . '->buttonAddInitial_availableTask', | ||
| 15042 | @_, | ||
| 15043 | ); | ||
| 15044 | } | ||
| 15045 | |||
| 15046 | # Import the currently selected portions of the notebook list | ||
| 15047 | @list = $self->notebookGetSelectedData(); | ||
| 15048 | if (! @list) { | ||
| 15049 | |||
| 15050 | # Nothing selected | ||
| 15051 | return undef; | ||
| 15052 | } | ||
| 15053 | |||
| 15054 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15055 | # a single row of the list | ||
| 15056 | $dataRef = $list[0]; | ||
| 15057 | @dataList = @$dataRef; | ||
| 15058 | # The standard task name is the second item of data | ||
| 15059 | $taskName = $dataList[1]; | ||
| 15060 | if (! $taskName) { | ||
| 15061 | |||
| 15062 | # Can't continue | ||
| 15063 | return undef; | ||
| 15064 | |||
| 15065 | } else { | ||
| 15066 | |||
| 15067 | # Open up a task start 'pref' window to specify task settings | ||
| 15068 | $self->createFreeWin( | ||
| 15069 | 'Games::Axmud::PrefWin::TaskStart', | ||
| 15070 | $self, | ||
| 15071 | $self->session, | ||
| 15072 | '\'' . $taskName . '\' task preferences', | ||
| 15073 | undef, # No ->editObj | ||
| 15074 | FALSE, # Not temporary | ||
| 15075 | # Config | ||
| 15076 | 'type' => 'global_initial', # Global initial tasklist | ||
| 15077 | 'task_name' => $taskName, | ||
| 15078 | ); | ||
| 15079 | } | ||
| 15080 | |||
| 15081 | return 1; | ||
| 15082 | } | ||
| 15083 | |||
| 15084 | sub buttonAddCustom_availableTask { | ||
| 15085 | |||
| 15086 | # Callback: Adds a new task to the custom tasklist after prompting the user to specify task | ||
| 15087 | # settings using a GA::PrefWin::TaskStar window (equivalent to | ||
| 15088 | # ';addcustomtask <task> <name> <switches>') | ||
| 15089 | # | ||
| 15090 | # Expected arguments | ||
| 15091 | # (none besides $self) | ||
| 15092 | # | ||
| 15093 | # Return values | ||
| 15094 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15095 | # 1 otherwise | ||
| 15096 | |||
| 15097 | my ($self, $check) = @_; | ||
| 15098 | |||
| 15099 | # Local variables | ||
| 15100 | my ( | ||
| 15101 | $dataRef, $taskName, | ||
| 15102 | @list, @dataList, | ||
| 15103 | ); | ||
| 15104 | |||
| 15105 | # Check for improper arguments | ||
| 15106 | if (defined $check) { | ||
| 15107 | |||
| 15108 | return $axmud::CLIENT->writeImproper( | ||
| 15109 | $self->_objClass . '->buttonAddCustom_availableTask', | ||
| 15110 | @_, | ||
| 15111 | ); | ||
| 15112 | } | ||
| 15113 | |||
| 15114 | # Import the currently selected portions of the notebook list | ||
| 15115 | @list = $self->notebookGetSelectedData(); | ||
| 15116 | if (! @list) { | ||
| 15117 | |||
| 15118 | # Nothing selected | ||
| 15119 | return undef; | ||
| 15120 | } | ||
| 15121 | |||
| 15122 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15123 | # a single row of the list | ||
| 15124 | $dataRef = $list[0]; | ||
| 15125 | @dataList = @$dataRef; | ||
| 15126 | # The standard task name is the second item of data | ||
| 15127 | $taskName = $dataList[1]; | ||
| 15128 | if (! $taskName) { | ||
| 15129 | |||
| 15130 | # Can't continue | ||
| 15131 | return undef; | ||
| 15132 | |||
| 15133 | } else { | ||
| 15134 | |||
| 15135 | # Open up a task start 'pref' window to specify task settings | ||
| 15136 | $self->createFreeWin( | ||
| 15137 | 'Games::Axmud::PrefWin::TaskStart', | ||
| 15138 | $self, | ||
| 15139 | $self->session, | ||
| 15140 | '\'' . $taskName . '\' task preferences', | ||
| 15141 | undef, # No ->editObj | ||
| 15142 | FALSE, # Not temporary | ||
| 15143 | # Config | ||
| 15144 | 'type' => 'custom', # Custom tasklist | ||
| 15145 | 'task_name' => $taskName, | ||
| 15146 | ); | ||
| 15147 | } | ||
| 15148 | |||
| 15149 | return 1; | ||
| 15150 | } | ||
| 15151 | |||
| 15152 | sub buttonHalt_availableTask { | ||
| 15153 | |||
| 15154 | # Callback: Halts gracefully all copies of the selected task (equivalent to | ||
| 15155 | # ';halttask <task>') | ||
| 15156 | # | ||
| 15157 | # Expected arguments | ||
| 15158 | # (none besides $self) | ||
| 15159 | # | ||
| 15160 | # Return values | ||
| 15161 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15162 | # 1 otherwise | ||
| 15163 | |||
| 15164 | my ($self, $check) = @_; | ||
| 15165 | |||
| 15166 | # Local variables | ||
| 15167 | my ( | ||
| 15168 | $dataRef, $taskName, | ||
| 15169 | @list, @dataList, | ||
| 15170 | ); | ||
| 15171 | |||
| 15172 | # Check for improper arguments | ||
| 15173 | if (defined $check) { | ||
| 15174 | |||
| 15175 | return $axmud::CLIENT->writeImproper( | ||
| 15176 | $self->_objClass . '->buttonHalt_availableTask', | ||
| 15177 | @_, | ||
| 15178 | ); | ||
| 15179 | } | ||
| 15180 | |||
| 15181 | # Import the currently selected portions of the notebook list | ||
| 15182 | @list = $self->notebookGetSelectedData(); | ||
| 15183 | if (! @list) { | ||
| 15184 | |||
| 15185 | # Nothing selected | ||
| 15186 | return undef; | ||
| 15187 | } | ||
| 15188 | |||
| 15189 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15190 | # a single row of the list | ||
| 15191 | $dataRef = $list[0]; | ||
| 15192 | @dataList = @$dataRef; | ||
| 15193 | # The standard task name is the second item of data | ||
| 15194 | $taskName = $dataList[1]; | ||
| 15195 | if (! $taskName) { | ||
| 15196 | |||
| 15197 | # Can't continue | ||
| 15198 | return undef; | ||
| 15199 | |||
| 15200 | } else { | ||
| 15201 | |||
| 15202 | # Halt gracefully all copies of this task | ||
| 15203 | $self->session->pseudoCmd('halttask ' . $taskName, $self->pseudoCmdMode); | ||
| 15204 | |||
| 15205 | # Update the notebook | ||
| 15206 | $self->updateNotebook(); | ||
| 15207 | } | ||
| 15208 | |||
| 15209 | return 1; | ||
| 15210 | } | ||
| 15211 | |||
| 15212 | sub buttonKill_availableTask { | ||
| 15213 | |||
| 15214 | # Callback: Kills all copies of the selected task (equivalent to ';killtask <task>') | ||
| 15215 | # | ||
| 15216 | # Expected arguments | ||
| 15217 | # (none besides $self) | ||
| 15218 | # | ||
| 15219 | # Return values | ||
| 15220 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15221 | # 1 otherwise | ||
| 15222 | |||
| 15223 | my ($self, $check) = @_; | ||
| 15224 | |||
| 15225 | # Local variables | ||
| 15226 | my ( | ||
| 15227 | $dataRef, $taskName, | ||
| 15228 | @list, @dataList, | ||
| 15229 | ); | ||
| 15230 | |||
| 15231 | # Check for improper arguments | ||
| 15232 | if (defined $check) { | ||
| 15233 | |||
| 15234 | return $axmud::CLIENT->writeImproper( | ||
| 15235 | $self->_objClass . '->buttonKill_availableTask', | ||
| 15236 | @_, | ||
| 15237 | ); | ||
| 15238 | } | ||
| 15239 | |||
| 15240 | # Import the currently selected portions of the notebook list | ||
| 15241 | @list = $self->notebookGetSelectedData(); | ||
| 15242 | if (! @list) { | ||
| 15243 | |||
| 15244 | # Nothing selected | ||
| 15245 | return undef; | ||
| 15246 | } | ||
| 15247 | |||
| 15248 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15249 | # a single row of the list | ||
| 15250 | $dataRef = $list[0]; | ||
| 15251 | @dataList = @$dataRef; | ||
| 15252 | # The standard task name is the second item of data | ||
| 15253 | $taskName = $dataList[1]; | ||
| 15254 | if (! $taskName) { | ||
| 15255 | |||
| 15256 | # Can't continue | ||
| 15257 | return undef; | ||
| 15258 | |||
| 15259 | } else { | ||
| 15260 | |||
| 15261 | # Kill all copies of this task | ||
| 15262 | $self->session->pseudoCmd('killtask ' . $taskName, $self->pseudoCmdMode); | ||
| 15263 | |||
| 15264 | # Update the notebook | ||
| 15265 | $self->updateNotebook(); | ||
| 15266 | } | ||
| 15267 | |||
| 15268 | return 1; | ||
| 15269 | } | ||
| 15270 | |||
| 15271 | sub buttonPause_availableTask { | ||
| 15272 | |||
| 15273 | # Callback: Pauses all copies of the selected task (equivalent to ';pausetask <task>') | ||
| 15274 | # | ||
| 15275 | # Expected arguments | ||
| 15276 | # (none besides $self) | ||
| 15277 | # | ||
| 15278 | # Return values | ||
| 15279 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15280 | # 1 otherwise | ||
| 15281 | |||
| 15282 | my ($self, $check) = @_; | ||
| 15283 | |||
| 15284 | # Local variables | ||
| 15285 | my ( | ||
| 15286 | $dataRef, $taskName, | ||
| 15287 | @list, @dataList, | ||
| 15288 | ); | ||
| 15289 | |||
| 15290 | # Check for improper arguments | ||
| 15291 | if (defined $check) { | ||
| 15292 | |||
| 15293 | return $axmud::CLIENT->writeImproper( | ||
| 15294 | $self->_objClass . '->buttonPause_availableTask', | ||
| 15295 | @_, | ||
| 15296 | ); | ||
| 15297 | } | ||
| 15298 | |||
| 15299 | # Import the currently selected portions of the notebook list | ||
| 15300 | @list = $self->notebookGetSelectedData(); | ||
| 15301 | if (! @list) { | ||
| 15302 | |||
| 15303 | # Nothing selected | ||
| 15304 | return undef; | ||
| 15305 | } | ||
| 15306 | |||
| 15307 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15308 | # a single row of the list | ||
| 15309 | $dataRef = $list[0]; | ||
| 15310 | @dataList = @$dataRef; | ||
| 15311 | # The standard task name is the second item of data | ||
| 15312 | $taskName = $dataList[1]; | ||
| 15313 | if (! $taskName) { | ||
| 15314 | |||
| 15315 | # Can't continue | ||
| 15316 | return undef; | ||
| 15317 | |||
| 15318 | } else { | ||
| 15319 | |||
| 15320 | # Pause all copies of this task | ||
| 15321 | $self->session->pseudoCmd('pausetask ' . $taskName, $self->pseudoCmdMode); | ||
| 15322 | |||
| 15323 | # Update the notebook | ||
| 15324 | $self->updateNotebook(); | ||
| 15325 | } | ||
| 15326 | |||
| 15327 | return 1; | ||
| 15328 | } | ||
| 15329 | |||
| 15330 | sub buttonSafeResume_task { | ||
| 15331 | |||
| 15332 | # Callback: Resumes all tasks safely (equivalent to ';resumetask') | ||
| 15333 | # | ||
| 15334 | # Expected arguments | ||
| 15335 | # (none besides $self) | ||
| 15336 | # | ||
| 15337 | # Return values | ||
| 15338 | # 'undef' on improper arguments | ||
| 15339 | # 1 otherwise | ||
| 15340 | |||
| 15341 | my ($self, $check) = @_; | ||
| 15342 | |||
| 15343 | # Local variables | ||
| 15344 | my ($tab, $slWidget); | ||
| 15345 | |||
| 15346 | # Check for improper arguments | ||
| 15347 | if (defined $check) { | ||
| 15348 | |||
| 15349 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonSafeResume_task', @_); | ||
| 15350 | } | ||
| 15351 | |||
| 15352 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 15353 | $tab = $self->notebookGetTab(); | ||
| 15354 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 15355 | |||
| 15356 | # Unselect everything in the list | ||
| 15357 | $slWidget->get_selection->unselect_all(); | ||
| 15358 | |||
| 15359 | # Reumse paused tasks | ||
| 15360 | $self->session->pseudoCmd('resumetask', $self->pseudoCmdMode); | ||
| 15361 | |||
| 15362 | # Update the notebook | ||
| 15363 | $self->updateNotebook(); | ||
| 15364 | |||
| 15365 | return 1; | ||
| 15366 | } | ||
| 15367 | |||
| 15368 | sub buttonReset_availableTask { | ||
| 15369 | |||
| 15370 | # Callback: Resets all copies of the selected task (equivalent to ';resettask <task>') | ||
| 15371 | # | ||
| 15372 | # Expected arguments | ||
| 15373 | # (none besides $self) | ||
| 15374 | # | ||
| 15375 | # Return values | ||
| 15376 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15377 | # 1 otherwise | ||
| 15378 | |||
| 15379 | my ($self, $check) = @_; | ||
| 15380 | |||
| 15381 | # Local variables | ||
| 15382 | my ( | ||
| 15383 | $dataRef, $taskName, | ||
| 15384 | @list, @dataList, | ||
| 15385 | ); | ||
| 15386 | |||
| 15387 | # Check for improper arguments | ||
| 15388 | if (defined $check) { | ||
| 15389 | |||
| 15390 | return $axmud::CLIENT->writeImproper( | ||
| 15391 | $self->_objClass . '->buttonReset_availableTask', | ||
| 15392 | @_, | ||
| 15393 | ); | ||
| 15394 | } | ||
| 15395 | |||
| 15396 | # Import the currently selected portions of the notebook list | ||
| 15397 | @list = $self->notebookGetSelectedData(); | ||
| 15398 | if (! @list) { | ||
| 15399 | |||
| 15400 | # Nothing selected | ||
| 15401 | return undef; | ||
| 15402 | } | ||
| 15403 | |||
| 15404 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15405 | # a single row of the list | ||
| 15406 | $dataRef = $list[0]; | ||
| 15407 | @dataList = @$dataRef; | ||
| 15408 | # The standard task name is the second item of data | ||
| 15409 | $taskName = $dataList[1]; | ||
| 15410 | if (! $taskName) { | ||
| 15411 | |||
| 15412 | # Can't continue | ||
| 15413 | return undef; | ||
| 15414 | |||
| 15415 | } else { | ||
| 15416 | |||
| 15417 | # Pause all copies of this task | ||
| 15418 | $self->session->pseudoCmd('resettask ' . $taskName, $self->pseudoCmdMode); | ||
| 15419 | |||
| 15420 | # Update the notebook | ||
| 15421 | $self->updateNotebook(); | ||
| 15422 | } | ||
| 15423 | |||
| 15424 | return 1; | ||
| 15425 | } | ||
| 15426 | |||
| 15427 | sub buttonHelp_availableTask { | ||
| 15428 | |||
| 15429 | # Callback: Shows help for the selected task (equivalent to ';taskhelp <task>') | ||
| 15430 | # | ||
| 15431 | # Expected arguments | ||
| 15432 | # (none besides $self) | ||
| 15433 | # | ||
| 15434 | # Return values | ||
| 15435 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15436 | # 1 otherwise | ||
| 15437 | |||
| 15438 | my ($self, $check) = @_; | ||
| 15439 | |||
| 15440 | # Local variables | ||
| 15441 | my ( | ||
| 15442 | $dataRef, $taskName, | ||
| 15443 | @list, @dataList, | ||
| 15444 | ); | ||
| 15445 | |||
| 15446 | # Check for improper arguments | ||
| 15447 | if (defined $check) { | ||
| 15448 | |||
| 15449 | return $axmud::CLIENT->writeImproper( | ||
| 15450 | $self->_objClass . '->buttonHelp_availableTask', | ||
| 15451 | @_, | ||
| 15452 | ); | ||
| 15453 | } | ||
| 15454 | |||
| 15455 | # Import the currently selected portions of the notebook list | ||
| 15456 | @list = $self->notebookGetSelectedData(); | ||
| 15457 | if (! @list) { | ||
| 15458 | |||
| 15459 | # Nothing selected | ||
| 15460 | return undef; | ||
| 15461 | } | ||
| 15462 | |||
| 15463 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15464 | # a single row of the list | ||
| 15465 | $dataRef = $list[0]; | ||
| 15466 | @dataList = @$dataRef; | ||
| 15467 | # The standard task name is the second item of data | ||
| 15468 | $taskName = $dataList[1]; | ||
| 15469 | if (! $taskName) { | ||
| 15470 | |||
| 15471 | # Can't continue | ||
| 15472 | return undef; | ||
| 15473 | |||
| 15474 | } else { | ||
| 15475 | |||
| 15476 | # Pause all copies of this task | ||
| 15477 | $self->session->pseudoCmd('taskhelp ' . $taskName, $self->pseudoCmdMode); | ||
| 15478 | |||
| 15479 | # Update the notebook | ||
| 15480 | $self->updateNotebook(); | ||
| 15481 | } | ||
| 15482 | |||
| 15483 | return 1; | ||
| 15484 | } | ||
| 15485 | |||
| 15486 | # Tasklist button callbacks - Current tasklist | ||
| 15487 | |||
| 15488 | sub buttonEdit_task { | ||
| 15489 | |||
| 15490 | # Callback: Edits the selected task (equivalent to ';edittask') | ||
| 15491 | # | ||
| 15492 | # Expected arguments | ||
| 15493 | # (none besides $self) | ||
| 15494 | # | ||
| 15495 | # Return values | ||
| 15496 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 15497 | # object no longer exists | ||
| 15498 | # 1 otherwise | ||
| 15499 | |||
| 15500 | my ($self, $check) = @_; | ||
| 15501 | |||
| 15502 | # Local variables | ||
| 15503 | my ( | ||
| 15504 | $dataRef, $taskName, $taskObj, | ||
| 15505 | @list, @dataList, | ||
| 15506 | ); | ||
| 15507 | |||
| 15508 | # Check for improper arguments | ||
| 15509 | if (defined $check) { | ||
| 15510 | |||
| 15511 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_task', @_); | ||
| 15512 | } | ||
| 15513 | |||
| 15514 | # Import the currently selected portions of the notebook list | ||
| 15515 | @list = $self->notebookGetSelectedData(); | ||
| 15516 | if (! @list) { | ||
| 15517 | |||
| 15518 | # Nothing selected | ||
| 15519 | return undef; | ||
| 15520 | } | ||
| 15521 | |||
| 15522 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15523 | # a single row of the list | ||
| 15524 | $dataRef = $list[0]; | ||
| 15525 | @dataList = @$dataRef; | ||
| 15526 | # The unique task name is the first item of data | ||
| 15527 | $taskName = $dataList[0]; | ||
| 15528 | if (! $taskName) { | ||
| 15529 | |||
| 15530 | # Can't continue | ||
| 15531 | return undef; | ||
| 15532 | } | ||
| 15533 | |||
| 15534 | # Get the task reference itself | ||
| 15535 | $taskObj = $self->session->ivShow('currentTaskHash', $taskName); | ||
| 15536 | if (! $taskObj) { | ||
| 15537 | |||
| 15538 | # Can't continue | ||
| 15539 | return undef; | ||
| 15540 | |||
| 15541 | } else { | ||
| 15542 | |||
| 15543 | # Open up an 'edit' window to edit the object | ||
| 15544 | $self->createFreeWin( | ||
| 15545 | 'Games::Axmud::EditWin::Task', | ||
| 15546 | $self, | ||
| 15547 | $self->session, | ||
| 15548 | 'Edit ' . $taskObj->prettyName . ' task', | ||
| 15549 | $taskObj, | ||
| 15550 | FALSE, # Not temporary | ||
| 15551 | # Config | ||
| 15552 | 'edit_flag' => FALSE, # Some IVs for current tasks not editable | ||
| 15553 | ); | ||
| 15554 | |||
| 15555 | return 1; | ||
| 15556 | } | ||
| 15557 | } | ||
| 15558 | |||
| 15559 | sub buttonHalt_task { | ||
| 15560 | |||
| 15561 | # Callback: Halts the selected task gracefully (equivalent to ';halttask') | ||
| 15562 | # | ||
| 15563 | # Expected arguments | ||
| 15564 | # (none besides $self) | ||
| 15565 | # | ||
| 15566 | # Return values | ||
| 15567 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 15568 | # object no longer exists | ||
| 15569 | # 1 otherwise | ||
| 15570 | |||
| 15571 | my ($self, $check) = @_; | ||
| 15572 | |||
| 15573 | # Local variables | ||
| 15574 | my ( | ||
| 15575 | $dataRef, $taskName, | ||
| 15576 | @list, @dataList, | ||
| 15577 | ); | ||
| 15578 | |||
| 15579 | # Check for improper arguments | ||
| 15580 | if (defined $check) { | ||
| 15581 | |||
| 15582 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonHalt_task', @_); | ||
| 15583 | } | ||
| 15584 | |||
| 15585 | # Import the currently selected portions of the notebook list | ||
| 15586 | @list = $self->notebookGetSelectedData(); | ||
| 15587 | if (! @list) { | ||
| 15588 | |||
| 15589 | # Nothing selected | ||
| 15590 | return undef; | ||
| 15591 | } | ||
| 15592 | |||
| 15593 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15594 | # a single row of the list | ||
| 15595 | $dataRef = $list[0]; | ||
| 15596 | @dataList = @$dataRef; | ||
| 15597 | # The unique task name is the first item of data | ||
| 15598 | $taskName = $dataList[0]; | ||
| 15599 | if (! $taskName) { | ||
| 15600 | |||
| 15601 | # Can't continue | ||
| 15602 | return undef; | ||
| 15603 | |||
| 15604 | } else { | ||
| 15605 | |||
| 15606 | # Halt the task | ||
| 15607 | $self->session->pseudoCmd('halttask ' . $taskName, $self->pseudoCmdMode); | ||
| 15608 | |||
| 15609 | # Update the notebook | ||
| 15610 | $self->updateNotebook(); | ||
| 15611 | } | ||
| 15612 | |||
| 15613 | return 1; | ||
| 15614 | } | ||
| 15615 | |||
| 15616 | sub buttonHaltAll_task { | ||
| 15617 | |||
| 15618 | # Callback: Halts all tasks gracefully (equivalent to ';halttask -a') | ||
| 15619 | # | ||
| 15620 | # Expected arguments | ||
| 15621 | # (none besides $self) | ||
| 15622 | # | ||
| 15623 | # Return values | ||
| 15624 | # 'undef' on improper arguments | ||
| 15625 | # 1 otherwise | ||
| 15626 | |||
| 15627 | my ($self, $check) = @_; | ||
| 15628 | |||
| 15629 | # Local variables | ||
| 15630 | my ($tab, $slWidget); | ||
| 15631 | |||
| 15632 | # Check for improper arguments | ||
| 15633 | if (defined $check) { | ||
| 15634 | |||
| 15635 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonHaltAll_task', @_); | ||
| 15636 | } | ||
| 15637 | |||
| 15638 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 15639 | $tab = $self->notebookGetTab(); | ||
| 15640 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 15641 | |||
| 15642 | # Unselect everything in the list | ||
| 15643 | $slWidget->get_selection->unselect_all(); | ||
| 15644 | |||
| 15645 | # Halt all tasks | ||
| 15646 | $self->session->pseudoCmd('halttask -a', $self->pseudoCmdMode); | ||
| 15647 | |||
| 15648 | # Update the notebook | ||
| 15649 | $self->updateNotebook(); | ||
| 15650 | |||
| 15651 | return 1; | ||
| 15652 | } | ||
| 15653 | |||
| 15654 | sub buttonKill_task { | ||
| 15655 | |||
| 15656 | # Callback: Kills the selected task immediately (equivalent to ';killtask') | ||
| 15657 | # | ||
| 15658 | # Expected arguments | ||
| 15659 | # (none besides $self) | ||
| 15660 | # | ||
| 15661 | # Return values | ||
| 15662 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 15663 | # object no longer exists | ||
| 15664 | # 1 otherwise | ||
| 15665 | |||
| 15666 | my ($self, $check) = @_; | ||
| 15667 | |||
| 15668 | # Local variables | ||
| 15669 | my ( | ||
| 15670 | $dataRef, $taskName, | ||
| 15671 | @list, @dataList, | ||
| 15672 | ); | ||
| 15673 | |||
| 15674 | # Check for improper arguments | ||
| 15675 | if (defined $check) { | ||
| 15676 | |||
| 15677 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonKill_task', @_); | ||
| 15678 | } | ||
| 15679 | |||
| 15680 | # Import the currently selected portions of the notebook list | ||
| 15681 | @list = $self->notebookGetSelectedData(); | ||
| 15682 | if (! @list) { | ||
| 15683 | |||
| 15684 | # Nothing selected | ||
| 15685 | return undef; | ||
| 15686 | } | ||
| 15687 | |||
| 15688 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15689 | # a single row of the list | ||
| 15690 | $dataRef = $list[0]; | ||
| 15691 | @dataList = @$dataRef; | ||
| 15692 | # The unique task name is the first item of data | ||
| 15693 | $taskName = $dataList[0]; | ||
| 15694 | if (! $taskName) { | ||
| 15695 | |||
| 15696 | # Can't continue | ||
| 15697 | return undef; | ||
| 15698 | |||
| 15699 | } else { | ||
| 15700 | |||
| 15701 | # Kill the task | ||
| 15702 | $self->session->pseudoCmd('killtask ' . $taskName, $self->pseudoCmdMode); | ||
| 15703 | |||
| 15704 | # Update the notebook | ||
| 15705 | $self->updateNotebook(); | ||
| 15706 | } | ||
| 15707 | |||
| 15708 | return 1; | ||
| 15709 | } | ||
| 15710 | |||
| 15711 | sub buttonKillAll_task { | ||
| 15712 | |||
| 15713 | # Callback: Kills all tasks immediately (equivalent to ';killtask -a') | ||
| 15714 | # | ||
| 15715 | # Expected arguments | ||
| 15716 | # (none besides $self) | ||
| 15717 | # | ||
| 15718 | # Return values | ||
| 15719 | # 'undef' on improper arguments | ||
| 15720 | # 1 otherwise | ||
| 15721 | |||
| 15722 | my ($self, $check) = @_; | ||
| 15723 | |||
| 15724 | # Local variables | ||
| 15725 | my ($tab, $slWidget); | ||
| 15726 | |||
| 15727 | # Check for improper arguments | ||
| 15728 | if (defined $check) { | ||
| 15729 | |||
| 15730 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonKillAll_task', @_); | ||
| 15731 | } | ||
| 15732 | |||
| 15733 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 15734 | $tab = $self->notebookGetTab(); | ||
| 15735 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 15736 | |||
| 15737 | # Unselect everything in the list | ||
| 15738 | $slWidget->get_selection->unselect_all(); | ||
| 15739 | |||
| 15740 | # Halt all tasks | ||
| 15741 | $self->session->pseudoCmd('killtask -a', $self->pseudoCmdMode); | ||
| 15742 | |||
| 15743 | # Update the notebook | ||
| 15744 | $self->updateNotebook(); | ||
| 15745 | |||
| 15746 | return 1; | ||
| 15747 | } | ||
| 15748 | |||
| 15749 | sub buttonPause_task { | ||
| 15750 | |||
| 15751 | # Callback: Pauses the selected task (equivalent to ';pausetask') | ||
| 15752 | # | ||
| 15753 | # Expected arguments | ||
| 15754 | # (none besides $self) | ||
| 15755 | # | ||
| 15756 | # Return values | ||
| 15757 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 15758 | # object no longer exists | ||
| 15759 | # 1 otherwise | ||
| 15760 | |||
| 15761 | my ($self, $check) = @_; | ||
| 15762 | |||
| 15763 | # Local variables | ||
| 15764 | my ( | ||
| 15765 | $dataRef, $taskName, | ||
| 15766 | @list, @dataList, | ||
| 15767 | ); | ||
| 15768 | |||
| 15769 | # Check for improper arguments | ||
| 15770 | if (defined $check) { | ||
| 15771 | |||
| 15772 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonPause_task', @_); | ||
| 15773 | } | ||
| 15774 | |||
| 15775 | # Import the currently selected portions of the notebook list | ||
| 15776 | @list = $self->notebookGetSelectedData(); | ||
| 15777 | if (! @list) { | ||
| 15778 | |||
| 15779 | # Nothing selected | ||
| 15780 | return undef; | ||
| 15781 | } | ||
| 15782 | |||
| 15783 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15784 | # a single row of the list | ||
| 15785 | $dataRef = $list[0]; | ||
| 15786 | @dataList = @$dataRef; | ||
| 15787 | # The unique task name is the first item of data | ||
| 15788 | $taskName = $dataList[0]; | ||
| 15789 | if (! $taskName) { | ||
| 15790 | |||
| 15791 | # Can't continue | ||
| 15792 | return undef; | ||
| 15793 | |||
| 15794 | } else { | ||
| 15795 | |||
| 15796 | # Pause the task | ||
| 15797 | $self->session->pseudoCmd('pausetask ' . $taskName, $self->pseudoCmdMode); | ||
| 15798 | |||
| 15799 | # Update the notebook | ||
| 15800 | $self->updateNotebook(); | ||
| 15801 | } | ||
| 15802 | |||
| 15803 | return 1; | ||
| 15804 | } | ||
| 15805 | |||
| 15806 | sub buttonPauseAll_task { | ||
| 15807 | |||
| 15808 | # Callback: Pauses all tasks (equivalent to ';pausetask -a') | ||
| 15809 | # | ||
| 15810 | # Expected arguments | ||
| 15811 | # (none besides $self) | ||
| 15812 | # | ||
| 15813 | # Return values | ||
| 15814 | # 'undef' on improper arguments | ||
| 15815 | # 1 otherwise | ||
| 15816 | |||
| 15817 | my ($self, $check) = @_; | ||
| 15818 | |||
| 15819 | # Local variables | ||
| 15820 | my ($tab, $slWidget, $ref); | ||
| 15821 | |||
| 15822 | # Check for improper arguments | ||
| 15823 | if (defined $check) { | ||
| 15824 | |||
| 15825 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonPauseAll_task', @_); | ||
| 15826 | } | ||
| 15827 | |||
| 15828 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 15829 | $tab = $self->notebookGetTab(); | ||
| 15830 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 15831 | |||
| 15832 | # Unselect everything in the list | ||
| 15833 | $slWidget->get_selection->unselect_all(); | ||
| 15834 | |||
| 15835 | # Pause all tasks | ||
| 15836 | $self->session->pseudoCmd('pausetask -a', $self->pseudoCmdMode); | ||
| 15837 | |||
| 15838 | # Update the notebook | ||
| 15839 | $self->updateNotebook(); | ||
| 15840 | |||
| 15841 | return 1; | ||
| 15842 | } | ||
| 15843 | |||
| 15844 | sub buttonReset_task { | ||
| 15845 | |||
| 15846 | # Callback: Resets the selected task (equivalent to ';resettask') | ||
| 15847 | # | ||
| 15848 | # Expected arguments | ||
| 15849 | # (none besides $self) | ||
| 15850 | # | ||
| 15851 | # Return values | ||
| 15852 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 15853 | # 1 otherwise | ||
| 15854 | |||
| 15855 | my ($self, $check) = @_; | ||
| 15856 | |||
| 15857 | # Local variables | ||
| 15858 | my ( | ||
| 15859 | $dataRef, $taskName, | ||
| 15860 | @list, @dataList, | ||
| 15861 | ); | ||
| 15862 | |||
| 15863 | # Check for improper arguments | ||
| 15864 | if (defined $check) { | ||
| 15865 | |||
| 15866 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonReset_task', @_); | ||
| 15867 | } | ||
| 15868 | |||
| 15869 | # Import the currently selected portions of the notebook list | ||
| 15870 | @list = $self->notebookGetSelectedData(); | ||
| 15871 | if (! @list) { | ||
| 15872 | |||
| 15873 | # Nothing selected | ||
| 15874 | return undef; | ||
| 15875 | } | ||
| 15876 | |||
| 15877 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 15878 | # a single row of the list | ||
| 15879 | $dataRef = $list[0]; | ||
| 15880 | @dataList = @$dataRef; | ||
| 15881 | # The unique task name is the first item of data | ||
| 15882 | $taskName = $dataList[0]; | ||
| 15883 | if (! $taskName) { | ||
| 15884 | |||
| 15885 | # Can't continue | ||
| 15886 | return undef; | ||
| 15887 | |||
| 15888 | } else { | ||
| 15889 | |||
| 15890 | # Reset the task | ||
| 15891 | $self->session->pseudoCmd('resettask ' . $taskName, $self->pseudoCmdMode); | ||
| 15892 | |||
| 15893 | # Update the notebook | ||
| 15894 | $self->updateNotebook(); | ||
| 15895 | } | ||
| 15896 | |||
| 15897 | return 1; | ||
| 15898 | } | ||
| 15899 | |||
| 15900 | sub buttonResetAll_task { | ||
| 15901 | |||
| 15902 | # Callback: Resets all tasks (equivalent to ';resettask -a') | ||
| 15903 | # | ||
| 15904 | # Expected arguments | ||
| 15905 | # (none besides $self) | ||
| 15906 | # | ||
| 15907 | # Return values | ||
| 15908 | # 'undef' on improper arguments | ||
| 15909 | # 1 otherwise | ||
| 15910 | |||
| 15911 | my ($self, $check) = @_; | ||
| 15912 | |||
| 15913 | # Local variables | ||
| 15914 | my ($tab, $slWidget); | ||
| 15915 | |||
| 15916 | # Check for improper arguments | ||
| 15917 | if (defined $check) { | ||
| 15918 | |||
| 15919 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonResetAll_task', @_); | ||
| 15920 | } | ||
| 15921 | |||
| 15922 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 15923 | $tab = $self->notebookGetTab(); | ||
| 15924 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 15925 | |||
| 15926 | # Unselect everything in the list | ||
| 15927 | $slWidget->get_selection->unselect_all(); | ||
| 15928 | |||
| 15929 | # Halt all tasks | ||
| 15930 | $self->session->pseudoCmd('resettask -a', $self->pseudoCmdMode); | ||
| 15931 | |||
| 15932 | # Update the notebook | ||
| 15933 | $self->updateNotebook(); | ||
| 15934 | |||
| 15935 | return 1; | ||
| 15936 | } | ||
| 15937 | |||
| 15938 | sub buttonFreezeAll_task { | ||
| 15939 | |||
| 15940 | # Callback: Freezes (or unfreezes) all tasks immediately (equivalent to ';freezetask') | ||
| 15941 | # | ||
| 15942 | # Expected arguments | ||
| 15943 | # (none besides $self) | ||
| 15944 | # | ||
| 15945 | # Return values | ||
| 15946 | # 'undef' on improper arguments | ||
| 15947 | # 1 otherwise | ||
| 15948 | |||
| 15949 | my ($self, $check) = @_; | ||
| 15950 | |||
| 15951 | # Local variables | ||
| 15952 | my ($tab, $slWidget); | ||
| 15953 | |||
| 15954 | # Check for improper arguments | ||
| 15955 | if (defined $check) { | ||
| 15956 | |||
| 15957 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonFreezeAll_task', @_); | ||
| 15958 | } | ||
| 15959 | |||
| 15960 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 15961 | $tab = $self->notebookGetTab(); | ||
| 15962 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 15963 | |||
| 15964 | # Unselect everything in the list | ||
| 15965 | $slWidget->get_selection->unselect_all(); | ||
| 15966 | |||
| 15967 | # Freeze/unfreeze all tasks | ||
| 15968 | $self->session->pseudoCmd('freezetask', $self->pseudoCmdMode); | ||
| 15969 | |||
| 15970 | # Update the notebook | ||
| 15971 | $self->updateNotebook(); | ||
| 15972 | |||
| 15973 | return 1; | ||
| 15974 | } | ||
| 15975 | |||
| 15976 | sub buttonDump_task { | ||
| 15977 | |||
| 15978 | # Callback: Displays the list of running tasks in the 'main' window (equivalent to | ||
| 15979 | # ';listtask') | ||
| 15980 | # | ||
| 15981 | # Expected arguments | ||
| 15982 | # (none besides $self) | ||
| 15983 | # | ||
| 15984 | # Return values | ||
| 15985 | # 'undef' on improper arguments | ||
| 15986 | # 1 otherwise | ||
| 15987 | |||
| 15988 | my ($self, $check) = @_; | ||
| 15989 | |||
| 15990 | # Local variables | ||
| 15991 | my ($tab, $slWidget); | ||
| 15992 | |||
| 15993 | # Check for improper arguments | ||
| 15994 | if (defined $check) { | ||
| 15995 | |||
| 15996 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_task', @_); | ||
| 15997 | } | ||
| 15998 | |||
| 15999 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16000 | $tab = $self->notebookGetTab(); | ||
| 16001 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16002 | |||
| 16003 | # Unselect everything in the list | ||
| 16004 | $slWidget->get_selection->unselect_all(); | ||
| 16005 | |||
| 16006 | # Display list of tasks | ||
| 16007 | $self->session->pseudoCmd('listtask', $self->pseudoCmdMode); | ||
| 16008 | |||
| 16009 | # Update the notebook | ||
| 16010 | $self->updateNotebook(); | ||
| 16011 | |||
| 16012 | return 1; | ||
| 16013 | } | ||
| 16014 | |||
| 16015 | # Tasklist button callbacks - Global initial tasklist | ||
| 16016 | |||
| 16017 | sub buttonEdit_initialTask { | ||
| 16018 | |||
| 16019 | # Callback: Edit a task from the global initial tasklist (equivalent to ';editinitialtask') | ||
| 16020 | # | ||
| 16021 | # Expected arguments | ||
| 16022 | # (none besides $self) | ||
| 16023 | # | ||
| 16024 | # Return values | ||
| 16025 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 16026 | # object no longer exists | ||
| 16027 | # 1 otherwise | ||
| 16028 | |||
| 16029 | my ($self, $check) = @_; | ||
| 16030 | |||
| 16031 | # Local variables | ||
| 16032 | my ( | ||
| 16033 | $dataRef, $taskName, $taskObj, | ||
| 16034 | @list, @dataList, | ||
| 16035 | ); | ||
| 16036 | |||
| 16037 | # Check for improper arguments | ||
| 16038 | if (defined $check) { | ||
| 16039 | |||
| 16040 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_initialTask', @_); | ||
| 16041 | } | ||
| 16042 | |||
| 16043 | # Import the currently selected portions of the notebook list | ||
| 16044 | @list = $self->notebookGetSelectedData(); | ||
| 16045 | if (! @list) { | ||
| 16046 | |||
| 16047 | # Nothing selected | ||
| 16048 | return undef; | ||
| 16049 | } | ||
| 16050 | |||
| 16051 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16052 | # a single row of the list | ||
| 16053 | $dataRef = $list[0]; | ||
| 16054 | @dataList = @$dataRef; | ||
| 16055 | # The initial task name is the first item of data | ||
| 16056 | $taskName = $dataList[0]; | ||
| 16057 | if (! $taskName) { | ||
| 16058 | |||
| 16059 | # Can't continue | ||
| 16060 | return undef; | ||
| 16061 | } | ||
| 16062 | |||
| 16063 | # Get the task reference itself | ||
| 16064 | $taskObj = $axmud::CLIENT->ivShow('initTaskHash', $taskName); | ||
| 16065 | if (! $taskObj) { | ||
| 16066 | |||
| 16067 | # Can't continue | ||
| 16068 | return undef; | ||
| 16069 | |||
| 16070 | } else { | ||
| 16071 | |||
| 16072 | # Open up an 'edit' window to edit the object | ||
| 16073 | $self->createFreeWin( | ||
| 16074 | 'Games::Axmud::EditWin::Task', | ||
| 16075 | $self, | ||
| 16076 | $self->session, | ||
| 16077 | 'Edit ' . $taskObj->prettyName . ' task', | ||
| 16078 | $taskObj, | ||
| 16079 | FALSE, # Not temporary | ||
| 16080 | # Config | ||
| 16081 | 'edit_flag' => TRUE, # Some IVs for initial tasks are editable | ||
| 16082 | ); | ||
| 16083 | |||
| 16084 | return 1; | ||
| 16085 | } | ||
| 16086 | } | ||
| 16087 | |||
| 16088 | sub buttonMoveUp_initialTask { | ||
| 16089 | |||
| 16090 | # Callback: Moves a global initial task up in the ordered list (no equivalent client | ||
| 16091 | # command) | ||
| 16092 | # | ||
| 16093 | # Expected arguments | ||
| 16094 | # (none besides $self) | ||
| 16095 | # | ||
| 16096 | # Return values | ||
| 16097 | # 'undef' on improper arguments or if no line is selected | ||
| 16098 | # 1 otherwise | ||
| 16099 | |||
| 16100 | my ($self, $check) = @_; | ||
| 16101 | |||
| 16102 | # Local variables | ||
| 16103 | my ( | ||
| 16104 | $index, $taskName, | ||
| 16105 | @taskList, | ||
| 16106 | ); | ||
| 16107 | |||
| 16108 | # Check for improper arguments | ||
| 16109 | if (defined $check) { | ||
| 16110 | |||
| 16111 | return $axmud::CLIENT->writeImproper( | ||
| 16112 | $self->_objClass . '->buttonMoveUp_initialTask', | ||
| 16113 | @_, | ||
| 16114 | ); | ||
| 16115 | } | ||
| 16116 | |||
| 16117 | # Import the ordered list of global initial tasks | ||
| 16118 | @taskList = $axmud::CLIENT->initTaskOrderList; | ||
| 16119 | |||
| 16120 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 16121 | # contains | ||
| 16122 | ($index, $taskName) = $self->initialTaskData(); | ||
| 16123 | if (! defined $index) { | ||
| 16124 | |||
| 16125 | return undef; | ||
| 16126 | } | ||
| 16127 | |||
| 16128 | # $index must be at least 2nd in the list (element 1), else it can't be moved up | ||
| 16129 | if ($index) { | ||
| 16130 | |||
| 16131 | # Move the item up the ordered list | ||
| 16132 | splice(@taskList, $index, 1); | ||
| 16133 | splice(@taskList, ($index - 1), 0, $taskName); | ||
| 16134 | |||
| 16135 | # Update the client IV | ||
| 16136 | $axmud::CLIENT->set_initTaskOrderList(@taskList); | ||
| 16137 | # Update the notebook (the single argument makes sure the same item is selected) | ||
| 16138 | $self->updateNotebook($index - 1); | ||
| 16139 | } | ||
| 16140 | |||
| 16141 | return 1; | ||
| 16142 | } | ||
| 16143 | |||
| 16144 | sub buttonMoveDown_initialTask { | ||
| 16145 | |||
| 16146 | # Callback: Moves a global initial task down in the ordered list (no equivalent client | ||
| 16147 | # command) | ||
| 16148 | # | ||
| 16149 | # Expected arguments | ||
| 16150 | # (none besides $self) | ||
| 16151 | # | ||
| 16152 | # Return values | ||
| 16153 | # 'undef' on improper arguments, if no line is selected or if the selected item can't be | ||
| 16154 | # moved down | ||
| 16155 | # 1 otherwise | ||
| 16156 | |||
| 16157 | my ($self, $check) = @_; | ||
| 16158 | |||
| 16159 | # Local variables | ||
| 16160 | my ( | ||
| 16161 | $index, $taskName, | ||
| 16162 | @taskList, | ||
| 16163 | ); | ||
| 16164 | |||
| 16165 | # Check for improper arguments | ||
| 16166 | if (defined $check) { | ||
| 16167 | |||
| 16168 | return $axmud::CLIENT->writeImproper( | ||
| 16169 | $self->_objClass . '->buttonMoveDown_initialTask', | ||
| 16170 | @_, | ||
| 16171 | ); | ||
| 16172 | } | ||
| 16173 | |||
| 16174 | # Import the ordered list of global initial tasks | ||
| 16175 | @taskList = $axmud::CLIENT->initTaskOrderList; | ||
| 16176 | |||
| 16177 | # Import the GA::Obj::SimpleList and find the currently selected line and the data it | ||
| 16178 | # contains | ||
| 16179 | ($index, $taskName) = $self->initialTaskData(); | ||
| 16180 | if (! defined $index) { | ||
| 16181 | |||
| 16182 | return undef; | ||
| 16183 | } | ||
| 16184 | |||
| 16185 | # $index must not be last in the list, else it can't be moved down | ||
| 16186 | if ($taskList[-1] ne $taskName) { | ||
| 16187 | |||
| 16188 | # Move the item down the ordered list | ||
| 16189 | splice(@taskList, $index, 1); | ||
| 16190 | splice(@taskList, ($index + 1), 0, $taskName); | ||
| 16191 | |||
| 16192 | # Update the client IV | ||
| 16193 | $axmud::CLIENT->set_initTaskOrderList(@taskList); | ||
| 16194 | # Update the notebook (the single argument makes sure the same item is selected) | ||
| 16195 | $self->updateNotebook($index + 1); | ||
| 16196 | } | ||
| 16197 | |||
| 16198 | return 1; | ||
| 16199 | } | ||
| 16200 | |||
| 16201 | sub buttonDelete_initialTask { | ||
| 16202 | |||
| 16203 | # Callback: Delete a task from the global initial tasklist (equivalent to | ||
| 16204 | # ';deleteinitialtask') | ||
| 16205 | # | ||
| 16206 | # Expected arguments | ||
| 16207 | # (none besides $self) | ||
| 16208 | # | ||
| 16209 | # Return values | ||
| 16210 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 16211 | # 1 otherwise | ||
| 16212 | |||
| 16213 | my ($self, $check) = @_; | ||
| 16214 | |||
| 16215 | # Local variables | ||
| 16216 | my ( | ||
| 16217 | $dataRef, $taskName, | ||
| 16218 | @list, @dataList, | ||
| 16219 | ); | ||
| 16220 | |||
| 16221 | # Check for improper arguments | ||
| 16222 | if (defined $check) { | ||
| 16223 | |||
| 16224 | return $axmud::CLIENT->writeImproper( | ||
| 16225 | $self->_objClass . '->buttonDelete_initialTask', | ||
| 16226 | @_, | ||
| 16227 | ); | ||
| 16228 | } | ||
| 16229 | |||
| 16230 | # Import the currently selected portions of the notebook list | ||
| 16231 | @list = $self->notebookGetSelectedData(); | ||
| 16232 | if (! @list) { | ||
| 16233 | |||
| 16234 | # Nothing selected | ||
| 16235 | return undef; | ||
| 16236 | } | ||
| 16237 | |||
| 16238 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16239 | # a single row of the list | ||
| 16240 | $dataRef = $list[0]; | ||
| 16241 | @dataList = @$dataRef; | ||
| 16242 | # The initial task name is the first item of data | ||
| 16243 | $taskName = $dataList[0]; | ||
| 16244 | if (! $taskName) { | ||
| 16245 | |||
| 16246 | # Can't continue | ||
| 16247 | return undef; | ||
| 16248 | |||
| 16249 | } else { | ||
| 16250 | |||
| 16251 | # Delete the initial task | ||
| 16252 | $self->session->pseudoCmd('deleteinitialtask ' . $taskName, $self->pseudoCmdMode); | ||
| 16253 | |||
| 16254 | # Update the notebook | ||
| 16255 | $self->updateNotebook(); | ||
| 16256 | |||
| 16257 | return 1; | ||
| 16258 | } | ||
| 16259 | } | ||
| 16260 | |||
| 16261 | sub buttonDeleteAll_initialTask { | ||
| 16262 | |||
| 16263 | # Callback: Delete all tasks from the global initial tasklist (equivalent to | ||
| 16264 | # ';deleteinitialtask -a') | ||
| 16265 | # | ||
| 16266 | # Expected arguments | ||
| 16267 | # (none besides $self) | ||
| 16268 | # | ||
| 16269 | # Return values | ||
| 16270 | # 'undef' on improper arguments | ||
| 16271 | # 1 otherwise | ||
| 16272 | |||
| 16273 | my ($self, $check) = @_; | ||
| 16274 | |||
| 16275 | # Local variables | ||
| 16276 | my ($response, $tab, $slWidget); | ||
| 16277 | |||
| 16278 | # Check for improper arguments | ||
| 16279 | if (defined $check) { | ||
| 16280 | |||
| 16281 | return $axmud::CLIENT->writeImproper( | ||
| 16282 | $self->_objClass . '->buttonDeleteAll_initialTask', | ||
| 16283 | @_, | ||
| 16284 | ); | ||
| 16285 | } | ||
| 16286 | |||
| 16287 | # Check there are some items to delete | ||
| 16288 | if (! $axmud::CLIENT->initTaskHash) { | ||
| 16289 | |||
| 16290 | # Nothing selected | ||
| 16291 | return 1; | ||
| 16292 | } | ||
| 16293 | |||
| 16294 | # Get confirmation | ||
| 16295 | $response = $self->showMsgDialogue( | ||
| 16296 | 'Delete all', | ||
| 16297 | 'question', | ||
| 16298 | 'Are you sure you want to delete all global initial tasks?', | ||
| 16299 | 'yes-no', | ||
| 16300 | 'yes', | ||
| 16301 | ); | ||
| 16302 | |||
| 16303 | if (! $response || $response ne 'yes') { | ||
| 16304 | |||
| 16305 | # Cancelled | ||
| 16306 | return 1; | ||
| 16307 | } | ||
| 16308 | |||
| 16309 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16310 | $tab = $self->notebookGetTab(); | ||
| 16311 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16312 | |||
| 16313 | # Unselect everything in the list | ||
| 16314 | $slWidget->get_selection->unselect_all(); | ||
| 16315 | |||
| 16316 | # Delete all initial tasks | ||
| 16317 | $self->session->pseudoCmd('deleteinitialtask -a', $self->pseudoCmdMode); | ||
| 16318 | |||
| 16319 | # Update the notebook | ||
| 16320 | $self->updateNotebook(); | ||
| 16321 | |||
| 16322 | return 1; | ||
| 16323 | } | ||
| 16324 | |||
| 16325 | sub buttonDump_initialTask { | ||
| 16326 | |||
| 16327 | # Callback: Display list of initial tasks to the 'main' window (equivalent to | ||
| 16328 | # ';listinitialtask') | ||
| 16329 | # | ||
| 16330 | # Expected arguments | ||
| 16331 | # (none besides $self) | ||
| 16332 | # | ||
| 16333 | # Return values | ||
| 16334 | # 'undef' on improper arguments | ||
| 16335 | # 1 otherwise | ||
| 16336 | |||
| 16337 | my ($self, $check) = @_; | ||
| 16338 | |||
| 16339 | # Local variables | ||
| 16340 | my ($tab, $slWidget); | ||
| 16341 | |||
| 16342 | # Check for improper arguments | ||
| 16343 | if (defined $check) { | ||
| 16344 | |||
| 16345 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_initialTask', @_); | ||
| 16346 | } | ||
| 16347 | |||
| 16348 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16349 | $tab = $self->notebookGetTab(); | ||
| 16350 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16351 | |||
| 16352 | # Unselect everything in the list | ||
| 16353 | $slWidget->get_selection->unselect_all(); | ||
| 16354 | |||
| 16355 | # Display initial tasks | ||
| 16356 | $self->session->pseudoCmd('listinitialtask', $self->pseudoCmdMode); | ||
| 16357 | |||
| 16358 | # Update the notebook | ||
| 16359 | $self->updateNotebook(); | ||
| 16360 | |||
| 16361 | return 1; | ||
| 16362 | } | ||
| 16363 | |||
| 16364 | # Tasklist button callbacks - Custom tasklist | ||
| 16365 | |||
| 16366 | sub buttonStart_customTask { | ||
| 16367 | |||
| 16368 | # Callback: Starts a task from the custom tasklist (equivalent to ';startcustomtask') | ||
| 16369 | # | ||
| 16370 | # Expected arguments | ||
| 16371 | # (none besides $self) | ||
| 16372 | # | ||
| 16373 | # Return values | ||
| 16374 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 16375 | # 1 otherwise | ||
| 16376 | |||
| 16377 | my ($self, $check) = @_; | ||
| 16378 | |||
| 16379 | # Local variables | ||
| 16380 | my ( | ||
| 16381 | $dataRef, $taskName, | ||
| 16382 | @list, @dataList, | ||
| 16383 | ); | ||
| 16384 | |||
| 16385 | # Check for improper arguments | ||
| 16386 | if (defined $check) { | ||
| 16387 | |||
| 16388 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonStart_customTask', @_); | ||
| 16389 | } | ||
| 16390 | |||
| 16391 | # Import the currently selected portions of the notebook list | ||
| 16392 | @list = $self->notebookGetSelectedData(); | ||
| 16393 | if (! @list) { | ||
| 16394 | |||
| 16395 | # Nothing selected | ||
| 16396 | return undef; | ||
| 16397 | } | ||
| 16398 | |||
| 16399 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16400 | # a single row of the list | ||
| 16401 | $dataRef = $list[0]; | ||
| 16402 | @dataList = @$dataRef; | ||
| 16403 | # The custom task's name is the first item of data | ||
| 16404 | $taskName = $dataList[0]; | ||
| 16405 | if (! $taskName) { | ||
| 16406 | |||
| 16407 | # Can't continue | ||
| 16408 | return undef; | ||
| 16409 | |||
| 16410 | } else { | ||
| 16411 | |||
| 16412 | # Start the task | ||
| 16413 | $self->session->pseudoCmd('startcustomtask ' . $taskName, $self->pseudoCmdMode); | ||
| 16414 | |||
| 16415 | # Update the notebook | ||
| 16416 | $self->updateNotebook(); | ||
| 16417 | |||
| 16418 | return 1; | ||
| 16419 | } | ||
| 16420 | } | ||
| 16421 | |||
| 16422 | sub buttonEdit_customTask { | ||
| 16423 | |||
| 16424 | # Callback: Edit a task from the custom tasklist (equivalent to ';editcustomtask') | ||
| 16425 | # | ||
| 16426 | # Expected arguments | ||
| 16427 | # (none besides $self) | ||
| 16428 | # | ||
| 16429 | # Return values | ||
| 16430 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 16431 | # object no longer exists | ||
| 16432 | # 1 otherwise | ||
| 16433 | |||
| 16434 | my ($self, $check) = @_; | ||
| 16435 | |||
| 16436 | # Local variables | ||
| 16437 | my ( | ||
| 16438 | $dataRef, $taskName, $taskObj, | ||
| 16439 | @list, @dataList, | ||
| 16440 | ); | ||
| 16441 | |||
| 16442 | # Check for improper arguments | ||
| 16443 | if (defined $check) { | ||
| 16444 | |||
| 16445 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_customTask', @_); | ||
| 16446 | } | ||
| 16447 | |||
| 16448 | # Import the currently selected portions of the notebook list | ||
| 16449 | @list = $self->notebookGetSelectedData(); | ||
| 16450 | if (! @list) { | ||
| 16451 | |||
| 16452 | # Nothing selected | ||
| 16453 | return undef; | ||
| 16454 | } | ||
| 16455 | |||
| 16456 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16457 | # a single row of the list | ||
| 16458 | $dataRef = $list[0]; | ||
| 16459 | @dataList = @$dataRef; | ||
| 16460 | # The custom task's name is the first item of data | ||
| 16461 | $taskName = $dataList[0]; | ||
| 16462 | if (! $taskName) { | ||
| 16463 | |||
| 16464 | # Can't continue | ||
| 16465 | return undef; | ||
| 16466 | } | ||
| 16467 | |||
| 16468 | # Get the task object itself | ||
| 16469 | $taskObj = $axmud::CLIENT->ivShow('customTaskHash', $taskName); | ||
| 16470 | if (! $taskObj) { | ||
| 16471 | |||
| 16472 | # Can't continue | ||
| 16473 | return undef; | ||
| 16474 | |||
| 16475 | } else { | ||
| 16476 | |||
| 16477 | # Open up an 'edit' window to edit the object | ||
| 16478 | $self->createFreeWin( | ||
| 16479 | 'Games::Axmud::EditWin::Task', | ||
| 16480 | $self, | ||
| 16481 | $self->session, | ||
| 16482 | 'Edit ' . $taskObj->prettyName . ' task', | ||
| 16483 | $taskObj, | ||
| 16484 | FALSE, # Not temporary | ||
| 16485 | # Config | ||
| 16486 | 'edit_flag' => TRUE, # Some IVs for custom tasks are editable | ||
| 16487 | ); | ||
| 16488 | |||
| 16489 | return 1; | ||
| 16490 | } | ||
| 16491 | } | ||
| 16492 | |||
| 16493 | sub buttonDelete_customTask { | ||
| 16494 | |||
| 16495 | # Callback: Delete a task from the custom tasklist (equivalent to ';deletecustomtask') | ||
| 16496 | # | ||
| 16497 | # Expected arguments | ||
| 16498 | # (none besides $self) | ||
| 16499 | # | ||
| 16500 | # Return values | ||
| 16501 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 16502 | # 1 otherwise | ||
| 16503 | |||
| 16504 | my ($self, $check) = @_; | ||
| 16505 | |||
| 16506 | # Local variables | ||
| 16507 | my ( | ||
| 16508 | $dataRef, $taskName, | ||
| 16509 | @list, @dataList, | ||
| 16510 | ); | ||
| 16511 | |||
| 16512 | # Check for improper arguments | ||
| 16513 | if (defined $check) { | ||
| 16514 | |||
| 16515 | return $axmud::CLIENT->writeImproper( | ||
| 16516 | $self->_objClass . '->buttonDelete_customTask', | ||
| 16517 | @_, | ||
| 16518 | ); | ||
| 16519 | } | ||
| 16520 | |||
| 16521 | # Import the currently selected portions of the notebook list | ||
| 16522 | @list = $self->notebookGetSelectedData(); | ||
| 16523 | if (! @list) { | ||
| 16524 | |||
| 16525 | # Nothing selected | ||
| 16526 | return undef; | ||
| 16527 | } | ||
| 16528 | |||
| 16529 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16530 | # a single row of the list | ||
| 16531 | $dataRef = $list[0]; | ||
| 16532 | @dataList = @$dataRef; | ||
| 16533 | # The custom task's name is the first item of data | ||
| 16534 | $taskName = $dataList[0]; | ||
| 16535 | if (! $taskName) { | ||
| 16536 | |||
| 16537 | # Can't continue | ||
| 16538 | return undef; | ||
| 16539 | |||
| 16540 | } else { | ||
| 16541 | |||
| 16542 | # Delete the task | ||
| 16543 | $self->session->pseudoCmd('deletecustomtask ' . $taskName, $self->pseudoCmdMode); | ||
| 16544 | |||
| 16545 | # Update the notebook | ||
| 16546 | $self->updateNotebook(); | ||
| 16547 | |||
| 16548 | return 1; | ||
| 16549 | } | ||
| 16550 | } | ||
| 16551 | |||
| 16552 | sub buttonDeleteAll_customTask { | ||
| 16553 | |||
| 16554 | # Callback: Delete all tasks from the custom tasklist (equivalent to ';deletecustomtask -a') | ||
| 16555 | # | ||
| 16556 | # Expected arguments | ||
| 16557 | # (none besides $self) | ||
| 16558 | # | ||
| 16559 | # Return values | ||
| 16560 | # 'undef' on improper arguments | ||
| 16561 | # 1 otherwise | ||
| 16562 | |||
| 16563 | my ($self, $check) = @_; | ||
| 16564 | |||
| 16565 | # Local variables | ||
| 16566 | my ($tab, $slWidget, $response); | ||
| 16567 | |||
| 16568 | # Check for improper arguments | ||
| 16569 | if (defined $check) { | ||
| 16570 | |||
| 16571 | return $axmud::CLIENT->writeImproper( | ||
| 16572 | $self->_objClass . '->buttonDeleteAll_customTask', | ||
| 16573 | @_, | ||
| 16574 | ); | ||
| 16575 | } | ||
| 16576 | |||
| 16577 | |||
| 16578 | # Check there are some items to delete | ||
| 16579 | if (! $axmud::CLIENT->customTaskHash) { | ||
| 16580 | |||
| 16581 | # Nothing selected | ||
| 16582 | return 1; | ||
| 16583 | } | ||
| 16584 | |||
| 16585 | # Get confirmation | ||
| 16586 | $response = $self->showMsgDialogue( | ||
| 16587 | 'Delete all', | ||
| 16588 | 'question', | ||
| 16589 | 'Are you sure you want to delete all custom tasks?', | ||
| 16590 | 'yes-no', | ||
| 16591 | 'yes', | ||
| 16592 | ); | ||
| 16593 | |||
| 16594 | if (! $response || $response ne 'yes') { | ||
| 16595 | |||
| 16596 | # Cancelled | ||
| 16597 | return 1; | ||
| 16598 | } | ||
| 16599 | |||
| 16600 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16601 | $tab = $self->notebookGetTab(); | ||
| 16602 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16603 | |||
| 16604 | # Unselect everything in the list | ||
| 16605 | $slWidget->get_selection->unselect_all(); | ||
| 16606 | |||
| 16607 | # Delete all custom tasks | ||
| 16608 | $self->session->pseudoCmd('deletecustomtask -a', $self->pseudoCmdMode); | ||
| 16609 | |||
| 16610 | # Update the notebook | ||
| 16611 | $self->updateNotebook(); | ||
| 16612 | |||
| 16613 | return 1; | ||
| 16614 | } | ||
| 16615 | |||
| 16616 | sub buttonDump_customTask { | ||
| 16617 | |||
| 16618 | # Callback: Display list of custom tasks in the 'main' window (equivalent to | ||
| 16619 | # ';listcustomtask') | ||
| 16620 | # | ||
| 16621 | # Expected arguments | ||
| 16622 | # (none besides $self) | ||
| 16623 | # | ||
| 16624 | # Return values | ||
| 16625 | # 'undef' on improper arguments | ||
| 16626 | # 1 otherwise | ||
| 16627 | |||
| 16628 | my ($self, $check) = @_; | ||
| 16629 | |||
| 16630 | # Local variables | ||
| 16631 | my ($tab, $slWidget, $ref); | ||
| 16632 | |||
| 16633 | # Check for improper arguments | ||
| 16634 | if (defined $check) { | ||
| 16635 | |||
| 16636 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_customTask', @_); | ||
| 16637 | } | ||
| 16638 | |||
| 16639 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16640 | $tab = $self->notebookGetTab(); | ||
| 16641 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16642 | |||
| 16643 | # Unselect everything in the list | ||
| 16644 | $slWidget->get_selection->unselect_all(); | ||
| 16645 | |||
| 16646 | # Dump custom tasks | ||
| 16647 | $self->session->pseudoCmd('listcustomtask', $self->pseudoCmdMode); | ||
| 16648 | |||
| 16649 | # Update the notebook | ||
| 16650 | $self->updateNotebook(); | ||
| 16651 | |||
| 16652 | return 1; | ||
| 16653 | } | ||
| 16654 | |||
| 16655 | # Tasklist button callbacks - Task packages | ||
| 16656 | |||
| 16657 | sub buttonAdd_taskPackage { | ||
| 16658 | |||
| 16659 | # Callback: Add a task package name (equivalent to ';addtaskpackage') | ||
| 16660 | # | ||
| 16661 | # Expected arguments | ||
| 16662 | # (none besides $self) | ||
| 16663 | # | ||
| 16664 | # Return values | ||
| 16665 | # 'undef' on improper arguments | ||
| 16666 | # 1 otherwise | ||
| 16667 | |||
| 16668 | my ($self, $check) = @_; | ||
| 16669 | |||
| 16670 | # Local variables | ||
| 16671 | my ($tab, $slWidget, $standard, $package); | ||
| 16672 | |||
| 16673 | # Check for improper arguments | ||
| 16674 | if (defined $check) { | ||
| 16675 | |||
| 16676 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_taskPackage', @_); | ||
| 16677 | } | ||
| 16678 | |||
| 16679 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16680 | $tab = $self->notebookGetTab(); | ||
| 16681 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16682 | |||
| 16683 | # Unselect everything in the list, because we're starting a new task package name | ||
| 16684 | $slWidget->get_selection->unselect_all(); | ||
| 16685 | |||
| 16686 | ($standard, $package) = $self->showDoubleEntryDialogue( | ||
| 16687 | 'Add task package name', | ||
| 16688 | 'Standard task name', | ||
| 16689 | 'Task package name', | ||
| 16690 | ); | ||
| 16691 | |||
| 16692 | if (defined $standard && defined $package) { | ||
| 16693 | |||
| 16694 | $self->session->pseudoCmd( | ||
| 16695 | 'addtaskpackage ' . $standard . ' ' . $package, | ||
| 16696 | $self->pseudoCmdMode, | ||
| 16697 | ); | ||
| 16698 | |||
| 16699 | # Update the notebook | ||
| 16700 | $self->updateNotebook(); | ||
| 16701 | }; | ||
| 16702 | |||
| 16703 | return 1; | ||
| 16704 | } | ||
| 16705 | |||
| 16706 | sub buttonEdit_taskPackage { | ||
| 16707 | |||
| 16708 | # Callback: Edits a task package name (no client command equivalent) | ||
| 16709 | # | ||
| 16710 | # Expected arguments | ||
| 16711 | # (none besides $self) | ||
| 16712 | # | ||
| 16713 | # Return values | ||
| 16714 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 16715 | # item no longer exists | ||
| 16716 | # 1 otherwise | ||
| 16717 | |||
| 16718 | my ($self, $check) = @_; | ||
| 16719 | |||
| 16720 | # Local variables | ||
| 16721 | my ( | ||
| 16722 | $dataRef, $standard, $package, | ||
| 16723 | @list, @dataList, | ||
| 16724 | ); | ||
| 16725 | |||
| 16726 | # Check for improper arguments | ||
| 16727 | if (defined $check) { | ||
| 16728 | |||
| 16729 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_taskPackage', @_); | ||
| 16730 | } | ||
| 16731 | |||
| 16732 | # Import the currently selected portions of the notebook list | ||
| 16733 | @list = $self->notebookGetSelectedData(); | ||
| 16734 | if (! @list) { | ||
| 16735 | |||
| 16736 | # Nothing selected | ||
| 16737 | return undef; | ||
| 16738 | } | ||
| 16739 | |||
| 16740 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16741 | # a single row of the list | ||
| 16742 | $dataRef = $list[0]; | ||
| 16743 | @dataList = @$dataRef; | ||
| 16744 | # The standard task name is the second item of data | ||
| 16745 | $standard = $dataList[1]; | ||
| 16746 | if (! $standard) { | ||
| 16747 | |||
| 16748 | # Can't continue | ||
| 16749 | return undef; | ||
| 16750 | } | ||
| 16751 | |||
| 16752 | # Prompt for a new package name | ||
| 16753 | $package = $self->showEntryDialogue( | ||
| 16754 | 'Edit task package name', | ||
| 16755 | 'Enter a task package name for \'' . $standard . '\'', | ||
| 16756 | ); | ||
| 16757 | |||
| 16758 | if (defined $package) { | ||
| 16759 | |||
| 16760 | $self->session->pseudoCmd( | ||
| 16761 | 'addtaskpackage ' . $standard . ' ' . $package, | ||
| 16762 | $self->pseudoCmdMode, | ||
| 16763 | ); | ||
| 16764 | |||
| 16765 | # Update the notebook | ||
| 16766 | $self->updateNotebook(); | ||
| 16767 | }; | ||
| 16768 | |||
| 16769 | return 1; | ||
| 16770 | } | ||
| 16771 | |||
| 16772 | sub buttonDelete_taskPackage { | ||
| 16773 | |||
| 16774 | # Callback: Deletes a task package name (equivalent to ';deletetaskpackage') | ||
| 16775 | # | ||
| 16776 | # Expected arguments | ||
| 16777 | # (none besides $self) | ||
| 16778 | # | ||
| 16779 | # Return values | ||
| 16780 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 16781 | # item no longer exists | ||
| 16782 | # 1 otherwise | ||
| 16783 | |||
| 16784 | my ($self, $check) = @_; | ||
| 16785 | |||
| 16786 | # Local variables | ||
| 16787 | my ( | ||
| 16788 | $dataRef, $standard, | ||
| 16789 | @list, @dataList, | ||
| 16790 | ); | ||
| 16791 | |||
| 16792 | # Check for improper arguments | ||
| 16793 | if (defined $check) { | ||
| 16794 | |||
| 16795 | return $axmud::CLIENT->writeImproper( | ||
| 16796 | $self->_objClass . '->buttonDelete_taskPackage', | ||
| 16797 | @_, | ||
| 16798 | ); | ||
| 16799 | } | ||
| 16800 | |||
| 16801 | # Import the currently selected portions of the notebook list | ||
| 16802 | @list = $self->notebookGetSelectedData(); | ||
| 16803 | if (! @list) { | ||
| 16804 | |||
| 16805 | # Nothing selected | ||
| 16806 | return undef; | ||
| 16807 | } | ||
| 16808 | |||
| 16809 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16810 | # a single row of the list | ||
| 16811 | $dataRef = $list[0]; | ||
| 16812 | @dataList = @$dataRef; | ||
| 16813 | # The standard task name is the second item of data | ||
| 16814 | $standard = $dataList[1]; | ||
| 16815 | if (! $standard) { | ||
| 16816 | |||
| 16817 | # Can't continue | ||
| 16818 | return undef; | ||
| 16819 | |||
| 16820 | } else { | ||
| 16821 | |||
| 16822 | # Delete the task package | ||
| 16823 | $self->session->pseudoCmd('deletetaskpackage ' . $standard, $self->pseudoCmdMode); | ||
| 16824 | |||
| 16825 | # Update the notebook | ||
| 16826 | $self->updateNotebook(); | ||
| 16827 | }; | ||
| 16828 | |||
| 16829 | return 1; | ||
| 16830 | } | ||
| 16831 | |||
| 16832 | sub buttonReset_taskPackage { | ||
| 16833 | |||
| 16834 | # Callback: Reset a task package name to its default (equivalent to | ||
| 16835 | # ';resettaskpackage <name>') | ||
| 16836 | # | ||
| 16837 | # Expected arguments | ||
| 16838 | # (none besides $self) | ||
| 16839 | # | ||
| 16840 | # Return values | ||
| 16841 | # 'undef' on improper arguments, if no line is selected in the notebook or if the user | ||
| 16842 | # declines to continue the operation | ||
| 16843 | # 1 otherwise | ||
| 16844 | |||
| 16845 | my ($self, $check) = @_; | ||
| 16846 | |||
| 16847 | # Local variables | ||
| 16848 | my ( | ||
| 16849 | $dataRef, $standard, $result, | ||
| 16850 | @list, @dataList, | ||
| 16851 | ); | ||
| 16852 | |||
| 16853 | # Check for improper arguments | ||
| 16854 | if (defined $check) { | ||
| 16855 | |||
| 16856 | return $axmud::CLIENT->writeImproper( | ||
| 16857 | $self->_objClass . '->buttonReset_taskPackage', | ||
| 16858 | @_, | ||
| 16859 | ); | ||
| 16860 | } | ||
| 16861 | |||
| 16862 | # Import the currently selected portions of the notebook list | ||
| 16863 | @list = $self->notebookGetSelectedData(); | ||
| 16864 | if (! @list) { | ||
| 16865 | |||
| 16866 | # Nothing selected | ||
| 16867 | return undef; | ||
| 16868 | } | ||
| 16869 | |||
| 16870 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 16871 | # a single row of the list | ||
| 16872 | $dataRef = $list[0]; | ||
| 16873 | @dataList = @$dataRef; | ||
| 16874 | # The standard task name is the second item of data | ||
| 16875 | $standard = $dataList[1]; | ||
| 16876 | if (! $standard) { | ||
| 16877 | |||
| 16878 | # Can't continue | ||
| 16879 | return undef; | ||
| 16880 | } | ||
| 16881 | |||
| 16882 | # If it's not one of the built-in tasks, we need to show a warning message | ||
| 16883 | if (! $axmud::CLIENT->ivExists('constTaskPackageHash', $standard)) { | ||
| 16884 | |||
| 16885 | $result = $self->showMsgDialogue( | ||
| 16886 | 'Reset task package name', | ||
| 16887 | 'warning', | ||
| 16888 | 'The task \'' . $standard . '\' isn\'t a built-in task, so resetting its package' | ||
| 16889 | . ' name will cause it to disappear from this list. You won\'t be able to run the' | ||
| 16890 | . ' task until you enter a new package name for it. Continue?', | ||
| 16891 | 'yes-no', | ||
| 16892 | ); | ||
| 16893 | |||
| 16894 | if ($result ne 'yes') { | ||
| 16895 | |||
| 16896 | return undef; | ||
| 16897 | } | ||
| 16898 | } | ||
| 16899 | |||
| 16900 | # Reset the task package | ||
| 16901 | $self->session->pseudoCmd('resettaskpackage ' . $standard, $self->pseudoCmdMode); | ||
| 16902 | |||
| 16903 | # Update the notebook | ||
| 16904 | $self->updateNotebook(); | ||
| 16905 | |||
| 16906 | return 1; | ||
| 16907 | } | ||
| 16908 | |||
| 16909 | sub buttonResetAll_taskPackage { | ||
| 16910 | |||
| 16911 | # Callback: Resets all task package names to default (equivalent to | ||
| 16912 | # ';resettaskpackage') | ||
| 16913 | # | ||
| 16914 | # Expected arguments | ||
| 16915 | # (none besides $self) | ||
| 16916 | # | ||
| 16917 | # Return values | ||
| 16918 | # 'undef' on improper arguments or if the user declines to continue the operation | ||
| 16919 | # 1 otherwise | ||
| 16920 | |||
| 16921 | my ($self, $check) = @_; | ||
| 16922 | |||
| 16923 | # Local variables | ||
| 16924 | my ($tab, $slWidget, $result, $count, $text); | ||
| 16925 | |||
| 16926 | # Check for improper arguments | ||
| 16927 | if (defined $check) { | ||
| 16928 | |||
| 16929 | return $axmud::CLIENT->writeImproper( | ||
| 16930 | $self->_objClass . '->buttonResetAll_taskPackage', | ||
| 16931 | @_, | ||
| 16932 | ); | ||
| 16933 | } | ||
| 16934 | |||
| 16935 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 16936 | $tab = $self->notebookGetTab(); | ||
| 16937 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 16938 | |||
| 16939 | # Unselect everything in the list | ||
| 16940 | $slWidget->get_selection->unselect_all(); | ||
| 16941 | |||
| 16942 | # Count the number of tasks which aren't built-in tasks, but which have package names | ||
| 16943 | $count = 0; | ||
| 16944 | foreach my $taskName ($axmud::CLIENT->ivKeys('taskPackageHash')) { | ||
| 16945 | |||
| 16946 | if (! $axmud::CLIENT->ivExists('constTaskPackageHash', $taskName)) { | ||
| 16947 | |||
| 16948 | $count++; | ||
| 16949 | } | ||
| 16950 | } | ||
| 16951 | |||
| 16952 | if ($count) { | ||
| 16953 | |||
| 16954 | if ($count == 1) { | ||
| 16955 | |||
| 16956 | $text = 'This list contains 1 task which isn\'t a built-in task. Resetting all' | ||
| 16957 | . ' task package names will cause this task to disappear from the list.' | ||
| 16958 | . ' You won\'t be able to run it until you enter a new package name' | ||
| 16959 | . ' for it. Continue?'; | ||
| 16960 | |||
| 16961 | } else { | ||
| 16962 | |||
| 16963 | $text = 'This list contains ' . $count . ' tasks which aren\'t built-in tasks.' | ||
| 16964 | . ' Resetting all package names will cause these tasks to disappear from the' | ||
| 16965 | . ' list. You won\'t be able to run them until you enter new package names for' | ||
| 16966 | . ' them. Continue?'; | ||
| 16967 | } | ||
| 16968 | |||
| 16969 | $result = $self->showMsgDialogue( | ||
| 16970 | 'Reset task package name', | ||
| 16971 | 'warning', | ||
| 16972 | $text, | ||
| 16973 | 'yes-no', | ||
| 16974 | ); | ||
| 16975 | |||
| 16976 | if ($result ne 'yes') { | ||
| 16977 | |||
| 16978 | return undef; | ||
| 16979 | } | ||
| 16980 | } | ||
| 16981 | |||
| 16982 | # Reset all task packages | ||
| 16983 | $self->session->pseudoCmd('resettaskpackage', $self->pseudoCmdMode); | ||
| 16984 | |||
| 16985 | # Update the notebook | ||
| 16986 | $self->updateNotebook(); | ||
| 16987 | |||
| 16988 | return 1; | ||
| 16989 | } | ||
| 16990 | |||
| 16991 | sub buttonDump_taskPackage { | ||
| 16992 | |||
| 16993 | # Callback: Displays the list of task package names in the 'main' window (equivalent to | ||
| 16994 | # ';listtaskpackage') | ||
| 16995 | # | ||
| 16996 | # Expected arguments | ||
| 16997 | # (none besides $self) | ||
| 16998 | # | ||
| 16999 | # Return values | ||
| 17000 | # 'undef' on improper arguments | ||
| 17001 | # 1 otherwise | ||
| 17002 | |||
| 17003 | my ($self, $check) = @_; | ||
| 17004 | |||
| 17005 | # Local variables | ||
| 17006 | my ($tab, $slWidget, $standard, $package); | ||
| 17007 | |||
| 17008 | # Check for improper arguments | ||
| 17009 | if (defined $check) { | ||
| 17010 | |||
| 17011 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonHaltAll_task', @_); | ||
| 17012 | } | ||
| 17013 | |||
| 17014 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17015 | $tab = $self->notebookGetTab(); | ||
| 17016 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17017 | |||
| 17018 | # Unselect everything in the list | ||
| 17019 | $slWidget->get_selection->unselect_all(); | ||
| 17020 | |||
| 17021 | # Dump the data | ||
| 17022 | $self->session->pseudoCmd('listtaskpackage -d', $self->pseudoCmdMode); | ||
| 17023 | $self->session->pseudoCmd('listtaskpackage', $self->pseudoCmdMode); | ||
| 17024 | |||
| 17025 | # Update the notebook | ||
| 17026 | $self->updateNotebook(); | ||
| 17027 | |||
| 17028 | return 1; | ||
| 17029 | } | ||
| 17030 | |||
| 17031 | # Tasklist button callbacks - Task labels | ||
| 17032 | |||
| 17033 | sub buttonAdd_taskLabel { | ||
| 17034 | |||
| 17035 | # Callback: Adds a task label (equivalent to ';addtasklabel') | ||
| 17036 | # | ||
| 17037 | # Expected arguments | ||
| 17038 | # (none besides $self) | ||
| 17039 | # | ||
| 17040 | # Return values | ||
| 17041 | # 'undef' on improper arguments | ||
| 17042 | # 1 otherwise | ||
| 17043 | |||
| 17044 | my ($self, $check) = @_; | ||
| 17045 | |||
| 17046 | # Local variables | ||
| 17047 | my ( | ||
| 17048 | $tab, $slWidget, $label, $standard, | ||
| 17049 | @comboList, | ||
| 17050 | ); | ||
| 17051 | |||
| 17052 | # Check for improper arguments | ||
| 17053 | if (defined $check) { | ||
| 17054 | |||
| 17055 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_taskLabel', @_); | ||
| 17056 | } | ||
| 17057 | |||
| 17058 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17059 | $tab = $self->notebookGetTab(); | ||
| 17060 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17061 | |||
| 17062 | # Unselect everything in the list | ||
| 17063 | $slWidget->get_selection->unselect_all(); | ||
| 17064 | |||
| 17065 | # Get a sorted list of standard task names | ||
| 17066 | @comboList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskPackageHash')); | ||
| 17067 | |||
| 17068 | # Prompt the user for a label | ||
| 17069 | ($label, $standard) = $self->showEntryComboDialogue( | ||
| 17070 | 'Add task label', | ||
| 17071 | 'Task label', | ||
| 17072 | 'Standard task name', | ||
| 17073 | \@comboList, | ||
| 17074 | ); | ||
| 17075 | |||
| 17076 | if (defined $label && defined $standard) { | ||
| 17077 | |||
| 17078 | $self->session->pseudoCmd( | ||
| 17079 | 'addtasklabel ' . $standard . ' ' . $label, | ||
| 17080 | $self->pseudoCmdMode, | ||
| 17081 | ); | ||
| 17082 | |||
| 17083 | # Update the notebook | ||
| 17084 | $self->updateNotebook(); | ||
| 17085 | }; | ||
| 17086 | |||
| 17087 | return 1; | ||
| 17088 | } | ||
| 17089 | |||
| 17090 | sub buttonDelete_taskLabel { | ||
| 17091 | |||
| 17092 | # Callback: Delete a task label (equivalent to ';deletetasklabel') | ||
| 17093 | # | ||
| 17094 | # Expected arguments | ||
| 17095 | # (none besides $self) | ||
| 17096 | # | ||
| 17097 | # Return values | ||
| 17098 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 17099 | # 1 otherwise | ||
| 17100 | |||
| 17101 | my ($self, $check) = @_; | ||
| 17102 | |||
| 17103 | # Local variables | ||
| 17104 | my ( | ||
| 17105 | $dataRef, $label, | ||
| 17106 | @list, @dataList, | ||
| 17107 | ); | ||
| 17108 | |||
| 17109 | # Check for improper arguments | ||
| 17110 | if (defined $check) { | ||
| 17111 | |||
| 17112 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_taskLabel', @_); | ||
| 17113 | } | ||
| 17114 | |||
| 17115 | # Import the currently selected portions of the notebook list | ||
| 17116 | @list = $self->notebookGetSelectedData(); | ||
| 17117 | if (! @list) { | ||
| 17118 | |||
| 17119 | # Nothing selected | ||
| 17120 | return undef; | ||
| 17121 | } | ||
| 17122 | |||
| 17123 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 17124 | # a single row of the list | ||
| 17125 | $dataRef = $list[0]; | ||
| 17126 | @dataList = @$dataRef; | ||
| 17127 | # The label is the second item of data | ||
| 17128 | $label = $dataList[1]; | ||
| 17129 | if (! $label) { | ||
| 17130 | |||
| 17131 | # Can't continue | ||
| 17132 | return undef; | ||
| 17133 | |||
| 17134 | } else { | ||
| 17135 | |||
| 17136 | # Delete the label | ||
| 17137 | $self->session->pseudoCmd('deletetasklabel ' . $label, $self->pseudoCmdMode); | ||
| 17138 | |||
| 17139 | # Update the notebook | ||
| 17140 | $self->updateNotebook(); | ||
| 17141 | }; | ||
| 17142 | |||
| 17143 | return 1; | ||
| 17144 | } | ||
| 17145 | |||
| 17146 | sub buttonEmpty_taskLabel { | ||
| 17147 | |||
| 17148 | # Callback: Empty task labels attached to a particular task (equivalent to | ||
| 17149 | # ';addtasklabel <name>') | ||
| 17150 | # | ||
| 17151 | # Expected arguments | ||
| 17152 | # (none besides $self) | ||
| 17153 | # | ||
| 17154 | # Return values | ||
| 17155 | # 'undef' on improper arguments or if the user declines to continue the operation | ||
| 17156 | # 1 otherwise | ||
| 17157 | |||
| 17158 | my ($self, $check) = @_; | ||
| 17159 | |||
| 17160 | # Local variables | ||
| 17161 | my ( | ||
| 17162 | $tab, $slWidget, $standard, | ||
| 17163 | @comboList, | ||
| 17164 | ); | ||
| 17165 | |||
| 17166 | # Check for improper arguments | ||
| 17167 | if (defined $check) { | ||
| 17168 | |||
| 17169 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEmpty_taskLabel', @_); | ||
| 17170 | } | ||
| 17171 | |||
| 17172 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17173 | $tab = $self->notebookGetTab(); | ||
| 17174 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17175 | |||
| 17176 | # Unselect everything in the list | ||
| 17177 | $slWidget->get_selection->unselect_all(); | ||
| 17178 | |||
| 17179 | # Get a sorted list of standard task names | ||
| 17180 | @comboList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskPackageHash')); | ||
| 17181 | |||
| 17182 | # Prompt the user to choose a task | ||
| 17183 | $standard = $self->showComboDialogue( | ||
| 17184 | 'Empty labels', | ||
| 17185 | 'Select the task which should have all its labels emptied', | ||
| 17186 | \@comboList, | ||
| 17187 | ); | ||
| 17188 | |||
| 17189 | if ($standard) { | ||
| 17190 | |||
| 17191 | $self->session->pseudoCmd('addtasklabel ' . $standard, $self->pseudoCmdMode); | ||
| 17192 | |||
| 17193 | # Update the notebook | ||
| 17194 | $self->updateNotebook(); | ||
| 17195 | }; | ||
| 17196 | |||
| 17197 | return 1; | ||
| 17198 | } | ||
| 17199 | |||
| 17200 | sub buttonReset_taskLabel { | ||
| 17201 | |||
| 17202 | # Callback: Reset task labels attached to a particular task (equivalent to | ||
| 17203 | # ';resettasklabel <name>') | ||
| 17204 | # | ||
| 17205 | # Expected arguments | ||
| 17206 | # (none besides $self) | ||
| 17207 | # | ||
| 17208 | # Return values | ||
| 17209 | # 'undef' on improper arguments | ||
| 17210 | # 1 otherwise | ||
| 17211 | |||
| 17212 | my ($self, $check) = @_; | ||
| 17213 | |||
| 17214 | # Local variables | ||
| 17215 | my ( | ||
| 17216 | $tab, $slWidget, $standard, | ||
| 17217 | @comboList, | ||
| 17218 | ); | ||
| 17219 | |||
| 17220 | # Check for improper arguments | ||
| 17221 | if (defined $check) { | ||
| 17222 | |||
| 17223 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonReset_taskLabel', @_); | ||
| 17224 | } | ||
| 17225 | |||
| 17226 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17227 | $tab = $self->notebookGetTab(); | ||
| 17228 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17229 | |||
| 17230 | # Unselect everything in the list | ||
| 17231 | $slWidget->get_selection->unselect_all(); | ||
| 17232 | |||
| 17233 | # Get a sorted list of standard task names | ||
| 17234 | @comboList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('taskPackageHash')); | ||
| 17235 | |||
| 17236 | # Prompt the user to choose a task | ||
| 17237 | $standard = $self->showComboDialogue( | ||
| 17238 | 'Reset labels', | ||
| 17239 | 'Select the task which should have all its labels reset', | ||
| 17240 | \@comboList, | ||
| 17241 | ); | ||
| 17242 | |||
| 17243 | if ($standard) { | ||
| 17244 | |||
| 17245 | $self->session->pseudoCmd('resettasklabel ' . $standard, $self->pseudoCmdMode); | ||
| 17246 | |||
| 17247 | # Update the notebook | ||
| 17248 | $self->updateNotebook(); | ||
| 17249 | }; | ||
| 17250 | |||
| 17251 | return 1; | ||
| 17252 | } | ||
| 17253 | |||
| 17254 | sub buttonResetAll_taskLabel { | ||
| 17255 | |||
| 17256 | # Callback: Resets all task labels to defaults (equivalent to ';resettasklabel') | ||
| 17257 | # | ||
| 17258 | # Expected arguments | ||
| 17259 | # (none besides $self) | ||
| 17260 | # | ||
| 17261 | # Return values | ||
| 17262 | # 'undef' on improper arguments | ||
| 17263 | # 1 otherwise | ||
| 17264 | |||
| 17265 | my ($self, $check) = @_; | ||
| 17266 | |||
| 17267 | # Local variables | ||
| 17268 | my ($tab, $slWidget); | ||
| 17269 | |||
| 17270 | # Check for improper arguments | ||
| 17271 | if (defined $check) { | ||
| 17272 | |||
| 17273 | return $axmud::CLIENT->writeImproper( | ||
| 17274 | $self->_objClass . '->buttonResetAll_taskLabel', | ||
| 17275 | @_, | ||
| 17276 | ); | ||
| 17277 | } | ||
| 17278 | |||
| 17279 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17280 | $tab = $self->notebookGetTab(); | ||
| 17281 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17282 | |||
| 17283 | # Unselect everything in the list | ||
| 17284 | $slWidget->get_selection->unselect_all(); | ||
| 17285 | |||
| 17286 | # Reset all task labels | ||
| 17287 | $self->session->pseudoCmd('resettasklabel', $self->pseudoCmdMode); | ||
| 17288 | |||
| 17289 | # Update the notebook | ||
| 17290 | $self->updateNotebook(); | ||
| 17291 | |||
| 17292 | return 1; | ||
| 17293 | } | ||
| 17294 | |||
| 17295 | sub buttonDump_taskLabel { | ||
| 17296 | |||
| 17297 | # Callback: Displays the list of task labels in the 'main' window (equivalent to | ||
| 17298 | # ';listtasklabel') | ||
| 17299 | # | ||
| 17300 | # Expected arguments | ||
| 17301 | # (none besides $self) | ||
| 17302 | # | ||
| 17303 | # Return values | ||
| 17304 | # 'undef' on improper arguments | ||
| 17305 | # 1 otherwise | ||
| 17306 | |||
| 17307 | my ($self, $check) = @_; | ||
| 17308 | |||
| 17309 | # Local variables | ||
| 17310 | my ($tab, $slWidget); | ||
| 17311 | |||
| 17312 | # Check for improper arguments | ||
| 17313 | if (defined $check) { | ||
| 17314 | |||
| 17315 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_taskLabel', @_); | ||
| 17316 | } | ||
| 17317 | |||
| 17318 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17319 | $tab = $self->notebookGetTab(); | ||
| 17320 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17321 | |||
| 17322 | # Unselect everything in the list | ||
| 17323 | $slWidget->get_selection->unselect_all(); | ||
| 17324 | |||
| 17325 | # Dump the data | ||
| 17326 | $self->session->pseudoCmd('listtasklabel -b', $self->pseudoCmdMode); | ||
| 17327 | $self->session->pseudoCmd('listtasklabel', $self->pseudoCmdMode); | ||
| 17328 | |||
| 17329 | # Update the notebook | ||
| 17330 | $self->updateNotebook(); | ||
| 17331 | |||
| 17332 | return 1; | ||
| 17333 | } | ||
| 17334 | |||
| 17335 | # Interfaces and interface model callbacks | ||
| 17336 | |||
| 17337 | sub buttonEdit_activeInterface { | ||
| 17338 | |||
| 17339 | # Callback: Edits an active interface (equivalent to ';editactiveinterface') | ||
| 17340 | # | ||
| 17341 | # Expected arguments | ||
| 17342 | # (none besides $self) | ||
| 17343 | # | ||
| 17344 | # Return values | ||
| 17345 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 17346 | # object no longer exists | ||
| 17347 | # 1 otherwise | ||
| 17348 | |||
| 17349 | my ($self, $check) = @_; | ||
| 17350 | |||
| 17351 | # Local variables | ||
| 17352 | my ( | ||
| 17353 | $dataRef, $interfaceNum, $interfaceObj, | ||
| 17354 | @list, @dataList, | ||
| 17355 | ); | ||
| 17356 | |||
| 17357 | # Check for improper arguments | ||
| 17358 | if (defined $check) { | ||
| 17359 | |||
| 17360 | return $axmud::CLIENT->writeImproper( | ||
| 17361 | $self->_objClass . '->buttonEdit_activeInterface', | ||
| 17362 | @_, | ||
| 17363 | ); | ||
| 17364 | } | ||
| 17365 | |||
| 17366 | # Import the currently selected portions of the notebook list | ||
| 17367 | @list = $self->notebookGetSelectedData(); | ||
| 17368 | if (! @list) { | ||
| 17369 | |||
| 17370 | # Nothing selected | ||
| 17371 | return undef; | ||
| 17372 | } | ||
| 17373 | |||
| 17374 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 17375 | # a single row of the list | ||
| 17376 | $dataRef = $list[0]; | ||
| 17377 | @dataList = @$dataRef; | ||
| 17378 | # The interface's number is the first item of data | ||
| 17379 | $interfaceNum = $dataList[0]; | ||
| 17380 | if (! $interfaceNum) { | ||
| 17381 | |||
| 17382 | # Can't continue | ||
| 17383 | return undef; | ||
| 17384 | } | ||
| 17385 | |||
| 17386 | # Get the interface object itself | ||
| 17387 | $interfaceObj = $self->session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 17388 | if (! $interfaceObj) { | ||
| 17389 | |||
| 17390 | # Can't continue | ||
| 17391 | return undef; | ||
| 17392 | |||
| 17393 | } else { | ||
| 17394 | |||
| 17395 | # Open up an 'edit' window to edit the object | ||
| 17396 | $self->createFreeWin( | ||
| 17397 | 'Games::Axmud::EditWin::Interface::Active', | ||
| 17398 | $self, | ||
| 17399 | $self->session, | ||
| 17400 | 'Edit active ' . $interfaceObj->category . ' interface \'' . $interfaceObj->name | ||
| 17401 | . '\'', | ||
| 17402 | $interfaceObj, | ||
| 17403 | FALSE, # Not temporary | ||
| 17404 | ); | ||
| 17405 | |||
| 17406 | return 1; | ||
| 17407 | } | ||
| 17408 | } | ||
| 17409 | |||
| 17410 | sub buttonDump_activeInterface { | ||
| 17411 | |||
| 17412 | # Callback: Displays the list of active interfaces to the 'main' window (equivalent to | ||
| 17413 | # ';listactiveinterface' <switch>) | ||
| 17414 | # | ||
| 17415 | # Expected arguments | ||
| 17416 | # (none besides $self) | ||
| 17417 | # | ||
| 17418 | # Return values | ||
| 17419 | # 'undef' on improper arguments | ||
| 17420 | # 1 otherwise | ||
| 17421 | |||
| 17422 | my ($self, $check) = @_; | ||
| 17423 | |||
| 17424 | # Local variables | ||
| 17425 | my ($tab, $slWidget); | ||
| 17426 | |||
| 17427 | # Check for improper arguments | ||
| 17428 | if (defined $check) { | ||
| 17429 | |||
| 17430 | return $axmud::CLIENT->writeImproper( | ||
| 17431 | $self->_objClass . '->buttonDump_activeInterface', | ||
| 17432 | @_, | ||
| 17433 | ); | ||
| 17434 | } | ||
| 17435 | |||
| 17436 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17437 | $tab = $self->notebookGetTab(); | ||
| 17438 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17439 | |||
| 17440 | # Unselect everything in the list | ||
| 17441 | $slWidget->get_selection->unselect_all(); | ||
| 17442 | |||
| 17443 | # Dump the data | ||
| 17444 | if ($tab eq 'All') { | ||
| 17445 | |||
| 17446 | $self->session->pseudoCmd('listactiveinterface -n', $self->pseudoCmdMode); | ||
| 17447 | |||
| 17448 | } elsif ($tab eq 'Dependent') { | ||
| 17449 | |||
| 17450 | $self->session->pseudoCmd('listactiveinterface -d', $self->pseudoCmdMode); | ||
| 17451 | |||
| 17452 | } elsif ($tab eq 'Independent') { | ||
| 17453 | |||
| 17454 | $self->session->pseudoCmd('listactiveinterface -i', $self->pseudoCmdMode); | ||
| 17455 | |||
| 17456 | } else { | ||
| 17457 | |||
| 17458 | # Trigger, Alias (etc) tabs | ||
| 17459 | $self->session->pseudoCmd('listactiveinterface -c ' . lc($tab), $self->pseudoCmdMode); | ||
| 17460 | } | ||
| 17461 | |||
| 17462 | # Update the notebook | ||
| 17463 | $self->updateNotebook(); | ||
| 17464 | |||
| 17465 | return 1; | ||
| 17466 | } | ||
| 17467 | |||
| 17468 | sub buttonView_interfaceModel { | ||
| 17469 | |||
| 17470 | # Callback: Views an interface model object (equivalent to ';editinterfacemodel') | ||
| 17471 | # | ||
| 17472 | # Expected arguments | ||
| 17473 | # (none besides $self) | ||
| 17474 | # | ||
| 17475 | # Return values | ||
| 17476 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 17477 | # object no longer exists | ||
| 17478 | # 1 otherwise | ||
| 17479 | |||
| 17480 | my ($self, $check) = @_; | ||
| 17481 | |||
| 17482 | # Local variables | ||
| 17483 | my ( | ||
| 17484 | $dataRef, $interfaceModelName, $interfaceModelObj, | ||
| 17485 | @list, @dataList, | ||
| 17486 | ); | ||
| 17487 | |||
| 17488 | # Check for improper arguments | ||
| 17489 | if (defined $check) { | ||
| 17490 | |||
| 17491 | return $axmud::CLIENT->writeImproper( | ||
| 17492 | $self->_objClass . '->buttonView_interfaceModel', | ||
| 17493 | @_, | ||
| 17494 | ); | ||
| 17495 | } | ||
| 17496 | |||
| 17497 | # Import the currently selected portions of the notebook list | ||
| 17498 | @list = $self->notebookGetSelectedData(); | ||
| 17499 | if (! @list) { | ||
| 17500 | |||
| 17501 | # Nothing selected | ||
| 17502 | return undef; | ||
| 17503 | } | ||
| 17504 | |||
| 17505 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 17506 | # a single row of the list | ||
| 17507 | $dataRef = $list[0]; | ||
| 17508 | @dataList = @$dataRef; | ||
| 17509 | # The interface model's name is the first item of data | ||
| 17510 | $interfaceModelName = $dataList[0]; | ||
| 17511 | if (! $interfaceModelName) { | ||
| 17512 | |||
| 17513 | # Can't continue | ||
| 17514 | return undef; | ||
| 17515 | } | ||
| 17516 | |||
| 17517 | # Get the interface model object itself | ||
| 17518 | $interfaceModelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $interfaceModelName); | ||
| 17519 | if (! $interfaceModelObj) { | ||
| 17520 | |||
| 17521 | # Can't continue | ||
| 17522 | return undef; | ||
| 17523 | |||
| 17524 | } else { | ||
| 17525 | |||
| 17526 | # Open up an 'edit' window to edit the object | ||
| 17527 | $self->createFreeWin( | ||
| 17528 | 'Games::Axmud::EditWin::InterfaceModel', | ||
| 17529 | $self, | ||
| 17530 | $self->session, | ||
| 17531 | 'Edit ' . $interfaceModelObj->category . ' interface model', | ||
| 17532 | $interfaceModelObj, | ||
| 17533 | FALSE, # Not temporary | ||
| 17534 | ); | ||
| 17535 | |||
| 17536 | return 1; | ||
| 17537 | } | ||
| 17538 | } | ||
| 17539 | |||
| 17540 | sub buttonDump_interfaceModel { | ||
| 17541 | |||
| 17542 | # Callback: Displays the list of interface models to the 'main' window (equivalent to | ||
| 17543 | # ';listinterfacemodel' <switch>) | ||
| 17544 | # | ||
| 17545 | # Expected arguments | ||
| 17546 | # (none besides $self) | ||
| 17547 | # | ||
| 17548 | # Return values | ||
| 17549 | # 'undef' on improper arguments | ||
| 17550 | # 1 otherwise | ||
| 17551 | |||
| 17552 | my ($self, $check) = @_; | ||
| 17553 | |||
| 17554 | # Local variables | ||
| 17555 | my ($tab, $slWidget); | ||
| 17556 | |||
| 17557 | # Check for improper arguments | ||
| 17558 | if (defined $check) { | ||
| 17559 | |||
| 17560 | return $axmud::CLIENT->writeImproper( | ||
| 17561 | $self->_objClass . '->buttonDump_interfaceModel', | ||
| 17562 | @_, | ||
| 17563 | ); | ||
| 17564 | } | ||
| 17565 | |||
| 17566 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17567 | $tab = $self->notebookGetTab(); | ||
| 17568 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17569 | |||
| 17570 | # Unselect everything in the list | ||
| 17571 | $slWidget->get_selection->unselect_all(); | ||
| 17572 | |||
| 17573 | # Dump the data | ||
| 17574 | $self->session->pseudoCmd('listinterfacemodel', $self->pseudoCmdMode); | ||
| 17575 | |||
| 17576 | # Update the notebook | ||
| 17577 | $self->updateNotebook(); | ||
| 17578 | |||
| 17579 | return 1; | ||
| 17580 | } | ||
| 17581 | |||
| 17582 | # World model callbacks | ||
| 17583 | |||
| 17584 | sub buttonAdd_model { | ||
| 17585 | |||
| 17586 | # Callback: Adds a world model object (equivalent to ';addmodelobject') | ||
| 17587 | # | ||
| 17588 | # Expected arguments | ||
| 17589 | # (none besides $self) | ||
| 17590 | # | ||
| 17591 | # Return values | ||
| 17592 | # 'undef' on improper arguments | ||
| 17593 | # 1 otherwise | ||
| 17594 | |||
| 17595 | my ($self, $check) = @_; | ||
| 17596 | |||
| 17597 | # Local variables | ||
| 17598 | my ( | ||
| 17599 | $tab, $slWidget, $objName, $objParent, $string, | ||
| 17600 | %switchHash, %typeHash, | ||
| 17601 | ); | ||
| 17602 | |||
| 17603 | # Check for improper arguments | ||
| 17604 | if (defined $check) { | ||
| 17605 | |||
| 17606 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_model', @_); | ||
| 17607 | } | ||
| 17608 | |||
| 17609 | # Compile a quick hash of switches accepted by ;addmodelobject | ||
| 17610 | %switchHash = ( | ||
| 17611 | 'Weapons' => '-w', | ||
| 17612 | 'Armours' => '-a', | ||
| 17613 | 'Garments' => '-g', | ||
| 17614 | 'Characters' => '-c', | ||
| 17615 | 'Minions' => '-m', | ||
| 17616 | 'Sentients' => '-s', | ||
| 17617 | 'Creatures' => '-k', | ||
| 17618 | 'Portables' => '-p', | ||
| 17619 | 'Decorations' => '-d', | ||
| 17620 | 'Custom' => '-u', | ||
| 17621 | ); | ||
| 17622 | |||
| 17623 | # Also a hash to convert the tab name to the type of model object | ||
| 17624 | %typeHash = ( | ||
| 17625 | 'Weapons' => 'weapon', | ||
| 17626 | 'Armours' => 'armour', | ||
| 17627 | 'Garments' => 'garment', | ||
| 17628 | 'Characters' => 'char', | ||
| 17629 | 'Minions' => 'minion', | ||
| 17630 | 'Sentients' => 'sentient', | ||
| 17631 | 'Creatures' => 'creature', | ||
| 17632 | 'Portables' => 'portable', | ||
| 17633 | 'Decorations' => 'decoration', | ||
| 17634 | 'Custom' => 'custom', | ||
| 17635 | ); | ||
| 17636 | |||
| 17637 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17638 | $tab = $self->notebookGetTab(); | ||
| 17639 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17640 | |||
| 17641 | # Unselect everything in the list, because we're creating a new model object | ||
| 17642 | $slWidget->get_selection->unselect_all(); | ||
| 17643 | |||
| 17644 | # Prompt to get a name for the object | ||
| 17645 | ($objName, $objParent) = $self->showDoubleEntryDialogue( | ||
| 17646 | 'Add \'' . $typeHash{$tab} . '\' model object', | ||
| 17647 | 'Object name', | ||
| 17648 | 'Parent # (optional)', | ||
| 17649 | ); | ||
| 17650 | |||
| 17651 | if ($objName) { | ||
| 17652 | |||
| 17653 | if ($objParent) { | ||
| 17654 | $string = '<' . $objName . '> ' . $objParent; | ||
| 17655 | } else { | ||
| 17656 | $string = '<' . $objName . '>'; | ||
| 17657 | } | ||
| 17658 | |||
| 17659 | # Add the new world model object | ||
| 17660 | $self->session->pseudoCmd( | ||
| 17661 | 'addmodelobject ' . $switchHash{$tab} . ' ' . $string, | ||
| 17662 | $self->pseudoCmdMode, | ||
| 17663 | ); | ||
| 17664 | |||
| 17665 | # Update the notebook | ||
| 17666 | $self->updateNotebook(); | ||
| 17667 | } | ||
| 17668 | |||
| 17669 | return 1; | ||
| 17670 | } | ||
| 17671 | |||
| 17672 | sub buttonAddRegion_model { | ||
| 17673 | |||
| 17674 | # Callback: Adds a region model object (equivalent to ';addregion') | ||
| 17675 | # | ||
| 17676 | # Expected arguments | ||
| 17677 | # (none besides $self) | ||
| 17678 | # | ||
| 17679 | # Return values | ||
| 17680 | # 'undef' on improper arguments | ||
| 17681 | # 1 otherwise | ||
| 17682 | |||
| 17683 | my ($self, $check) = @_; | ||
| 17684 | |||
| 17685 | # Local variables | ||
| 17686 | my ( | ||
| 17687 | $tab, $slWidget, $objName, $objParent, $string, | ||
| 17688 | %switchHash, | ||
| 17689 | ); | ||
| 17690 | |||
| 17691 | # Check for improper arguments | ||
| 17692 | if (defined $check) { | ||
| 17693 | |||
| 17694 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAddRegion_model', @_); | ||
| 17695 | } | ||
| 17696 | |||
| 17697 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17698 | $tab = $self->notebookGetTab(); | ||
| 17699 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17700 | |||
| 17701 | # Unselect everything in the list, because we're creating a new model object | ||
| 17702 | $slWidget->get_selection->unselect_all(); | ||
| 17703 | |||
| 17704 | # Prompt to get a name for the object | ||
| 17705 | ($objName, $objParent) = $self->showDoubleEntryDialogue( | ||
| 17706 | 'Add region model object', | ||
| 17707 | 'Region name', | ||
| 17708 | 'Parent region name (optional)', | ||
| 17709 | ); | ||
| 17710 | |||
| 17711 | if ($objName) { | ||
| 17712 | |||
| 17713 | if ($objParent) { | ||
| 17714 | $string = '<' . $objName . '> ' . $objParent; | ||
| 17715 | } else { | ||
| 17716 | $string = '<' . $objName . '>'; | ||
| 17717 | } | ||
| 17718 | |||
| 17719 | # Add the new region model object | ||
| 17720 | $self->session->pseudoCmd( | ||
| 17721 | 'addregion ' . $string, | ||
| 17722 | $self->pseudoCmdMode, | ||
| 17723 | ); | ||
| 17724 | |||
| 17725 | # Update the notebook | ||
| 17726 | $self->updateNotebook(); | ||
| 17727 | } | ||
| 17728 | |||
| 17729 | return 1; | ||
| 17730 | } | ||
| 17731 | |||
| 17732 | sub buttonAddChar_model { | ||
| 17733 | |||
| 17734 | # Callback: Adds a character model object (equivalent to ';addplayercharacter') | ||
| 17735 | # | ||
| 17736 | # Expected arguments | ||
| 17737 | # (none besides $self) | ||
| 17738 | # | ||
| 17739 | # Return values | ||
| 17740 | # 'undef' on improper arguments | ||
| 17741 | # 1 otherwise | ||
| 17742 | |||
| 17743 | my ($self, $check) = @_; | ||
| 17744 | |||
| 17745 | # Local variables | ||
| 17746 | my ( | ||
| 17747 | $tab, $slWidget, $objName, $objParent, $string, | ||
| 17748 | %switchHash, | ||
| 17749 | ); | ||
| 17750 | |||
| 17751 | # Check for improper arguments | ||
| 17752 | if (defined $check) { | ||
| 17753 | |||
| 17754 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAddChar_model', @_); | ||
| 17755 | } | ||
| 17756 | |||
| 17757 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17758 | $tab = $self->notebookGetTab(); | ||
| 17759 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17760 | |||
| 17761 | # Unselect everything in the list, because we're creating a new model object | ||
| 17762 | $slWidget->get_selection->unselect_all(); | ||
| 17763 | |||
| 17764 | # Prompt to get a name for the object | ||
| 17765 | ($objName, $objParent) = $self->showDoubleEntryDialogue( | ||
| 17766 | 'Add character model object', | ||
| 17767 | 'Character name', | ||
| 17768 | 'Parent object # (optional)', | ||
| 17769 | 16, # Max length 16 characters, to match profile name maximum | ||
| 17770 | ); | ||
| 17771 | |||
| 17772 | if ($objName) { | ||
| 17773 | |||
| 17774 | if ($objParent) { | ||
| 17775 | $string = '<' . $objName . '> ' . $objParent; | ||
| 17776 | } else { | ||
| 17777 | $string = '<' . $objName . '>'; | ||
| 17778 | } | ||
| 17779 | |||
| 17780 | # Add the new region model object | ||
| 17781 | $self->session->pseudoCmd( | ||
| 17782 | 'addplayercharacter ' . $string, | ||
| 17783 | $self->pseudoCmdMode, | ||
| 17784 | ); | ||
| 17785 | |||
| 17786 | # Update the notebook | ||
| 17787 | $self->updateNotebook(); | ||
| 17788 | } | ||
| 17789 | |||
| 17790 | return 1; | ||
| 17791 | } | ||
| 17792 | |||
| 17793 | sub buttonAddTempRegion_model { | ||
| 17794 | |||
| 17795 | # Callback: Adds a temporary region model object (equivalent to ';addregion -t') | ||
| 17796 | # | ||
| 17797 | # Expected arguments | ||
| 17798 | # (none besides $self) | ||
| 17799 | # | ||
| 17800 | # Return values | ||
| 17801 | # 'undef' on improper arguments | ||
| 17802 | # 1 otherwise | ||
| 17803 | |||
| 17804 | my ($self, $check) = @_; | ||
| 17805 | |||
| 17806 | # Local variables | ||
| 17807 | my ( | ||
| 17808 | $tab, $slWidget, $objName, $objParent, $string, | ||
| 17809 | %switchHash, | ||
| 17810 | ); | ||
| 17811 | |||
| 17812 | # Check for improper arguments | ||
| 17813 | if (defined $check) { | ||
| 17814 | |||
| 17815 | return $axmud::CLIENT->writeImproper( | ||
| 17816 | $self->_objClass . '->buttonAddTempRegion_model', | ||
| 17817 | @_, | ||
| 17818 | ); | ||
| 17819 | } | ||
| 17820 | |||
| 17821 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17822 | $tab = $self->notebookGetTab(); | ||
| 17823 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17824 | |||
| 17825 | # Unselect everything in the list, because we're creating a new model object | ||
| 17826 | $slWidget->get_selection->unselect_all(); | ||
| 17827 | |||
| 17828 | # Prompt to get a name for the object | ||
| 17829 | ($objName, $objParent) = $self->showDoubleEntryDialogue( | ||
| 17830 | 'Add temporary region model object', | ||
| 17831 | 'Region name', | ||
| 17832 | 'Parent region name (optional)', | ||
| 17833 | ); | ||
| 17834 | |||
| 17835 | if ($objName) { | ||
| 17836 | |||
| 17837 | if ($objParent) { | ||
| 17838 | $string = '<' . $objName . '> <' . $objParent . '>'; | ||
| 17839 | } else { | ||
| 17840 | $string = '<' . $objName . '>'; | ||
| 17841 | } | ||
| 17842 | |||
| 17843 | # Add the new region model object | ||
| 17844 | $self->session->pseudoCmd( | ||
| 17845 | 'addregion ' . $string . ' -t', | ||
| 17846 | $self->pseudoCmdMode, | ||
| 17847 | ); | ||
| 17848 | |||
| 17849 | # Update the notebook | ||
| 17850 | $self->updateNotebook(); | ||
| 17851 | } | ||
| 17852 | |||
| 17853 | return 1; | ||
| 17854 | } | ||
| 17855 | |||
| 17856 | sub buttonEdit_model { | ||
| 17857 | |||
| 17858 | # Callback: Edits a world model object (equivalent to ';editmodelobject') | ||
| 17859 | # | ||
| 17860 | # Expected arguments | ||
| 17861 | # (none besides $self) | ||
| 17862 | # | ||
| 17863 | # Return values | ||
| 17864 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 17865 | # object no longer exists | ||
| 17866 | # 1 otherwise | ||
| 17867 | |||
| 17868 | my ($self, $check) = @_; | ||
| 17869 | |||
| 17870 | # Local variables | ||
| 17871 | my ( | ||
| 17872 | $dataRef, $number, $obj, $package, | ||
| 17873 | @list, @dataList, | ||
| 17874 | ); | ||
| 17875 | |||
| 17876 | # Check for improper arguments | ||
| 17877 | if (defined $check) { | ||
| 17878 | |||
| 17879 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_model', @_); | ||
| 17880 | } | ||
| 17881 | |||
| 17882 | # Import the currently selected portions of the notebook list | ||
| 17883 | @list = $self->notebookGetSelectedData(); | ||
| 17884 | if (! @list) { | ||
| 17885 | |||
| 17886 | # Nothing selected | ||
| 17887 | return undef; | ||
| 17888 | } | ||
| 17889 | |||
| 17890 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 17891 | # a single row of the list | ||
| 17892 | $dataRef = $list[0]; | ||
| 17893 | @dataList = @$dataRef; | ||
| 17894 | # The world model object's unique number is the first item of data | ||
| 17895 | $number = $dataList[0]; | ||
| 17896 | if (! $number) { | ||
| 17897 | |||
| 17898 | # Can't continue | ||
| 17899 | return undef; | ||
| 17900 | } | ||
| 17901 | |||
| 17902 | # Get the world model object itself | ||
| 17903 | $obj = $self->session->worldModelObj->ivShow('modelHash', $number); | ||
| 17904 | if (! $obj) { | ||
| 17905 | |||
| 17906 | # Can't continue | ||
| 17907 | return undef; | ||
| 17908 | |||
| 17909 | } else { | ||
| 17910 | |||
| 17911 | $package = 'Games::Axmud::EditWin::ModelObj::' . ucfirst($obj->category); | ||
| 17912 | |||
| 17913 | # Open up an 'edit' window to edit the object | ||
| 17914 | $self->createFreeWin( | ||
| 17915 | 'Games::Axmud::EditWin::ModelObj::' . ucfirst($obj->category), | ||
| 17916 | $self, | ||
| 17917 | $self->session, | ||
| 17918 | 'Edit ' . $obj->category . ' model object #' . $obj->number, | ||
| 17919 | $obj, | ||
| 17920 | FALSE, | ||
| 17921 | ); | ||
| 17922 | } | ||
| 17923 | |||
| 17924 | return 1; | ||
| 17925 | } | ||
| 17926 | |||
| 17927 | sub buttonEdit_worldModel { | ||
| 17928 | |||
| 17929 | # Callback: Edits a world model object (equivalent to ';editmodel') | ||
| 17930 | # | ||
| 17931 | # Expected arguments | ||
| 17932 | # (none besides $self) | ||
| 17933 | # | ||
| 17934 | # Return values | ||
| 17935 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 17936 | # object no longer exists | ||
| 17937 | # 1 otherwise | ||
| 17938 | |||
| 17939 | my ($self, $check) = @_; | ||
| 17940 | |||
| 17941 | # Local variables | ||
| 17942 | my ($tab, $slWidget); | ||
| 17943 | |||
| 17944 | # Check for improper arguments | ||
| 17945 | if (defined $check) { | ||
| 17946 | |||
| 17947 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_worldModel', @_); | ||
| 17948 | } | ||
| 17949 | |||
| 17950 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 17951 | $tab = $self->notebookGetTab(); | ||
| 17952 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 17953 | |||
| 17954 | # Unselect everything in the list, because we're creating a new model object | ||
| 17955 | $slWidget->get_selection->unselect_all(); | ||
| 17956 | |||
| 17957 | # Open up an 'edit' window to edit the world model | ||
| 17958 | $self->createFreeWin( | ||
| 17959 | 'Games::Axmud::EditWin::WorldModel', | ||
| 17960 | $self, | ||
| 17961 | $self->session, | ||
| 17962 | 'Edit world model', | ||
| 17963 | $self->session->worldModelObj, | ||
| 17964 | FALSE, | ||
| 17965 | ); | ||
| 17966 | |||
| 17967 | return 1; | ||
| 17968 | } | ||
| 17969 | |||
| 17970 | sub buttonEdit_regionmap { | ||
| 17971 | |||
| 17972 | # Callback: Edits a regionmap corresponding to the selected world model object (equivalent | ||
| 17973 | # to ';editregionmap') | ||
| 17974 | # | ||
| 17975 | # Expected arguments | ||
| 17976 | # (none besides $self) | ||
| 17977 | # | ||
| 17978 | # Return values | ||
| 17979 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 17980 | # object no longer exists | ||
| 17981 | # 1 otherwise | ||
| 17982 | |||
| 17983 | my ($self, $check) = @_; | ||
| 17984 | |||
| 17985 | # Local variables | ||
| 17986 | my ( | ||
| 17987 | $dataRef, $name, $obj, | ||
| 17988 | @list, @dataList, | ||
| 17989 | ); | ||
| 17990 | |||
| 17991 | # Check for improper arguments | ||
| 17992 | if (defined $check) { | ||
| 17993 | |||
| 17994 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_regionmap', @_); | ||
| 17995 | } | ||
| 17996 | |||
| 17997 | # Import the currently selected portions of the notebook list | ||
| 17998 | @list = $self->notebookGetSelectedData(); | ||
| 17999 | if (! @list) { | ||
| 18000 | |||
| 18001 | # Nothing selected | ||
| 18002 | return undef; | ||
| 18003 | } | ||
| 18004 | |||
| 18005 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18006 | # a single row of the list | ||
| 18007 | $dataRef = $list[0]; | ||
| 18008 | @dataList = @$dataRef; | ||
| 18009 | # The regionmap's name is the third item of data | ||
| 18010 | $name = $dataList[2]; | ||
| 18011 | if (! $name) { | ||
| 18012 | |||
| 18013 | # Can't continue | ||
| 18014 | return undef; | ||
| 18015 | } | ||
| 18016 | |||
| 18017 | # Get the regionmap object itself | ||
| 18018 | $obj = $self->session->worldModelObj->ivShow('regionmapHash', $name); | ||
| 18019 | if (! $obj) { | ||
| 18020 | |||
| 18021 | # Can't continue | ||
| 18022 | return undef; | ||
| 18023 | |||
| 18024 | } else { | ||
| 18025 | |||
| 18026 | # Open up an 'edit' window to edit the object | ||
| 18027 | $self->createFreeWin( | ||
| 18028 | 'Games::Axmud::EditWin::Regionmap', | ||
| 18029 | $self, | ||
| 18030 | $self->session, | ||
| 18031 | 'Edit regionmap \'' . $obj->name . '\'', | ||
| 18032 | $obj, | ||
| 18033 | FALSE, | ||
| 18034 | ); | ||
| 18035 | } | ||
| 18036 | |||
| 18037 | return 1; | ||
| 18038 | } | ||
| 18039 | |||
| 18040 | sub buttonDelete_model { | ||
| 18041 | |||
| 18042 | # Callback: Deletes a world model object (equivalent to ';deletemodelobject') | ||
| 18043 | # | ||
| 18044 | # Expected arguments | ||
| 18045 | # (none besides $self) | ||
| 18046 | # | ||
| 18047 | # Return values | ||
| 18048 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 18049 | # 1 otherwise | ||
| 18050 | |||
| 18051 | my ($self, $check) = @_; | ||
| 18052 | |||
| 18053 | # Local variables | ||
| 18054 | my ( | ||
| 18055 | $dataRef, $number, | ||
| 18056 | @list, @dataList, | ||
| 18057 | ); | ||
| 18058 | |||
| 18059 | # Check for improper arguments | ||
| 18060 | if (defined $check) { | ||
| 18061 | |||
| 18062 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_model', @_); | ||
| 18063 | } | ||
| 18064 | |||
| 18065 | # Import the currently selected portions of the notebook list | ||
| 18066 | @list = $self->notebookGetSelectedData(); | ||
| 18067 | if (! @list) { | ||
| 18068 | |||
| 18069 | # Nothing selected | ||
| 18070 | return undef; | ||
| 18071 | } | ||
| 18072 | |||
| 18073 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18074 | # a single row of the list | ||
| 18075 | $dataRef = $list[0]; | ||
| 18076 | @dataList = @$dataRef; | ||
| 18077 | # The model object number is the first item of data | ||
| 18078 | $number = $dataList[0]; | ||
| 18079 | if (! $number) { | ||
| 18080 | |||
| 18081 | # Can't continue | ||
| 18082 | return undef; | ||
| 18083 | } | ||
| 18084 | |||
| 18085 | # Delete the world model object | ||
| 18086 | $self->session->pseudoCmd('deletemodelobject ' . $number, $self->pseudoCmdMode); | ||
| 18087 | |||
| 18088 | # Update the notebook | ||
| 18089 | $self->updateNotebook(); | ||
| 18090 | |||
| 18091 | return 1; | ||
| 18092 | } | ||
| 18093 | |||
| 18094 | sub buttonDeleteRegion_model { | ||
| 18095 | |||
| 18096 | # Callback: Deletes a region model object (equivalent to ';deleteregion') | ||
| 18097 | # | ||
| 18098 | # Expected arguments | ||
| 18099 | # (none besides $self) | ||
| 18100 | # | ||
| 18101 | # Return values | ||
| 18102 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 18103 | # 1 otherwise | ||
| 18104 | |||
| 18105 | my ($self, $check) = @_; | ||
| 18106 | |||
| 18107 | # Local variables | ||
| 18108 | my ( | ||
| 18109 | $dataRef, $number, | ||
| 18110 | @list, @dataList, | ||
| 18111 | ); | ||
| 18112 | |||
| 18113 | # Check for improper arguments | ||
| 18114 | if (defined $check) { | ||
| 18115 | |||
| 18116 | return $axmud::CLIENT->writeImproper( | ||
| 18117 | $self->_objClass . '->buttonDeleteRegion_model', | ||
| 18118 | @_, | ||
| 18119 | ); | ||
| 18120 | } | ||
| 18121 | |||
| 18122 | # Import the currently selected portions of the notebook list | ||
| 18123 | @list = $self->notebookGetSelectedData(); | ||
| 18124 | if (! @list) { | ||
| 18125 | |||
| 18126 | # Nothing selected | ||
| 18127 | return undef; | ||
| 18128 | } | ||
| 18129 | |||
| 18130 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18131 | # a single row of the list | ||
| 18132 | $dataRef = $list[0]; | ||
| 18133 | @dataList = @$dataRef; | ||
| 18134 | # The model object number is the first item of data | ||
| 18135 | $number = $dataList[0]; | ||
| 18136 | if (! $number) { | ||
| 18137 | |||
| 18138 | # Can't continue | ||
| 18139 | return undef; | ||
| 18140 | } | ||
| 18141 | |||
| 18142 | # Delete the region model object | ||
| 18143 | $self->session->pseudoCmd('deleteregion ' . $number, $self->pseudoCmdMode); | ||
| 18144 | |||
| 18145 | # Update the notebook | ||
| 18146 | $self->updateNotebook(); | ||
| 18147 | |||
| 18148 | return 1; | ||
| 18149 | } | ||
| 18150 | |||
| 18151 | sub buttonDeleteRoom_model { | ||
| 18152 | |||
| 18153 | # Callback: Deletes a room model object (equivalent to ';deleteroom') | ||
| 18154 | # | ||
| 18155 | # Expected arguments | ||
| 18156 | # (none besides $self) | ||
| 18157 | # | ||
| 18158 | # Return values | ||
| 18159 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 18160 | # 1 otherwise | ||
| 18161 | |||
| 18162 | my ($self, $check) = @_; | ||
| 18163 | |||
| 18164 | # Local variables | ||
| 18165 | my ( | ||
| 18166 | $dataRef, $number, | ||
| 18167 | @list, @dataList, | ||
| 18168 | ); | ||
| 18169 | |||
| 18170 | # Check for improper arguments | ||
| 18171 | if (defined $check) { | ||
| 18172 | |||
| 18173 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDeleteRoom_model', @_); | ||
| 18174 | } | ||
| 18175 | |||
| 18176 | # Import the currently selected portions of the notebook list | ||
| 18177 | @list = $self->notebookGetSelectedData(); | ||
| 18178 | if (! @list) { | ||
| 18179 | |||
| 18180 | # Nothing selected | ||
| 18181 | return undef; | ||
| 18182 | } | ||
| 18183 | |||
| 18184 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18185 | # a single row of the list | ||
| 18186 | $dataRef = $list[0]; | ||
| 18187 | @dataList = @$dataRef; | ||
| 18188 | # The model object number is the first item of data | ||
| 18189 | $number = $dataList[0]; | ||
| 18190 | if (! $number) { | ||
| 18191 | |||
| 18192 | # Can't continue | ||
| 18193 | return undef; | ||
| 18194 | } | ||
| 18195 | |||
| 18196 | # Delete the room model object | ||
| 18197 | $self->session->pseudoCmd('deleteroom ' . $number, $self->pseudoCmdMode); | ||
| 18198 | |||
| 18199 | # Update the notebook | ||
| 18200 | $self->updateNotebook(); | ||
| 18201 | |||
| 18202 | return 1; | ||
| 18203 | } | ||
| 18204 | |||
| 18205 | sub buttonDump_Model { | ||
| 18206 | |||
| 18207 | # Callback: Displays a list of world model objects in the 'main' window (equivalent to | ||
| 18208 | # ';dumpmodel') | ||
| 18209 | # | ||
| 18210 | # Expected arguments | ||
| 18211 | # (none besides $self) | ||
| 18212 | # | ||
| 18213 | # Return values | ||
| 18214 | # 'undef' on improper arguments | ||
| 18215 | # 1 otherwise | ||
| 18216 | |||
| 18217 | my ($self, $check) = @_; | ||
| 18218 | |||
| 18219 | # Local variables | ||
| 18220 | my ($tab, $slWidget); | ||
| 18221 | |||
| 18222 | # Check for improper arguments | ||
| 18223 | if (defined $check) { | ||
| 18224 | |||
| 18225 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_Model', @_); | ||
| 18226 | } | ||
| 18227 | |||
| 18228 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18229 | $tab = $self->notebookGetTab(); | ||
| 18230 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18231 | |||
| 18232 | # Unselect everything in the list | ||
| 18233 | $slWidget->get_selection->unselect_all(); | ||
| 18234 | |||
| 18235 | # Display the list | ||
| 18236 | $self->session->pseudoCmd('dumpmodel', $self->pseudoCmdMode); | ||
| 18237 | |||
| 18238 | return 1; | ||
| 18239 | } | ||
| 18240 | |||
| 18241 | sub buttonDumpChar_model { | ||
| 18242 | |||
| 18243 | # Callback: Displays a list of character model objects in the 'main' window (equivalent to | ||
| 18244 | # ';listplayercharacter -a') | ||
| 18245 | # | ||
| 18246 | # Expected arguments | ||
| 18247 | # (none besides $self) | ||
| 18248 | # | ||
| 18249 | # Return values | ||
| 18250 | # 'undef' on improper arguments | ||
| 18251 | # 1 otherwise | ||
| 18252 | |||
| 18253 | my ($self, $check) = @_; | ||
| 18254 | |||
| 18255 | # Local variables | ||
| 18256 | my ($tab, $slWidget); | ||
| 18257 | |||
| 18258 | # Check for improper arguments | ||
| 18259 | if (defined $check) { | ||
| 18260 | |||
| 18261 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDumpChar_model', @_); | ||
| 18262 | } | ||
| 18263 | |||
| 18264 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18265 | $tab = $self->notebookGetTab(); | ||
| 18266 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18267 | |||
| 18268 | # Unselect everything in the list | ||
| 18269 | $slWidget->get_selection->unselect_all(); | ||
| 18270 | |||
| 18271 | # Display the list | ||
| 18272 | $self->session->pseudoCmd('listplayercharacter -a', $self->pseudoCmdMode); | ||
| 18273 | |||
| 18274 | return 1; | ||
| 18275 | } | ||
| 18276 | |||
| 18277 | sub buttonAdd_exitModel { | ||
| 18278 | |||
| 18279 | # Callback: Adds an exit model object (equivalent to ';addexit') | ||
| 18280 | # | ||
| 18281 | # Expected arguments | ||
| 18282 | # (none besides $self) | ||
| 18283 | # | ||
| 18284 | # Return values | ||
| 18285 | # 'undef' on improper arguments | ||
| 18286 | # 1 otherwise | ||
| 18287 | |||
| 18288 | my ($self, $check) = @_; | ||
| 18289 | |||
| 18290 | # Local variables | ||
| 18291 | my ($tab, $slWidget, $obj, $objName, $objParent, $string); | ||
| 18292 | |||
| 18293 | # Check for improper arguments | ||
| 18294 | if (defined $check) { | ||
| 18295 | |||
| 18296 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_exitModel', @_); | ||
| 18297 | } | ||
| 18298 | |||
| 18299 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18300 | $tab = $self->notebookGetTab(); | ||
| 18301 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18302 | |||
| 18303 | # Unselect everything in the list, because we're creating a new model object | ||
| 18304 | $slWidget->get_selection->unselect_all(); | ||
| 18305 | |||
| 18306 | # Prompt to get a name for the object | ||
| 18307 | ($objName, $objParent) = $self->showDoubleEntryDialogue( | ||
| 18308 | 'Add exit object', | ||
| 18309 | 'Nominal direction', | ||
| 18310 | 'Parent room #', | ||
| 18311 | 32, # Max chars for directions | ||
| 18312 | ); | ||
| 18313 | |||
| 18314 | if ($objName && $objParent) { | ||
| 18315 | |||
| 18316 | if ($objParent) { | ||
| 18317 | $string = $objName . ' ' . $objParent; | ||
| 18318 | } else { | ||
| 18319 | $string = $objName; | ||
| 18320 | } | ||
| 18321 | |||
| 18322 | # Add the new exit model object | ||
| 18323 | $self->session->pseudoCmd('addexit ' . $string, $self->pseudoCmdMode); | ||
| 18324 | |||
| 18325 | # Update the notebook | ||
| 18326 | $self->updateNotebook(); | ||
| 18327 | } | ||
| 18328 | |||
| 18329 | return 1; | ||
| 18330 | } | ||
| 18331 | |||
| 18332 | sub buttonEdit_exitModel { | ||
| 18333 | |||
| 18334 | # Callback: Edits an exit model object (equivalent to ';editexit') | ||
| 18335 | # | ||
| 18336 | # Expected arguments | ||
| 18337 | # (none besides $self) | ||
| 18338 | # | ||
| 18339 | # Return values | ||
| 18340 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 18341 | # object no longer exists | ||
| 18342 | # 1 otherwise | ||
| 18343 | |||
| 18344 | my ($self, $check) = @_; | ||
| 18345 | |||
| 18346 | # Local variables | ||
| 18347 | my ( | ||
| 18348 | $dataRef, $number, $obj, | ||
| 18349 | @list, @dataList, | ||
| 18350 | ); | ||
| 18351 | |||
| 18352 | # Check for improper arguments | ||
| 18353 | if (defined $check) { | ||
| 18354 | |||
| 18355 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_exitModel', @_); | ||
| 18356 | } | ||
| 18357 | |||
| 18358 | # Import the currently selected portions of the notebook list | ||
| 18359 | @list = $self->notebookGetSelectedData(); | ||
| 18360 | if (! @list) { | ||
| 18361 | |||
| 18362 | # Nothing selected | ||
| 18363 | return undef; | ||
| 18364 | } | ||
| 18365 | |||
| 18366 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18367 | # a single row of the list | ||
| 18368 | $dataRef = $list[0]; | ||
| 18369 | @dataList = @$dataRef; | ||
| 18370 | # The exit model object's unique number is the first item of data | ||
| 18371 | $number = $dataList[0]; | ||
| 18372 | if (! $number) { | ||
| 18373 | |||
| 18374 | # Can't continue | ||
| 18375 | return undef; | ||
| 18376 | } | ||
| 18377 | |||
| 18378 | # Get the world model object itself | ||
| 18379 | $obj = $self->session->worldModelObj->ivShow('exitModelHash', $number); | ||
| 18380 | if (! $obj) { | ||
| 18381 | |||
| 18382 | # Can't continue | ||
| 18383 | return undef; | ||
| 18384 | |||
| 18385 | } else { | ||
| 18386 | |||
| 18387 | # Open up an 'edit' window to edit the object | ||
| 18388 | $self->createFreeWin( | ||
| 18389 | 'Games::Axmud::EditWin::Exit', | ||
| 18390 | $self, | ||
| 18391 | $self->session, | ||
| 18392 | 'Edit exit model object #' . $obj->number, | ||
| 18393 | $obj, | ||
| 18394 | FALSE, # Not temporary | ||
| 18395 | ); | ||
| 18396 | } | ||
| 18397 | |||
| 18398 | return 1; | ||
| 18399 | } | ||
| 18400 | |||
| 18401 | sub buttonDelete_exitModel { | ||
| 18402 | |||
| 18403 | # Callback: Deletes an exit model object (equivalent to ';deleteexit') | ||
| 18404 | # | ||
| 18405 | # Expected arguments | ||
| 18406 | # (none besides $self) | ||
| 18407 | # | ||
| 18408 | # Return values | ||
| 18409 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 18410 | # 1 otherwise | ||
| 18411 | |||
| 18412 | my ($self, $check) = @_; | ||
| 18413 | |||
| 18414 | # Local variables | ||
| 18415 | my ( | ||
| 18416 | $dataRef, $number, | ||
| 18417 | @list, @dataList, | ||
| 18418 | ); | ||
| 18419 | |||
| 18420 | # Check for improper arguments | ||
| 18421 | if (defined $check) { | ||
| 18422 | |||
| 18423 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_exitModel', @_); | ||
| 18424 | } | ||
| 18425 | |||
| 18426 | # Import the currently selected portions of the notebook list | ||
| 18427 | @list = $self->notebookGetSelectedData(); | ||
| 18428 | if (! @list) { | ||
| 18429 | |||
| 18430 | # Nothing selected | ||
| 18431 | return undef; | ||
| 18432 | } | ||
| 18433 | |||
| 18434 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18435 | # a single row of the list | ||
| 18436 | $dataRef = $list[0]; | ||
| 18437 | @dataList = @$dataRef; | ||
| 18438 | # The model object number is the first item of data | ||
| 18439 | $number = $dataList[0]; | ||
| 18440 | if (! $number) { | ||
| 18441 | |||
| 18442 | # Can't continue | ||
| 18443 | return undef; | ||
| 18444 | } | ||
| 18445 | |||
| 18446 | # Delete the exit model object | ||
| 18447 | $self->session->pseudoCmd('deleteexit ' . $number, $self->pseudoCmdMode); | ||
| 18448 | |||
| 18449 | # Update the notebook | ||
| 18450 | $self->updateNotebook(); | ||
| 18451 | |||
| 18452 | return 1; | ||
| 18453 | } | ||
| 18454 | |||
| 18455 | sub buttonDump_exitModel { | ||
| 18456 | |||
| 18457 | # Callback: Displays a list of exit model objects in the 'main' window (equivalent to | ||
| 18458 | # ';dumpexitmodel') | ||
| 18459 | # | ||
| 18460 | # Expected arguments | ||
| 18461 | # (none besides $self) | ||
| 18462 | # | ||
| 18463 | # Return values | ||
| 18464 | # 'undef' on improper arguments | ||
| 18465 | # 1 otherwise | ||
| 18466 | |||
| 18467 | my ($self, $check) = @_; | ||
| 18468 | |||
| 18469 | # Local variables | ||
| 18470 | my ($tab, $slWidget); | ||
| 18471 | |||
| 18472 | # Check for improper arguments | ||
| 18473 | if (defined $check) { | ||
| 18474 | |||
| 18475 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_exitModel', @_); | ||
| 18476 | } | ||
| 18477 | |||
| 18478 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18479 | $tab = $self->notebookGetTab(); | ||
| 18480 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18481 | |||
| 18482 | # Unselect everything in the list | ||
| 18483 | $slWidget->get_selection->unselect_all(); | ||
| 18484 | |||
| 18485 | # Display the list | ||
| 18486 | $self->session->pseudoCmd('dumpexitmodel', $self->pseudoCmdMode); | ||
| 18487 | |||
| 18488 | return 1; | ||
| 18489 | } | ||
| 18490 | |||
| 18491 | # Buffer callbacks | ||
| 18492 | |||
| 18493 | sub buttonDump20_displayBuffer { | ||
| 18494 | |||
| 18495 | # Callback: Display a list of the 20 most recent lines from the display buffer in the | ||
| 18496 | # 'main' window (equivalent to ';dumpdisplaybuffer <start> <stop>') | ||
| 18497 | # | ||
| 18498 | # Expected arguments | ||
| 18499 | # (none besides $self) | ||
| 18500 | # | ||
| 18501 | # Return values | ||
| 18502 | # 'undef' on improper arguments | ||
| 18503 | # 1 otherwise | ||
| 18504 | |||
| 18505 | my ($self, $check) = @_; | ||
| 18506 | |||
| 18507 | # Local variables | ||
| 18508 | my ($tab, $slWidget, $start, $stop); | ||
| 18509 | |||
| 18510 | # Check for improper arguments | ||
| 18511 | if (defined $check) { | ||
| 18512 | |||
| 18513 | return $axmud::CLIENT->writeImproper( | ||
| 18514 | $self->_objClass . '->buttonDump20_displayBuffer', | ||
| 18515 | @_, | ||
| 18516 | ); | ||
| 18517 | } | ||
| 18518 | |||
| 18519 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18520 | $tab = $self->notebookGetTab(); | ||
| 18521 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18522 | |||
| 18523 | # Unselect everything in the list | ||
| 18524 | $slWidget->get_selection->unselect_all(); | ||
| 18525 | |||
| 18526 | # Don't do anything if no lines have been received | ||
| 18527 | if ($self->session->displayBufferFirst) { | ||
| 18528 | |||
| 18529 | # Work out the line numbers | ||
| 18530 | $stop = $self->session->displayBufferLast; | ||
| 18531 | $start = $self->session->displayBufferLast - 19; | ||
| 18532 | if ($start < 1) { | ||
| 18533 | |||
| 18534 | $start = 1; | ||
| 18535 | } | ||
| 18536 | |||
| 18537 | # Display the lines | ||
| 18538 | $self->session->pseudoCmd( | ||
| 18539 | 'dumpdisplaybuffer ' . $start . ' ' . $stop, | ||
| 18540 | $self->pseudoCmdMode, | ||
| 18541 | ); | ||
| 18542 | } | ||
| 18543 | |||
| 18544 | return 1; | ||
| 18545 | } | ||
| 18546 | |||
| 18547 | sub buttonDumpAll_displayBuffer { | ||
| 18548 | |||
| 18549 | # Callback: Display a list of all lines from the display buffer in the 'main' window | ||
| 18550 | # (equivalent to ';dumpdisplaybuffer <first line> <last line>') | ||
| 18551 | # | ||
| 18552 | # Expected arguments | ||
| 18553 | # (none besides $self) | ||
| 18554 | # | ||
| 18555 | # Return values | ||
| 18556 | # 'undef' on improper arguments | ||
| 18557 | # 1 otherwise | ||
| 18558 | |||
| 18559 | my ($self, $check) = @_; | ||
| 18560 | |||
| 18561 | # Local variables | ||
| 18562 | my ($tab, $slWidget, $start, $stop); | ||
| 18563 | |||
| 18564 | # Check for improper arguments | ||
| 18565 | if (defined $check) { | ||
| 18566 | |||
| 18567 | return $axmud::CLIENT->writeImproper( | ||
| 18568 | $self->_objClass . '->buttonDumpAll_displayBuffer', | ||
| 18569 | @_, | ||
| 18570 | ); | ||
| 18571 | } | ||
| 18572 | |||
| 18573 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18574 | $tab = $self->notebookGetTab(); | ||
| 18575 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18576 | |||
| 18577 | # Unselect everything in the list | ||
| 18578 | $slWidget->get_selection->unselect_all(); | ||
| 18579 | |||
| 18580 | # Don't do anything if no lines have been received | ||
| 18581 | if ($self->session->displayBufferFirst) { | ||
| 18582 | |||
| 18583 | # Work out the line numbers | ||
| 18584 | $stop = $self->session->displayBufferLast; | ||
| 18585 | $start = $self->session->displayBufferFirst; | ||
| 18586 | |||
| 18587 | # Display the lines | ||
| 18588 | $self->session->pseudoCmd( | ||
| 18589 | 'dumpdisplaybuffer ' . $start . ' ' . $stop, | ||
| 18590 | $self->pseudoCmdMode, | ||
| 18591 | ); | ||
| 18592 | } | ||
| 18593 | |||
| 18594 | return 1; | ||
| 18595 | } | ||
| 18596 | |||
| 18597 | sub buttonStatus_displayBuffer { | ||
| 18598 | |||
| 18599 | # Callback: Display the display buffer's status in the 'main' window (equivalent to | ||
| 18600 | # ';displaybuffer') | ||
| 18601 | # | ||
| 18602 | # Expected arguments | ||
| 18603 | # (none besides $self) | ||
| 18604 | # | ||
| 18605 | # Return values | ||
| 18606 | # 'undef' on improper arguments | ||
| 18607 | # 1 otherwise | ||
| 18608 | |||
| 18609 | my ($self, $check) = @_; | ||
| 18610 | |||
| 18611 | # Local variables | ||
| 18612 | my ($tab, $slWidget, $start, $stop); | ||
| 18613 | |||
| 18614 | # Check for improper arguments | ||
| 18615 | if (defined $check) { | ||
| 18616 | |||
| 18617 | return $axmud::CLIENT->writeImproper( | ||
| 18618 | $self->_objClass . '->buttonStatus_displayBuffer', | ||
| 18619 | @_, | ||
| 18620 | ); | ||
| 18621 | } | ||
| 18622 | |||
| 18623 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18624 | $tab = $self->notebookGetTab(); | ||
| 18625 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18626 | |||
| 18627 | # Unselect everything in the list | ||
| 18628 | $slWidget->get_selection->unselect_all(); | ||
| 18629 | |||
| 18630 | # Display the display buffer status | ||
| 18631 | $self->session->pseudoCmd('displaybuffer', $self->pseudoCmdMode); | ||
| 18632 | |||
| 18633 | return 1; | ||
| 18634 | } | ||
| 18635 | |||
| 18636 | sub buttonView_displayBuffer { | ||
| 18637 | |||
| 18638 | # Callback: Views the selected display buffer line in an 'edit' window (equivalent to | ||
| 18639 | # ';editdisplaybuffer') | ||
| 18640 | # | ||
| 18641 | # Expected arguments | ||
| 18642 | # (none besides $self) | ||
| 18643 | # | ||
| 18644 | # Return values | ||
| 18645 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 18646 | # object no longer exists | ||
| 18647 | # 1 otherwise | ||
| 18648 | |||
| 18649 | my ($self, $check) = @_; | ||
| 18650 | |||
| 18651 | # Local variables | ||
| 18652 | my ( | ||
| 18653 | $dataRef, $number, $obj, | ||
| 18654 | @list, @dataList, | ||
| 18655 | ); | ||
| 18656 | |||
| 18657 | # Check for improper arguments | ||
| 18658 | if (defined $check) { | ||
| 18659 | |||
| 18660 | return $axmud::CLIENT->writeImproper( | ||
| 18661 | $self->_objClass . '->buttonView_displayBuffer', | ||
| 18662 | @_, | ||
| 18663 | ); | ||
| 18664 | } | ||
| 18665 | |||
| 18666 | # Import the currently selected portions of the notebook list | ||
| 18667 | @list = $self->notebookGetSelectedData(); | ||
| 18668 | if (! @list) { | ||
| 18669 | |||
| 18670 | # Nothing selected | ||
| 18671 | return undef; | ||
| 18672 | } | ||
| 18673 | |||
| 18674 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18675 | # a single row of the list | ||
| 18676 | $dataRef = $list[0]; | ||
| 18677 | @dataList = @$dataRef; | ||
| 18678 | # The line number is the first item of data | ||
| 18679 | $number = $dataList[0]; | ||
| 18680 | if (! defined $number) { | ||
| 18681 | |||
| 18682 | # Can't continue | ||
| 18683 | return undef; | ||
| 18684 | } | ||
| 18685 | |||
| 18686 | # Get the corresponding display buffer object | ||
| 18687 | $obj = $self->session->ivShow('displayBufferHash', $number); | ||
| 18688 | if (! $obj) { | ||
| 18689 | |||
| 18690 | # Can't continue | ||
| 18691 | return undef; | ||
| 18692 | |||
| 18693 | } else { | ||
| 18694 | |||
| 18695 | # Open up an 'edit' window to edit the object | ||
| 18696 | $self->createFreeWin( | ||
| 18697 | 'Games::Axmud::EditWin::Buffer::Display', | ||
| 18698 | $self, | ||
| 18699 | $self->session, | ||
| 18700 | 'Edit display buffer line #' . $number, | ||
| 18701 | $obj, | ||
| 18702 | FALSE, # Not temporary | ||
| 18703 | ); | ||
| 18704 | } | ||
| 18705 | |||
| 18706 | return 1; | ||
| 18707 | } | ||
| 18708 | |||
| 18709 | sub buttonTest_displayBuffer { | ||
| 18710 | |||
| 18711 | # Callback: Tets the selected display buffer line against a pattern supplied by the user in | ||
| 18712 | # a 'dialogue' window (no corresponding client command) | ||
| 18713 | # | ||
| 18714 | # Expected arguments | ||
| 18715 | # (none besides $self) | ||
| 18716 | # | ||
| 18717 | # Return values | ||
| 18718 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 18719 | # object no longer exists | ||
| 18720 | # 1 otherwise | ||
| 18721 | |||
| 18722 | my ($self, $check) = @_; | ||
| 18723 | |||
| 18724 | # Local variables | ||
| 18725 | my ( | ||
| 18726 | $dataRef, $number, $obj, $pattern, $msg, $type, | ||
| 18727 | @list, @dataList, | ||
| 18728 | ); | ||
| 18729 | |||
| 18730 | # Check for improper arguments | ||
| 18731 | if (defined $check) { | ||
| 18732 | |||
| 18733 | return $axmud::CLIENT->writeImproper( | ||
| 18734 | $self->_objClass . '->buttonTest_displayBuffer', | ||
| 18735 | @_, | ||
| 18736 | ); | ||
| 18737 | } | ||
| 18738 | |||
| 18739 | # Import the currently selected portions of the notebook list | ||
| 18740 | @list = $self->notebookGetSelectedData(); | ||
| 18741 | if (! @list) { | ||
| 18742 | |||
| 18743 | # Nothing selected | ||
| 18744 | return undef; | ||
| 18745 | } | ||
| 18746 | |||
| 18747 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 18748 | # a single row of the list | ||
| 18749 | $dataRef = $list[0]; | ||
| 18750 | @dataList = @$dataRef; | ||
| 18751 | # The line number is the first item of data | ||
| 18752 | $number = $dataList[0]; | ||
| 18753 | if (! defined $number) { | ||
| 18754 | |||
| 18755 | # Can't continue | ||
| 18756 | return undef; | ||
| 18757 | } | ||
| 18758 | |||
| 18759 | # Get the corresponding display buffer object | ||
| 18760 | $obj = $self->session->ivShow('displayBufferHash', $number); | ||
| 18761 | if (! $obj) { | ||
| 18762 | |||
| 18763 | # Can't continue | ||
| 18764 | return undef; | ||
| 18765 | } | ||
| 18766 | |||
| 18767 | # Prompt the user for a regex | ||
| 18768 | $pattern = $self->showEntryDialogue( | ||
| 18769 | 'Test original line', | ||
| 18770 | 'Enter a pattern (regex) to test against line #' . $number, | ||
| 18771 | ); | ||
| 18772 | |||
| 18773 | if ($pattern) { | ||
| 18774 | |||
| 18775 | if ($axmud::CLIENT->regexCheck($pattern)) { | ||
| 18776 | |||
| 18777 | $msg = 'Invalid pattern (regular expression)'; | ||
| 18778 | $type = 'error'; | ||
| 18779 | |||
| 18780 | } elsif ($obj->stripLine =~ m/$pattern/) { | ||
| 18781 | |||
| 18782 | $msg = 'Pattern MATCHES line #' . $number; | ||
| 18783 | $type = 'info'; | ||
| 18784 | |||
| 18785 | } else { | ||
| 18786 | |||
| 18787 | $msg = 'Pattern does NOT match line #' . $number; | ||
| 18788 | $type = 'error'; | ||
| 18789 | } | ||
| 18790 | |||
| 18791 | # Display the result | ||
| 18792 | $self->showMsgDialogue( | ||
| 18793 | 'Test result', | ||
| 18794 | $type, | ||
| 18795 | $msg, | ||
| 18796 | 'ok', | ||
| 18797 | ); | ||
| 18798 | } | ||
| 18799 | |||
| 18800 | return 1; | ||
| 18801 | } | ||
| 18802 | |||
| 18803 | sub buttonSave_displayBuffer { | ||
| 18804 | |||
| 18805 | # Callback: Saves the display buffer to file (equivalent to ';savebuffer -t') | ||
| 18806 | # | ||
| 18807 | # Expected arguments | ||
| 18808 | # (none besides $self) | ||
| 18809 | # | ||
| 18810 | # Return values | ||
| 18811 | # 'undef' on improper arguments | ||
| 18812 | # 1 otherwise | ||
| 18813 | |||
| 18814 | my ($self, $check) = @_; | ||
| 18815 | |||
| 18816 | # Local variables | ||
| 18817 | my ($tab, $slWidget, $start, $stop); | ||
| 18818 | |||
| 18819 | # Check for improper arguments | ||
| 18820 | if (defined $check) { | ||
| 18821 | |||
| 18822 | return $axmud::CLIENT->writeImproper( | ||
| 18823 | $self->_objClass . '->buttonSave_displayBuffer', | ||
| 18824 | @_, | ||
| 18825 | ); | ||
| 18826 | } | ||
| 18827 | |||
| 18828 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18829 | $tab = $self->notebookGetTab(); | ||
| 18830 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18831 | |||
| 18832 | # Unselect everything in the list | ||
| 18833 | $slWidget->get_selection->unselect_all(); | ||
| 18834 | |||
| 18835 | # Save the display buffer to file | ||
| 18836 | $self->session->pseudoCmd('savebuffer -d', $self->pseudoCmdMode); | ||
| 18837 | |||
| 18838 | return 1; | ||
| 18839 | } | ||
| 18840 | |||
| 18841 | sub buttonSaveBoth_displayBuffer { | ||
| 18842 | |||
| 18843 | # Callback: Saves the text and command buffers to file (equivalent to ';savebuffer') | ||
| 18844 | # | ||
| 18845 | # Expected arguments | ||
| 18846 | # (none besides $self) | ||
| 18847 | # | ||
| 18848 | # Return values | ||
| 18849 | # 'undef' on improper arguments | ||
| 18850 | # 1 otherwise | ||
| 18851 | |||
| 18852 | my ($self, $check) = @_; | ||
| 18853 | |||
| 18854 | # Local variables | ||
| 18855 | my ($tab, $slWidget, $start, $stop); | ||
| 18856 | |||
| 18857 | # Check for improper arguments | ||
| 18858 | if (defined $check) { | ||
| 18859 | |||
| 18860 | return $axmud::CLIENT->writeImproper( | ||
| 18861 | $self->_objClass . '->buttonSaveBoth_displayBuffer', | ||
| 18862 | @_, | ||
| 18863 | ); | ||
| 18864 | } | ||
| 18865 | |||
| 18866 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18867 | $tab = $self->notebookGetTab(); | ||
| 18868 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18869 | |||
| 18870 | # Unselect everything in the list | ||
| 18871 | $slWidget->get_selection->unselect_all(); | ||
| 18872 | |||
| 18873 | # Save the text and command buffers to file | ||
| 18874 | $self->session->pseudoCmd('savebuffer', $self->pseudoCmdMode); | ||
| 18875 | |||
| 18876 | return 1; | ||
| 18877 | } | ||
| 18878 | |||
| 18879 | sub buttonDump20_instructBuffer { | ||
| 18880 | |||
| 18881 | # Callback: Display a list of the 20 most recent lines from the instruction buffer in the | ||
| 18882 | # 'main' window (equivalent to ';dumpinstructionbuffer <start> <stop>') | ||
| 18883 | # | ||
| 18884 | # Expected arguments | ||
| 18885 | # (none besides $self) | ||
| 18886 | # | ||
| 18887 | # Return values | ||
| 18888 | # 'undef' on improper arguments | ||
| 18889 | # 1 otherwise | ||
| 18890 | |||
| 18891 | my ($self, $check) = @_; | ||
| 18892 | |||
| 18893 | # Local variables | ||
| 18894 | my ($tab, $slWidget, $start, $stop); | ||
| 18895 | |||
| 18896 | # Check for improper arguments | ||
| 18897 | if (defined $check) { | ||
| 18898 | |||
| 18899 | return $axmud::CLIENT->writeImproper( | ||
| 18900 | $self->_objClass . '->buttonDump20_instructBuffer', | ||
| 18901 | @_, | ||
| 18902 | ); | ||
| 18903 | } | ||
| 18904 | |||
| 18905 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18906 | $tab = $self->notebookGetTab(); | ||
| 18907 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18908 | |||
| 18909 | # Unselect everything in the list | ||
| 18910 | $slWidget->get_selection->unselect_all(); | ||
| 18911 | |||
| 18912 | # Don't do anything if no lines have been received | ||
| 18913 | if ($self->session->instructBufferFirst) { | ||
| 18914 | |||
| 18915 | # Work out the line numbers | ||
| 18916 | $stop = $self->session->instructBufferLast; | ||
| 18917 | $start = $self->session->instructBufferLast - 19; | ||
| 18918 | if ($start < 1) { | ||
| 18919 | |||
| 18920 | $start = 1; | ||
| 18921 | } | ||
| 18922 | |||
| 18923 | # Display the lines | ||
| 18924 | $self->session->pseudoCmd( | ||
| 18925 | 'dumpinstructionbuffer ' . $start . ' ' . $stop, | ||
| 18926 | $self->pseudoCmdMode, | ||
| 18927 | ); | ||
| 18928 | } | ||
| 18929 | |||
| 18930 | return 1; | ||
| 18931 | } | ||
| 18932 | |||
| 18933 | sub buttonDumpAll_instructBuffer { | ||
| 18934 | |||
| 18935 | # Callback: Display a list of all lines from the instruction buffer in the 'main' window | ||
| 18936 | # (equivalent to ';dumpcommandbuffer <first line> <last line>') | ||
| 18937 | # | ||
| 18938 | # Expected arguments | ||
| 18939 | # (none besides $self) | ||
| 18940 | # | ||
| 18941 | # Return values | ||
| 18942 | # 'undef' on improper arguments | ||
| 18943 | # 1 otherwise | ||
| 18944 | |||
| 18945 | my ($self, $check) = @_; | ||
| 18946 | |||
| 18947 | # Local variables | ||
| 18948 | my ($tab, $slWidget, $start, $stop); | ||
| 18949 | |||
| 18950 | # Check for improper arguments | ||
| 18951 | if (defined $check) { | ||
| 18952 | |||
| 18953 | return $axmud::CLIENT->writeImproper( | ||
| 18954 | $self->_objClass . '->buttonDumpAll_instructBuffer', | ||
| 18955 | @_, | ||
| 18956 | ); | ||
| 18957 | } | ||
| 18958 | |||
| 18959 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 18960 | $tab = $self->notebookGetTab(); | ||
| 18961 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 18962 | |||
| 18963 | # Unselect everything in the list | ||
| 18964 | $slWidget->get_selection->unselect_all(); | ||
| 18965 | |||
| 18966 | # Don't do anything if no lines have been received | ||
| 18967 | if ($self->session->instructBufferFirst) { | ||
| 18968 | |||
| 18969 | # Work out the line numbers | ||
| 18970 | $stop = $self->session->instructBufferLast; | ||
| 18971 | $start = $self->session->instructBufferFirst; | ||
| 18972 | |||
| 18973 | # Display the lines | ||
| 18974 | $self->session->pseudoCmd( | ||
| 18975 | 'dumpinstructionbuffer ' . $start . ' ' . $stop, | ||
| 18976 | $self->pseudoCmdMode, | ||
| 18977 | ); | ||
| 18978 | } | ||
| 18979 | |||
| 18980 | return 1; | ||
| 18981 | } | ||
| 18982 | |||
| 18983 | sub buttonStatus_instructBuffer { | ||
| 18984 | |||
| 18985 | # Callback: Display the instruction buffer's status in the 'main' window (equivalent to | ||
| 18986 | # ';cmdbuffer') | ||
| 18987 | # | ||
| 18988 | # Expected arguments | ||
| 18989 | # (none besides $self) | ||
| 18990 | # | ||
| 18991 | # Return values | ||
| 18992 | # 'undef' on improper arguments | ||
| 18993 | # 1 otherwise | ||
| 18994 | |||
| 18995 | my ($self, $check) = @_; | ||
| 18996 | |||
| 18997 | # Local variables | ||
| 18998 | my ($tab, $slWidget, $start, $stop); | ||
| 18999 | |||
| 19000 | # Check for improper arguments | ||
| 19001 | if (defined $check) { | ||
| 19002 | |||
| 19003 | return $axmud::CLIENT->writeImproper( | ||
| 19004 | $self->_objClass . '->buttonStatus_instructBuffer', | ||
| 19005 | @_, | ||
| 19006 | ); | ||
| 19007 | } | ||
| 19008 | |||
| 19009 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19010 | $tab = $self->notebookGetTab(); | ||
| 19011 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19012 | |||
| 19013 | # Unselect everything in the list | ||
| 19014 | $slWidget->get_selection->unselect_all(); | ||
| 19015 | |||
| 19016 | # Display the instruction buffer status | ||
| 19017 | $self->session->pseudoCmd('instructionbuffer', $self->pseudoCmdMode); | ||
| 19018 | |||
| 19019 | return 1; | ||
| 19020 | } | ||
| 19021 | |||
| 19022 | sub buttonView_instructBuffer { | ||
| 19023 | |||
| 19024 | # Callback: Views the selected intruction buffer line in an 'edit' window (equivalent to | ||
| 19025 | # ';editinstructionbuffer') | ||
| 19026 | # | ||
| 19027 | # Expected arguments | ||
| 19028 | # (none besides $self) | ||
| 19029 | # | ||
| 19030 | # Return values | ||
| 19031 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 19032 | # object no longer exists | ||
| 19033 | # 1 otherwise | ||
| 19034 | |||
| 19035 | my ($self, $check) = @_; | ||
| 19036 | |||
| 19037 | # Local variables | ||
| 19038 | my ( | ||
| 19039 | $dataRef, $number, $obj, | ||
| 19040 | @list, @dataList, | ||
| 19041 | ); | ||
| 19042 | |||
| 19043 | # Check for improper arguments | ||
| 19044 | if (defined $check) { | ||
| 19045 | |||
| 19046 | return $axmud::CLIENT->writeImproper( | ||
| 19047 | $self->_objClass . '->buttonView_instructBuffer', | ||
| 19048 | @_, | ||
| 19049 | ); | ||
| 19050 | } | ||
| 19051 | |||
| 19052 | # Import the currently selected portions of the notebook list | ||
| 19053 | @list = $self->notebookGetSelectedData(); | ||
| 19054 | if (! @list) { | ||
| 19055 | |||
| 19056 | # Nothing selected | ||
| 19057 | return undef; | ||
| 19058 | } | ||
| 19059 | |||
| 19060 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19061 | # a single row of the list | ||
| 19062 | $dataRef = $list[0]; | ||
| 19063 | @dataList = @$dataRef; | ||
| 19064 | # The line number is the first item of data | ||
| 19065 | $number = $dataList[0]; | ||
| 19066 | if (! defined $number) { | ||
| 19067 | |||
| 19068 | # Can't continue | ||
| 19069 | return undef; | ||
| 19070 | } | ||
| 19071 | |||
| 19072 | # Get the corresponding instruction buffer object | ||
| 19073 | $obj = $self->session->ivShow('instructBufferHash', $number); | ||
| 19074 | if (! $obj) { | ||
| 19075 | |||
| 19076 | # Can't continue | ||
| 19077 | return undef; | ||
| 19078 | |||
| 19079 | } else { | ||
| 19080 | |||
| 19081 | # Open up an 'edit' window to view the object | ||
| 19082 | $self->createFreeWin( | ||
| 19083 | 'Games::Axmud::EditWin::Buffer::Instruct', | ||
| 19084 | $self, | ||
| 19085 | $self->session, | ||
| 19086 | 'Edit instruction buffer item #' . $number, | ||
| 19087 | $obj, | ||
| 19088 | FALSE, # Not temporary | ||
| 19089 | ); | ||
| 19090 | } | ||
| 19091 | |||
| 19092 | return 1; | ||
| 19093 | } | ||
| 19094 | |||
| 19095 | sub buttonDump20_cmdBuffer { | ||
| 19096 | |||
| 19097 | # Callback: Display a list of the 20 most recent lines from the command buffer in the | ||
| 19098 | # 'main' window (equivalent to ';dumpcommandbuffer <start> <stop>') | ||
| 19099 | # | ||
| 19100 | # Expected arguments | ||
| 19101 | # (none besides $self) | ||
| 19102 | # | ||
| 19103 | # Return values | ||
| 19104 | # 'undef' on improper arguments | ||
| 19105 | # 1 otherwise | ||
| 19106 | |||
| 19107 | my ($self, $check) = @_; | ||
| 19108 | |||
| 19109 | # Local variables | ||
| 19110 | my ($tab, $slWidget, $start, $stop); | ||
| 19111 | |||
| 19112 | # Check for improper arguments | ||
| 19113 | if (defined $check) { | ||
| 19114 | |||
| 19115 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump20_cmdBuffer', @_); | ||
| 19116 | } | ||
| 19117 | |||
| 19118 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19119 | $tab = $self->notebookGetTab(); | ||
| 19120 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19121 | |||
| 19122 | # Unselect everything in the list | ||
| 19123 | $slWidget->get_selection->unselect_all(); | ||
| 19124 | |||
| 19125 | # Don't do anything if no lines have been received | ||
| 19126 | if ($self->session->cmdBufferFirst) { | ||
| 19127 | |||
| 19128 | # Work out the line numbers | ||
| 19129 | $stop = $self->session->cmdBufferLast; | ||
| 19130 | $start = $self->session->cmdBufferLast - 19; | ||
| 19131 | if ($start < 1) { | ||
| 19132 | |||
| 19133 | $start = 1; | ||
| 19134 | } | ||
| 19135 | |||
| 19136 | # Display the lines | ||
| 19137 | $self->session->pseudoCmd( | ||
| 19138 | 'dumpcommandbuffer ' . $start . ' ' . $stop, | ||
| 19139 | $self->pseudoCmdMode, | ||
| 19140 | ); | ||
| 19141 | } | ||
| 19142 | |||
| 19143 | return 1; | ||
| 19144 | } | ||
| 19145 | |||
| 19146 | sub buttonDumpAll_cmdBuffer { | ||
| 19147 | |||
| 19148 | # Callback: Display a list of all lines from the command buffer in the 'main' window | ||
| 19149 | # (equivalent to ';dumpcommandbuffer <first line> <last line>') | ||
| 19150 | # | ||
| 19151 | # Expected arguments | ||
| 19152 | # (none besides $self) | ||
| 19153 | # | ||
| 19154 | # Return values | ||
| 19155 | # 'undef' on improper arguments | ||
| 19156 | # 1 otherwise | ||
| 19157 | |||
| 19158 | my ($self, $check) = @_; | ||
| 19159 | |||
| 19160 | # Local variables | ||
| 19161 | my ($tab, $slWidget, $start, $stop); | ||
| 19162 | |||
| 19163 | # Check for improper arguments | ||
| 19164 | if (defined $check) { | ||
| 19165 | |||
| 19166 | return $axmud::CLIENT->writeImproper( | ||
| 19167 | $self->_objClass . '->buttonDumpAll_cmdBuffer', | ||
| 19168 | @_, | ||
| 19169 | ); | ||
| 19170 | } | ||
| 19171 | |||
| 19172 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19173 | $tab = $self->notebookGetTab(); | ||
| 19174 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19175 | |||
| 19176 | # Unselect everything in the list | ||
| 19177 | $slWidget->get_selection->unselect_all(); | ||
| 19178 | |||
| 19179 | # Don't do anything if no lines have been received | ||
| 19180 | if ($self->session->cmdBufferFirst) { | ||
| 19181 | |||
| 19182 | # Work out the line numbers | ||
| 19183 | $stop = $self->session->cmdBufferLast; | ||
| 19184 | $start = $self->session->cmdBufferFirst; | ||
| 19185 | |||
| 19186 | # Display the lines | ||
| 19187 | $self->session->pseudoCmd( | ||
| 19188 | 'dumpcommandbuffer ' . $start . ' ' . $stop, | ||
| 19189 | $self->pseudoCmdMode, | ||
| 19190 | ); | ||
| 19191 | } | ||
| 19192 | |||
| 19193 | return 1; | ||
| 19194 | } | ||
| 19195 | |||
| 19196 | sub buttonStatus_cmdBuffer { | ||
| 19197 | |||
| 19198 | # Callback: Display the command buffer's status in the 'main' window (equivalent to | ||
| 19199 | # ';cmdbuffer') | ||
| 19200 | # | ||
| 19201 | # Expected arguments | ||
| 19202 | # (none besides $self) | ||
| 19203 | # | ||
| 19204 | # Return values | ||
| 19205 | # 'undef' on improper arguments | ||
| 19206 | # 1 otherwise | ||
| 19207 | |||
| 19208 | my ($self, $check) = @_; | ||
| 19209 | |||
| 19210 | # Local variables | ||
| 19211 | my ($tab, $slWidget, $start, $stop); | ||
| 19212 | |||
| 19213 | # Check for improper arguments | ||
| 19214 | if (defined $check) { | ||
| 19215 | |||
| 19216 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonStatus_cmdBuffer', @_); | ||
| 19217 | } | ||
| 19218 | |||
| 19219 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19220 | $tab = $self->notebookGetTab(); | ||
| 19221 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19222 | |||
| 19223 | # Unselect everything in the list | ||
| 19224 | $slWidget->get_selection->unselect_all(); | ||
| 19225 | |||
| 19226 | # Display the command buffer status | ||
| 19227 | $self->session->pseudoCmd('commandbuffer', $self->pseudoCmdMode); | ||
| 19228 | |||
| 19229 | return 1; | ||
| 19230 | } | ||
| 19231 | |||
| 19232 | sub buttonView_cmdBuffer { | ||
| 19233 | |||
| 19234 | # Callback: Views the selected command buffer line in an 'edit' window (equivalent to | ||
| 19235 | # ';editcommandbuffer') | ||
| 19236 | # | ||
| 19237 | # Expected arguments | ||
| 19238 | # (none besides $self) | ||
| 19239 | # | ||
| 19240 | # Return values | ||
| 19241 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 19242 | # object no longer exists | ||
| 19243 | # 1 otherwise | ||
| 19244 | |||
| 19245 | my ($self, $check) = @_; | ||
| 19246 | |||
| 19247 | # Local variables | ||
| 19248 | my ( | ||
| 19249 | $dataRef, $number, $obj, | ||
| 19250 | @list, @dataList, | ||
| 19251 | ); | ||
| 19252 | |||
| 19253 | # Check for improper arguments | ||
| 19254 | if (defined $check) { | ||
| 19255 | |||
| 19256 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonView_cmdBuffer', @_); | ||
| 19257 | } | ||
| 19258 | |||
| 19259 | # Import the currently selected portions of the notebook list | ||
| 19260 | @list = $self->notebookGetSelectedData(); | ||
| 19261 | if (! @list) { | ||
| 19262 | |||
| 19263 | # Nothing selected | ||
| 19264 | return undef; | ||
| 19265 | } | ||
| 19266 | |||
| 19267 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19268 | # a single row of the list | ||
| 19269 | $dataRef = $list[0]; | ||
| 19270 | @dataList = @$dataRef; | ||
| 19271 | # The line number is the first item of data | ||
| 19272 | $number = $dataList[0]; | ||
| 19273 | if (! defined $number) { | ||
| 19274 | |||
| 19275 | # Can't continue | ||
| 19276 | return undef; | ||
| 19277 | } | ||
| 19278 | |||
| 19279 | # Get the corresponding command buffer object | ||
| 19280 | $obj = $self->session->ivShow('cmdBufferHash', $number); | ||
| 19281 | if (! $obj) { | ||
| 19282 | |||
| 19283 | # Can't continue | ||
| 19284 | return undef; | ||
| 19285 | |||
| 19286 | } else { | ||
| 19287 | |||
| 19288 | # Open up an 'edit' window to view the object | ||
| 19289 | $self->createFreeWin( | ||
| 19290 | 'Games::Axmud::EditWin::Buffer::Cmd', | ||
| 19291 | $self, | ||
| 19292 | $self->session, | ||
| 19293 | 'Edit world command buffer item #' . $number, | ||
| 19294 | $obj, | ||
| 19295 | FALSE, # Not temporary | ||
| 19296 | ); | ||
| 19297 | } | ||
| 19298 | |||
| 19299 | return 1; | ||
| 19300 | } | ||
| 19301 | |||
| 19302 | sub buttonSave_cmdBuffer { | ||
| 19303 | |||
| 19304 | # Callback: Saves the command buffer to file (equivalent to ';savebuffer -c') | ||
| 19305 | # | ||
| 19306 | # Expected arguments | ||
| 19307 | # (none besides $self) | ||
| 19308 | # | ||
| 19309 | # Return values | ||
| 19310 | # 'undef' on improper arguments | ||
| 19311 | # 1 otherwise | ||
| 19312 | |||
| 19313 | my ($self, $check) = @_; | ||
| 19314 | |||
| 19315 | # Local variables | ||
| 19316 | my ($tab, $slWidget, $start, $stop); | ||
| 19317 | |||
| 19318 | # Check for improper arguments | ||
| 19319 | if (defined $check) { | ||
| 19320 | |||
| 19321 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonSave_cmdBuffer', @_); | ||
| 19322 | } | ||
| 19323 | |||
| 19324 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19325 | $tab = $self->notebookGetTab(); | ||
| 19326 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19327 | |||
| 19328 | # Unselect everything in the list | ||
| 19329 | $slWidget->get_selection->unselect_all(); | ||
| 19330 | |||
| 19331 | # Save the command buffer to file | ||
| 19332 | $self->session->pseudoCmd('savebuffer -c', $self->pseudoCmdMode); | ||
| 19333 | |||
| 19334 | return 1; | ||
| 19335 | } | ||
| 19336 | |||
| 19337 | # Chat contact button callbacks | ||
| 19338 | |||
| 19339 | sub buttonAdd_chatContact { | ||
| 19340 | |||
| 19341 | # Callback: Add a chat contact object (equivalent to ';addcontact') | ||
| 19342 | # | ||
| 19343 | # Expected arguments | ||
| 19344 | # (none besides $self) | ||
| 19345 | # | ||
| 19346 | # Return values | ||
| 19347 | # 'undef' on improper arguments | ||
| 19348 | # 1 otherwise | ||
| 19349 | |||
| 19350 | my ($self, $check) = @_; | ||
| 19351 | |||
| 19352 | # Local variables | ||
| 19353 | my ($tab, $slWidget, $name, $ip); | ||
| 19354 | |||
| 19355 | # Check for improper arguments | ||
| 19356 | if (defined $check) { | ||
| 19357 | |||
| 19358 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_chatContact', @_); | ||
| 19359 | } | ||
| 19360 | |||
| 19361 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19362 | $tab = $self->notebookGetTab(); | ||
| 19363 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19364 | |||
| 19365 | # Unselect everything in the list, because we're creating a new chat contact | ||
| 19366 | $slWidget->get_selection->unselect_all(); | ||
| 19367 | |||
| 19368 | # Prompt the user for the name of the chat contact object | ||
| 19369 | ($name, $ip) = $self->showDoubleEntryDialogue( | ||
| 19370 | 'Add chat contact', | ||
| 19371 | "Enter a name for the object\n<i>Max 16 chars: A-Z a-z _ 0-9</i>", | ||
| 19372 | "Enter the contact's IP address\n<i>e.g. 100.101.102.103</i>", | ||
| 19373 | 16, # Max chars | ||
| 19374 | ); | ||
| 19375 | |||
| 19376 | if ($name && $ip) { | ||
| 19377 | |||
| 19378 | # Add the new chat contact | ||
| 19379 | $self->session->pseudoCmd('addcontact ' . $name . ' ' . $ip, $self->pseudoCmdMode); | ||
| 19380 | |||
| 19381 | # Update the notebook | ||
| 19382 | $self->updateNotebook(); | ||
| 19383 | } | ||
| 19384 | |||
| 19385 | return 1; | ||
| 19386 | } | ||
| 19387 | |||
| 19388 | sub buttonEdit_chatContact { | ||
| 19389 | |||
| 19390 | # Callback: Edits a chat contact object (equivalent to ';editcontact') | ||
| 19391 | # | ||
| 19392 | # Expected arguments | ||
| 19393 | # (none besides $self) | ||
| 19394 | # | ||
| 19395 | # Return values | ||
| 19396 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 19397 | # object no longer exists | ||
| 19398 | # 1 otherwise | ||
| 19399 | |||
| 19400 | my ($self, $check) = @_; | ||
| 19401 | |||
| 19402 | # Local variables | ||
| 19403 | my ( | ||
| 19404 | $dataRef, $name, $obj, | ||
| 19405 | @list, @dataList, | ||
| 19406 | ); | ||
| 19407 | |||
| 19408 | # Check for improper arguments | ||
| 19409 | if (defined $check) { | ||
| 19410 | |||
| 19411 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_chatContact', @_); | ||
| 19412 | } | ||
| 19413 | |||
| 19414 | # Import the currently selected portions of the notebook list | ||
| 19415 | @list = $self->notebookGetSelectedData(); | ||
| 19416 | if (! @list) { | ||
| 19417 | |||
| 19418 | # Nothing selected | ||
| 19419 | return undef; | ||
| 19420 | } | ||
| 19421 | |||
| 19422 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19423 | # a single row of the list | ||
| 19424 | $dataRef = $list[0]; | ||
| 19425 | @dataList = @$dataRef; | ||
| 19426 | # The colour scheme's name is the first item of data | ||
| 19427 | $name = $dataList[0]; | ||
| 19428 | if (! $name) { | ||
| 19429 | |||
| 19430 | # Can't continue | ||
| 19431 | return undef; | ||
| 19432 | } | ||
| 19433 | |||
| 19434 | # Get the chat contact itself | ||
| 19435 | $obj = $axmud::CLIENT->ivShow('chatContactHash', $name); | ||
| 19436 | if (! $obj) { | ||
| 19437 | |||
| 19438 | # Can't continue | ||
| 19439 | return undef; | ||
| 19440 | |||
| 19441 | } else { | ||
| 19442 | |||
| 19443 | # Open up an 'edit' window to edit the object | ||
| 19444 | $self->createFreeWin( | ||
| 19445 | 'Games::Axmud::EditWin::ChatContact', | ||
| 19446 | $self, | ||
| 19447 | $self->session, | ||
| 19448 | 'Edit contact \'' . $obj->name . '\'', | ||
| 19449 | $obj, | ||
| 19450 | FALSE, # Not temporary | ||
| 19451 | ); | ||
| 19452 | |||
| 19453 | return 1; | ||
| 19454 | } | ||
| 19455 | } | ||
| 19456 | |||
| 19457 | sub buttonDelete_chatContact { | ||
| 19458 | |||
| 19459 | # Callback: Deletes a chat contact object (equivalent to ';deletecontact') | ||
| 19460 | # | ||
| 19461 | # Expected arguments | ||
| 19462 | # (none besides $self) | ||
| 19463 | # | ||
| 19464 | # Return values | ||
| 19465 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 19466 | # 1 otherwise | ||
| 19467 | |||
| 19468 | my ($self, $check) = @_; | ||
| 19469 | |||
| 19470 | # Local variables | ||
| 19471 | my ( | ||
| 19472 | $dataRef, $name, | ||
| 19473 | @list, @dataList, | ||
| 19474 | ); | ||
| 19475 | |||
| 19476 | # Check for improper arguments | ||
| 19477 | if (defined $check) { | ||
| 19478 | |||
| 19479 | return $axmud::CLIENT->writeImproper( | ||
| 19480 | $self->_objClass . '->buttonDelete_chatContact', | ||
| 19481 | @_, | ||
| 19482 | ); | ||
| 19483 | } | ||
| 19484 | |||
| 19485 | # Import the currently selected portions of the notebook list | ||
| 19486 | @list = $self->notebookGetSelectedData(); | ||
| 19487 | if (! @list) { | ||
| 19488 | |||
| 19489 | # Nothing selected | ||
| 19490 | return undef; | ||
| 19491 | } | ||
| 19492 | |||
| 19493 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19494 | # a single row of the list | ||
| 19495 | $dataRef = $list[0]; | ||
| 19496 | @dataList = @$dataRef; | ||
| 19497 | # The chat contact object name is the first item of data | ||
| 19498 | $name = $dataList[0]; | ||
| 19499 | if (! $name) { | ||
| 19500 | |||
| 19501 | # Can't continue | ||
| 19502 | return undef; | ||
| 19503 | } | ||
| 19504 | |||
| 19505 | # Delete the chat contact | ||
| 19506 | $self->session->pseudoCmd('deletecontact ' . $name, $self->pseudoCmdMode); | ||
| 19507 | |||
| 19508 | # Update the notebook | ||
| 19509 | $self->updateNotebook(); | ||
| 19510 | |||
| 19511 | return 1; | ||
| 19512 | } | ||
| 19513 | |||
| 19514 | sub buttonDump_chatContact { | ||
| 19515 | |||
| 19516 | # Callback: Displays a list of chat contact objects in the 'main' window (equivalent to | ||
| 19517 | # ';listcontact') | ||
| 19518 | # | ||
| 19519 | # Expected arguments | ||
| 19520 | # (none besides $self) | ||
| 19521 | # | ||
| 19522 | # Return values | ||
| 19523 | # 'undef' on improper arguments | ||
| 19524 | # 1 otherwise | ||
| 19525 | |||
| 19526 | my ($self, $check) = @_; | ||
| 19527 | |||
| 19528 | # Local variables | ||
| 19529 | my ($tab, $slWidget); | ||
| 19530 | |||
| 19531 | # Check for improper arguments | ||
| 19532 | if (defined $check) { | ||
| 19533 | |||
| 19534 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_chatContact', @_); | ||
| 19535 | } | ||
| 19536 | |||
| 19537 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19538 | $tab = $self->notebookGetTab(); | ||
| 19539 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19540 | |||
| 19541 | # Unselect everything in the list | ||
| 19542 | $slWidget->get_selection->unselect_all(); | ||
| 19543 | |||
| 19544 | # Display the list | ||
| 19545 | $self->session->pseudoCmd('listcontact', $self->pseudoCmdMode); | ||
| 19546 | |||
| 19547 | return 1; | ||
| 19548 | } | ||
| 19549 | |||
| 19550 | # Colour scheme button callbacks | ||
| 19551 | |||
| 19552 | sub buttonAdd_colourScheme { | ||
| 19553 | |||
| 19554 | # Callback: Add a colour scheme object (equivalent to ';addcolourscheme') | ||
| 19555 | # | ||
| 19556 | # Expected arguments | ||
| 19557 | # (none besides $self) | ||
| 19558 | # | ||
| 19559 | # Return values | ||
| 19560 | # 'undef' on improper arguments | ||
| 19561 | # 1 otherwise | ||
| 19562 | |||
| 19563 | my ($self, $check) = @_; | ||
| 19564 | |||
| 19565 | # Local variables | ||
| 19566 | my ($tab, $slWidget, $name); | ||
| 19567 | |||
| 19568 | # Check for improper arguments | ||
| 19569 | if (defined $check) { | ||
| 19570 | |||
| 19571 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_colourScheme', @_); | ||
| 19572 | } | ||
| 19573 | |||
| 19574 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19575 | $tab = $self->notebookGetTab(); | ||
| 19576 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19577 | |||
| 19578 | # Unselect everything in the list, because we're creating a new colour scheme | ||
| 19579 | $slWidget->get_selection->unselect_all(); | ||
| 19580 | |||
| 19581 | # Prompt the user for the name of the colour scheme object | ||
| 19582 | $name = $self->showEntryDialogue( | ||
| 19583 | 'Add colour scheme', | ||
| 19584 | 'Enter a name for the object (max 16 chars: A-Z a-z _ 0-9)', | ||
| 19585 | 16, # Max chars | ||
| 19586 | ); | ||
| 19587 | |||
| 19588 | if ($name) { | ||
| 19589 | |||
| 19590 | # Add the new colour scheme | ||
| 19591 | $self->session->pseudoCmd('addcolourscheme ' . $name, $self->pseudoCmdMode); | ||
| 19592 | |||
| 19593 | # Update the notebook | ||
| 19594 | $self->updateNotebook(); | ||
| 19595 | } | ||
| 19596 | |||
| 19597 | return 1; | ||
| 19598 | } | ||
| 19599 | |||
| 19600 | sub buttonEdit_colourScheme { | ||
| 19601 | |||
| 19602 | # Callback: Edits a colour scheme object (equivalent to ';editcolourscheme') | ||
| 19603 | # | ||
| 19604 | # Expected arguments | ||
| 19605 | # (none besides $self) | ||
| 19606 | # | ||
| 19607 | # Return values | ||
| 19608 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 19609 | # object no longer exists | ||
| 19610 | # 1 otherwise | ||
| 19611 | |||
| 19612 | my ($self, $check) = @_; | ||
| 19613 | |||
| 19614 | # Local variables | ||
| 19615 | my ( | ||
| 19616 | $dataRef, $name, $obj, | ||
| 19617 | @list, @dataList, | ||
| 19618 | ); | ||
| 19619 | |||
| 19620 | # Check for improper arguments | ||
| 19621 | if (defined $check) { | ||
| 19622 | |||
| 19623 | return $axmud::CLIENT->writeImproper( | ||
| 19624 | $self->_objClass . '->buttonEdit_colourScheme', | ||
| 19625 | @_, | ||
| 19626 | ); | ||
| 19627 | } | ||
| 19628 | |||
| 19629 | # Import the currently selected portions of the notebook list | ||
| 19630 | @list = $self->notebookGetSelectedData(); | ||
| 19631 | if (! @list) { | ||
| 19632 | |||
| 19633 | # Nothing selected | ||
| 19634 | return undef; | ||
| 19635 | } | ||
| 19636 | |||
| 19637 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19638 | # a single row of the list | ||
| 19639 | $dataRef = $list[0]; | ||
| 19640 | @dataList = @$dataRef; | ||
| 19641 | # The colour scheme's name is the second item of data | ||
| 19642 | $name = $dataList[1]; | ||
| 19643 | if (! $name) { | ||
| 19644 | |||
| 19645 | # Can't continue | ||
| 19646 | return undef; | ||
| 19647 | } | ||
| 19648 | |||
| 19649 | # Get the colour scheme itself | ||
| 19650 | $obj = $axmud::CLIENT->ivShow('colourSchemeHash', $name); | ||
| 19651 | if (! $obj) { | ||
| 19652 | |||
| 19653 | # Can't continue | ||
| 19654 | return undef; | ||
| 19655 | |||
| 19656 | } else { | ||
| 19657 | |||
| 19658 | # Open up an 'edit' window to edit the object | ||
| 19659 | $self->createFreeWin( | ||
| 19660 | 'Games::Axmud::EditWin::ColourScheme', | ||
| 19661 | $self, | ||
| 19662 | $self->session, | ||
| 19663 | 'Edit colour scheme \'' . $name . '\'', | ||
| 19664 | $obj, | ||
| 19665 | FALSE, # Not temporary | ||
| 19666 | ); | ||
| 19667 | |||
| 19668 | return 1; | ||
| 19669 | } | ||
| 19670 | } | ||
| 19671 | |||
| 19672 | sub buttonDelete_colourScheme { | ||
| 19673 | |||
| 19674 | # Callback: Deletes a colour scheme object (equivalent to ';deletecolourscheme') | ||
| 19675 | # | ||
| 19676 | # Expected arguments | ||
| 19677 | # (none besides $self) | ||
| 19678 | # | ||
| 19679 | # Return values | ||
| 19680 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 19681 | # 1 otherwise | ||
| 19682 | |||
| 19683 | my ($self, $check) = @_; | ||
| 19684 | |||
| 19685 | # Local variables | ||
| 19686 | my ( | ||
| 19687 | $dataRef, $name, | ||
| 19688 | @list, @dataList, | ||
| 19689 | ); | ||
| 19690 | |||
| 19691 | # Check for improper arguments | ||
| 19692 | if (defined $check) { | ||
| 19693 | |||
| 19694 | return $axmud::CLIENT->writeImproper( | ||
| 19695 | $self->_objClass . '->buttonDelete_colourScheme', | ||
| 19696 | @_, | ||
| 19697 | ); | ||
| 19698 | } | ||
| 19699 | |||
| 19700 | # Import the currently selected portions of the notebook list | ||
| 19701 | @list = $self->notebookGetSelectedData(); | ||
| 19702 | if (! @list) { | ||
| 19703 | |||
| 19704 | # Nothing selected | ||
| 19705 | return undef; | ||
| 19706 | } | ||
| 19707 | |||
| 19708 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19709 | # a single row of the list | ||
| 19710 | $dataRef = $list[0]; | ||
| 19711 | @dataList = @$dataRef; | ||
| 19712 | # The colour scheme object name is the second item of data | ||
| 19713 | $name = $dataList[1]; | ||
| 19714 | if (! $name) { | ||
| 19715 | |||
| 19716 | # Can't continue | ||
| 19717 | return undef; | ||
| 19718 | } | ||
| 19719 | |||
| 19720 | # Delete the colour scheme | ||
| 19721 | $self->session->pseudoCmd('deletecolourscheme <' . $name . '>', $self->pseudoCmdMode); | ||
| 19722 | |||
| 19723 | # Update the notebook | ||
| 19724 | $self->updateNotebook(); | ||
| 19725 | |||
| 19726 | return 1; | ||
| 19727 | } | ||
| 19728 | |||
| 19729 | sub buttonDump_colourScheme { | ||
| 19730 | |||
| 19731 | # Callback: Displays a list of colour scheme objects in the 'main' window (equivalent to | ||
| 19732 | # ';listcolourscheme') | ||
| 19733 | # | ||
| 19734 | # Expected arguments | ||
| 19735 | # (none besides $self) | ||
| 19736 | # | ||
| 19737 | # Return values | ||
| 19738 | # 'undef' on improper arguments | ||
| 19739 | # 1 otherwise | ||
| 19740 | |||
| 19741 | my ($self, $check) = @_; | ||
| 19742 | |||
| 19743 | # Local variables | ||
| 19744 | my ($tab, $slWidget); | ||
| 19745 | |||
| 19746 | # Check for improper arguments | ||
| 19747 | if (defined $check) { | ||
| 19748 | |||
| 19749 | return $axmud::CLIENT->writeImproper( | ||
| 19750 | $self->_objClass . '->buttonDump_colourScheme', | ||
| 19751 | @_, | ||
| 19752 | ); | ||
| 19753 | } | ||
| 19754 | |||
| 19755 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19756 | $tab = $self->notebookGetTab(); | ||
| 19757 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19758 | |||
| 19759 | # Unselect everything in the list | ||
| 19760 | $slWidget->get_selection->unselect_all(); | ||
| 19761 | |||
| 19762 | # Display the list | ||
| 19763 | $self->session->pseudoCmd('listcolourscheme', $self->pseudoCmdMode); | ||
| 19764 | |||
| 19765 | return 1; | ||
| 19766 | } | ||
| 19767 | |||
| 19768 | # Map label style callbacks | ||
| 19769 | |||
| 19770 | sub buttonAdd_mapLabelStyle { | ||
| 19771 | |||
| 19772 | # Callback: Add a map label style object (equivalent to ';addlabelstyle') | ||
| 19773 | # | ||
| 19774 | # Expected arguments | ||
| 19775 | # (none besides $self) | ||
| 19776 | # | ||
| 19777 | # Return values | ||
| 19778 | # 'undef' on improper arguments | ||
| 19779 | # 1 otherwise | ||
| 19780 | |||
| 19781 | my ($self, $check) = @_; | ||
| 19782 | |||
| 19783 | # Local variables | ||
| 19784 | my ($tab, $slWidget, $name); | ||
| 19785 | |||
| 19786 | # Check for improper arguments | ||
| 19787 | if (defined $check) { | ||
| 19788 | |||
| 19789 | return $axmud::CLIENT->writeImproper( | ||
| 19790 | $self->_objClass . '->buttonAdd_mapLabelStyle', | ||
| 19791 | @_, | ||
| 19792 | ); | ||
| 19793 | } | ||
| 19794 | |||
| 19795 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 19796 | $tab = $self->notebookGetTab(); | ||
| 19797 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 19798 | |||
| 19799 | # Unselect everything in the list, because we're creating a new map label style | ||
| 19800 | $slWidget->get_selection->unselect_all(); | ||
| 19801 | |||
| 19802 | # Prompt the user for the name of the map label style object | ||
| 19803 | $name = $self->showEntryDialogue( | ||
| 19804 | 'Add map label style', | ||
| 19805 | 'Enter a name for the object (max 16 chars)', | ||
| 19806 | 16, # Max chars | ||
| 19807 | ); | ||
| 19808 | |||
| 19809 | if ($name) { | ||
| 19810 | |||
| 19811 | # Add the new map label style | ||
| 19812 | $self->session->pseudoCmd('addlabelstyle <' . $name . '>', $self->pseudoCmdMode); | ||
| 19813 | |||
| 19814 | # Update the notebook | ||
| 19815 | $self->updateNotebook(); | ||
| 19816 | } | ||
| 19817 | |||
| 19818 | return 1; | ||
| 19819 | } | ||
| 19820 | |||
| 19821 | sub buttonEdit_mapLabelStyle { | ||
| 19822 | |||
| 19823 | # Callback: Edits a map label style object (equivalent to ';editlabelstyle') | ||
| 19824 | # | ||
| 19825 | # Expected arguments | ||
| 19826 | # (none besides $self) | ||
| 19827 | # | ||
| 19828 | # Return values | ||
| 19829 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 19830 | # object no longer exists | ||
| 19831 | # 1 otherwise | ||
| 19832 | |||
| 19833 | my ($self, $check) = @_; | ||
| 19834 | |||
| 19835 | # Local variables | ||
| 19836 | my ( | ||
| 19837 | $dataRef, $name, $obj, | ||
| 19838 | @list, @dataList, | ||
| 19839 | ); | ||
| 19840 | |||
| 19841 | # Check for improper arguments | ||
| 19842 | if (defined $check) { | ||
| 19843 | |||
| 19844 | return $axmud::CLIENT->writeImproper( | ||
| 19845 | $self->_objClass . '->buttonEdit_mapLabelStyle', | ||
| 19846 | @_, | ||
| 19847 | ); | ||
| 19848 | } | ||
| 19849 | |||
| 19850 | # Import the currently selected portions of the notebook list | ||
| 19851 | @list = $self->notebookGetSelectedData(); | ||
| 19852 | if (! @list) { | ||
| 19853 | |||
| 19854 | # Nothing selected | ||
| 19855 | return undef; | ||
| 19856 | } | ||
| 19857 | |||
| 19858 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19859 | # a single row of the list | ||
| 19860 | $dataRef = $list[0]; | ||
| 19861 | @dataList = @$dataRef; | ||
| 19862 | # The map label style's name is the second item of data | ||
| 19863 | $name = $dataList[1]; | ||
| 19864 | if (! $name) { | ||
| 19865 | |||
| 19866 | # Can't continue | ||
| 19867 | return undef; | ||
| 19868 | } | ||
| 19869 | |||
| 19870 | # Get the map label style itself | ||
| 19871 | $obj = $self->session->worldModelObj->ivShow('mapLabelStyleHash', $name); | ||
| 19872 | if (! $obj) { | ||
| 19873 | |||
| 19874 | # Can't continue | ||
| 19875 | return undef; | ||
| 19876 | |||
| 19877 | } else { | ||
| 19878 | |||
| 19879 | # Open up an 'edit' window to edit the object | ||
| 19880 | $self->createFreeWin( | ||
| 19881 | 'Games::Axmud::EditWin::MapLabelStyle', | ||
| 19882 | $self, | ||
| 19883 | $self->session, | ||
| 19884 | 'Edit map label style \'' . $name . '\'', | ||
| 19885 | $obj, | ||
| 19886 | FALSE, # Not temporary | ||
| 19887 | ); | ||
| 19888 | |||
| 19889 | return 1; | ||
| 19890 | } | ||
| 19891 | } | ||
| 19892 | |||
| 19893 | sub buttonRename_mapLabelStyle { | ||
| 19894 | |||
| 19895 | # Callback: Renames a map label style object (equivalent to ';renamelabelstyle') | ||
| 19896 | # | ||
| 19897 | # Expected arguments | ||
| 19898 | # (none besides $self) | ||
| 19899 | # | ||
| 19900 | # Return values | ||
| 19901 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 19902 | # object no longer exists | ||
| 19903 | # 1 otherwise | ||
| 19904 | |||
| 19905 | my ($self, $check) = @_; | ||
| 19906 | |||
| 19907 | # Local variables | ||
| 19908 | my ( | ||
| 19909 | $dataRef, $oldName, $obj, $newName, | ||
| 19910 | @list, @dataList, | ||
| 19911 | ); | ||
| 19912 | |||
| 19913 | # Check for improper arguments | ||
| 19914 | if (defined $check) { | ||
| 19915 | |||
| 19916 | return $axmud::CLIENT->writeImproper( | ||
| 19917 | $self->_objClass . '->buttonRename_mapLabelStyle', | ||
| 19918 | @_, | ||
| 19919 | ); | ||
| 19920 | } | ||
| 19921 | |||
| 19922 | # Import the currently selected portions of the notebook list | ||
| 19923 | @list = $self->notebookGetSelectedData(); | ||
| 19924 | if (! @list) { | ||
| 19925 | |||
| 19926 | # Nothing selected | ||
| 19927 | return undef; | ||
| 19928 | } | ||
| 19929 | |||
| 19930 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 19931 | # a single row of the list | ||
| 19932 | $dataRef = $list[0]; | ||
| 19933 | @dataList = @$dataRef; | ||
| 19934 | # The map label style's name is the second item of data | ||
| 19935 | $oldName = $dataList[1]; | ||
| 19936 | if (! $oldName) { | ||
| 19937 | |||
| 19938 | # Can't continue | ||
| 19939 | return undef; | ||
| 19940 | } | ||
| 19941 | |||
| 19942 | # Get the map label style itself | ||
| 19943 | $obj = $self->session->worldModelObj->ivShow('mapLabelStyleHash', $oldName); | ||
| 19944 | if (! $obj) { | ||
| 19945 | |||
| 19946 | # Can't continue | ||
| 19947 | return undef; | ||
| 19948 | } | ||
| 19949 | |||
| 19950 | # Prompt the user for a new name | ||
| 19951 | $newName = $self->showEntryDialogue( | ||
| 19952 | 'Rename map label style', | ||
| 19953 | 'Enter a new name for the object (max 16 chars)', | ||
| 19954 | 16, # Max chars | ||
| 19955 | ); | ||
| 19956 | |||
| 19957 | if ($newName) { | ||
| 19958 | |||
| 19959 | # Rename the map label style | ||
| 19960 | $self->session->pseudoCmd( | ||
| 19961 | 'renamelabelstyle <' . $oldName . '> <' . $newName . '>', | ||
| 19962 | $self->pseudoCmdMode, | ||
| 19963 | ); | ||
| 19964 | |||
| 19965 | # Update the notebook | ||
| 19966 | $self->updateNotebook(); | ||
| 19967 | } | ||
| 19968 | |||
| 19969 | return 1; | ||
| 19970 | } | ||
| 19971 | |||
| 19972 | sub buttonDelete_mapLabelStyle { | ||
| 19973 | |||
| 19974 | # Callback: Deletes a map label style object (equivalent to ';deletelabelstyle') | ||
| 19975 | # | ||
| 19976 | # Expected arguments | ||
| 19977 | # (none besides $self) | ||
| 19978 | # | ||
| 19979 | # Return values | ||
| 19980 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 19981 | # 1 otherwise | ||
| 19982 | |||
| 19983 | my ($self, $check) = @_; | ||
| 19984 | |||
| 19985 | # Local variables | ||
| 19986 | my ( | ||
| 19987 | $dataRef, $name, | ||
| 19988 | @list, @dataList, | ||
| 19989 | ); | ||
| 19990 | |||
| 19991 | # Check for improper arguments | ||
| 19992 | if (defined $check) { | ||
| 19993 | |||
| 19994 | return $axmud::CLIENT->writeImproper( | ||
| 19995 | $self->_objClass . '->buttonDelete_mapLabelStyle', | ||
| 19996 | @_, | ||
| 19997 | ); | ||
| 19998 | } | ||
| 19999 | |||
| 20000 | # Import the currently selected portions of the notebook list | ||
| 20001 | @list = $self->notebookGetSelectedData(); | ||
| 20002 | if (! @list) { | ||
| 20003 | |||
| 20004 | # Nothing selected | ||
| 20005 | return undef; | ||
| 20006 | } | ||
| 20007 | |||
| 20008 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20009 | # a single row of the list | ||
| 20010 | $dataRef = $list[0]; | ||
| 20011 | @dataList = @$dataRef; | ||
| 20012 | # The map label style object name is the second item of data | ||
| 20013 | $name = $dataList[1]; | ||
| 20014 | if (! $name) { | ||
| 20015 | |||
| 20016 | # Can't continue | ||
| 20017 | return undef; | ||
| 20018 | } | ||
| 20019 | |||
| 20020 | # Delete the map label style | ||
| 20021 | $self->session->pseudoCmd('deletelabelstyle <' . $name . '>', $self->pseudoCmdMode); | ||
| 20022 | |||
| 20023 | # Update the notebook | ||
| 20024 | $self->updateNotebook(); | ||
| 20025 | |||
| 20026 | return 1; | ||
| 20027 | } | ||
| 20028 | |||
| 20029 | sub buttonDump_mapLabelStyle { | ||
| 20030 | |||
| 20031 | # Callback: Displays a list of map label style objects in the 'main' window (equivalent to | ||
| 20032 | # ';listlabelstyle') | ||
| 20033 | # | ||
| 20034 | # Expected arguments | ||
| 20035 | # (none besides $self) | ||
| 20036 | # | ||
| 20037 | # Return values | ||
| 20038 | # 'undef' on improper arguments | ||
| 20039 | # 1 otherwise | ||
| 20040 | |||
| 20041 | my ($self, $check) = @_; | ||
| 20042 | |||
| 20043 | # Local variables | ||
| 20044 | my ($tab, $slWidget); | ||
| 20045 | |||
| 20046 | # Check for improper arguments | ||
| 20047 | if (defined $check) { | ||
| 20048 | |||
| 20049 | return $axmud::CLIENT->writeImproper( | ||
| 20050 | $self->_objClass . '->buttonDump_mapLabelStyle', | ||
| 20051 | @_, | ||
| 20052 | ); | ||
| 20053 | } | ||
| 20054 | |||
| 20055 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20056 | $tab = $self->notebookGetTab(); | ||
| 20057 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20058 | |||
| 20059 | # Unselect everything in the list | ||
| 20060 | $slWidget->get_selection->unselect_all(); | ||
| 20061 | |||
| 20062 | # Display the list | ||
| 20063 | $self->session->pseudoCmd('listlabelstyle', $self->pseudoCmdMode); | ||
| 20064 | |||
| 20065 | return 1; | ||
| 20066 | } | ||
| 20067 | |||
| 20068 | # Region colour scheme button callbacks | ||
| 20069 | |||
| 20070 | sub buttonAdd_regionScheme { | ||
| 20071 | |||
| 20072 | # Callback: Add a region scheme object (equivalent to ';addregionscheme') | ||
| 20073 | # | ||
| 20074 | # Expected arguments | ||
| 20075 | # (none besides $self) | ||
| 20076 | # | ||
| 20077 | # Return values | ||
| 20078 | # 'undef' on improper arguments | ||
| 20079 | # 1 otherwise | ||
| 20080 | |||
| 20081 | my ($self, $check) = @_; | ||
| 20082 | |||
| 20083 | # Local variables | ||
| 20084 | my ($tab, $slWidget, $name); | ||
| 20085 | |||
| 20086 | # Check for improper arguments | ||
| 20087 | if (defined $check) { | ||
| 20088 | |||
| 20089 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_regionScheme', @_); | ||
| 20090 | } | ||
| 20091 | |||
| 20092 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20093 | $tab = $self->notebookGetTab(); | ||
| 20094 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20095 | |||
| 20096 | # Unselect everything in the list, because we're creating a new region scheme | ||
| 20097 | $slWidget->get_selection->unselect_all(); | ||
| 20098 | |||
| 20099 | # Prompt the user for the name of the region scheme object | ||
| 20100 | $name = $self->showEntryDialogue( | ||
| 20101 | 'Add region colour scheme', | ||
| 20102 | 'Enter a name for the object (max 16 chars)', | ||
| 20103 | 16, # Max chars | ||
| 20104 | ); | ||
| 20105 | |||
| 20106 | if ($name) { | ||
| 20107 | |||
| 20108 | # Add the new colour scheme | ||
| 20109 | $self->session->pseudoCmd('addregionscheme <' . $name . '>', $self->pseudoCmdMode); | ||
| 20110 | |||
| 20111 | # Update the notebook | ||
| 20112 | $self->updateNotebook(); | ||
| 20113 | } | ||
| 20114 | |||
| 20115 | return 1; | ||
| 20116 | } | ||
| 20117 | |||
| 20118 | sub buttonEdit_regionScheme { | ||
| 20119 | |||
| 20120 | # Callback: Edits a region colour scheme object (equivalent to ';editregionscheme') | ||
| 20121 | # | ||
| 20122 | # Expected arguments | ||
| 20123 | # (none besides $self) | ||
| 20124 | # | ||
| 20125 | # Return values | ||
| 20126 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 20127 | # object no longer exists | ||
| 20128 | # 1 otherwise | ||
| 20129 | |||
| 20130 | my ($self, $check) = @_; | ||
| 20131 | |||
| 20132 | # Local variables | ||
| 20133 | my ( | ||
| 20134 | $dataRef, $name, $obj, | ||
| 20135 | @list, @dataList, | ||
| 20136 | ); | ||
| 20137 | |||
| 20138 | # Check for improper arguments | ||
| 20139 | if (defined $check) { | ||
| 20140 | |||
| 20141 | return $axmud::CLIENT->writeImproper( | ||
| 20142 | $self->_objClass . '->buttonEdit_regionScheme', | ||
| 20143 | @_, | ||
| 20144 | ); | ||
| 20145 | } | ||
| 20146 | |||
| 20147 | # Import the currently selected portions of the notebook list | ||
| 20148 | @list = $self->notebookGetSelectedData(); | ||
| 20149 | if (! @list) { | ||
| 20150 | |||
| 20151 | # Nothing selected | ||
| 20152 | return undef; | ||
| 20153 | } | ||
| 20154 | |||
| 20155 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20156 | # a single row of the list | ||
| 20157 | $dataRef = $list[0]; | ||
| 20158 | @dataList = @$dataRef; | ||
| 20159 | # The region scheme's name is the second item of data | ||
| 20160 | $name = $dataList[1]; | ||
| 20161 | if (! $name) { | ||
| 20162 | |||
| 20163 | # Can't continue | ||
| 20164 | return undef; | ||
| 20165 | } | ||
| 20166 | |||
| 20167 | # Get the region scheme itself | ||
| 20168 | $obj = $self->session->worldModelObj->ivShow('regionSchemeHash', $name); | ||
| 20169 | if (! $obj) { | ||
| 20170 | |||
| 20171 | # Can't continue | ||
| 20172 | return undef; | ||
| 20173 | |||
| 20174 | } else { | ||
| 20175 | |||
| 20176 | # Open up an 'edit' window to edit the object | ||
| 20177 | $self->createFreeWin( | ||
| 20178 | 'Games::Axmud::EditWin::RegionScheme', | ||
| 20179 | $self, | ||
| 20180 | $self->session, | ||
| 20181 | 'Edit region colour scheme \'' . $name . '\'', | ||
| 20182 | $obj, | ||
| 20183 | FALSE, # Not temporary | ||
| 20184 | ); | ||
| 20185 | |||
| 20186 | return 1; | ||
| 20187 | } | ||
| 20188 | } | ||
| 20189 | |||
| 20190 | sub buttonRename_regionScheme { | ||
| 20191 | |||
| 20192 | # Callback: Renames a region colour scheme object (equivalent to ';renameregionscheme') | ||
| 20193 | # | ||
| 20194 | # Expected arguments | ||
| 20195 | # (none besides $self) | ||
| 20196 | # | ||
| 20197 | # Return values | ||
| 20198 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 20199 | # object no longer exists | ||
| 20200 | # 1 otherwise | ||
| 20201 | |||
| 20202 | my ($self, $check) = @_; | ||
| 20203 | |||
| 20204 | # Local variables | ||
| 20205 | my ( | ||
| 20206 | $dataRef, $oldName, $obj, $newName, | ||
| 20207 | @list, @dataList, | ||
| 20208 | ); | ||
| 20209 | |||
| 20210 | # Check for improper arguments | ||
| 20211 | if (defined $check) { | ||
| 20212 | |||
| 20213 | return $axmud::CLIENT->writeImproper( | ||
| 20214 | $self->_objClass . '->buttonEdit_regionScheme', | ||
| 20215 | @_, | ||
| 20216 | ); | ||
| 20217 | } | ||
| 20218 | |||
| 20219 | # Import the currently selected portions of the notebook list | ||
| 20220 | @list = $self->notebookGetSelectedData(); | ||
| 20221 | if (! @list) { | ||
| 20222 | |||
| 20223 | # Nothing selected | ||
| 20224 | return undef; | ||
| 20225 | } | ||
| 20226 | |||
| 20227 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20228 | # a single row of the list | ||
| 20229 | $dataRef = $list[0]; | ||
| 20230 | @dataList = @$dataRef; | ||
| 20231 | # The region scheme's name is the second item of data | ||
| 20232 | $oldName = $dataList[1]; | ||
| 20233 | if (! $oldName) { | ||
| 20234 | |||
| 20235 | # Can't continue | ||
| 20236 | return undef; | ||
| 20237 | } | ||
| 20238 | |||
| 20239 | # Get the region scheme itself | ||
| 20240 | $obj = $self->session->worldModelObj->ivShow('regionSchemeHash', $oldName); | ||
| 20241 | if (! $obj) { | ||
| 20242 | |||
| 20243 | # Can't continue | ||
| 20244 | return undef; | ||
| 20245 | } | ||
| 20246 | |||
| 20247 | # Prompt the user for a new name | ||
| 20248 | $newName = $self->showEntryDialogue( | ||
| 20249 | 'Rename region colour scheme', | ||
| 20250 | 'Enter a new name for the object (max 16 chars)', | ||
| 20251 | 16, # Max chars | ||
| 20252 | ); | ||
| 20253 | |||
| 20254 | if ($newName) { | ||
| 20255 | |||
| 20256 | # Rename the colour scheme | ||
| 20257 | $self->session->pseudoCmd( | ||
| 20258 | 'renameregionscheme <' . $oldName . '> <' . $newName . '>', | ||
| 20259 | $self->pseudoCmdMode, | ||
| 20260 | ); | ||
| 20261 | |||
| 20262 | # Update the notebook | ||
| 20263 | $self->updateNotebook(); | ||
| 20264 | } | ||
| 20265 | |||
| 20266 | return 1; | ||
| 20267 | } | ||
| 20268 | |||
| 20269 | sub buttonDelete_regionScheme { | ||
| 20270 | |||
| 20271 | # Callback: Deletes a region scheme object (equivalent to ';deleteregionscheme') | ||
| 20272 | # | ||
| 20273 | # Expected arguments | ||
| 20274 | # (none besides $self) | ||
| 20275 | # | ||
| 20276 | # Return values | ||
| 20277 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 20278 | # 1 otherwise | ||
| 20279 | |||
| 20280 | my ($self, $check) = @_; | ||
| 20281 | |||
| 20282 | # Local variables | ||
| 20283 | my ( | ||
| 20284 | $dataRef, $name, | ||
| 20285 | @list, @dataList, | ||
| 20286 | ); | ||
| 20287 | |||
| 20288 | # Check for improper arguments | ||
| 20289 | if (defined $check) { | ||
| 20290 | |||
| 20291 | return $axmud::CLIENT->writeImproper( | ||
| 20292 | $self->_objClass . '->buttonDelete_regionScheme', | ||
| 20293 | @_, | ||
| 20294 | ); | ||
| 20295 | } | ||
| 20296 | |||
| 20297 | # Import the currently selected portions of the notebook list | ||
| 20298 | @list = $self->notebookGetSelectedData(); | ||
| 20299 | if (! @list) { | ||
| 20300 | |||
| 20301 | # Nothing selected | ||
| 20302 | return undef; | ||
| 20303 | } | ||
| 20304 | |||
| 20305 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20306 | # a single row of the list | ||
| 20307 | $dataRef = $list[0]; | ||
| 20308 | @dataList = @$dataRef; | ||
| 20309 | # The region scheme object name is the second item of data | ||
| 20310 | $name = $dataList[1]; | ||
| 20311 | if (! $name) { | ||
| 20312 | |||
| 20313 | # Can't continue | ||
| 20314 | return undef; | ||
| 20315 | } | ||
| 20316 | |||
| 20317 | # Delete the region scheme | ||
| 20318 | $self->session->pseudoCmd('deleteregionscheme <' . $name . '>', $self->pseudoCmdMode); | ||
| 20319 | |||
| 20320 | # Update the notebook | ||
| 20321 | $self->updateNotebook(); | ||
| 20322 | |||
| 20323 | return 1; | ||
| 20324 | } | ||
| 20325 | |||
| 20326 | sub buttonDump_regionScheme { | ||
| 20327 | |||
| 20328 | # Callback: Displays a list of region scheme objects in the 'main' window (equivalent to | ||
| 20329 | # ';listregionscheme') | ||
| 20330 | # | ||
| 20331 | # Expected arguments | ||
| 20332 | # (none besides $self) | ||
| 20333 | # | ||
| 20334 | # Return values | ||
| 20335 | # 'undef' on improper arguments | ||
| 20336 | # 1 otherwise | ||
| 20337 | |||
| 20338 | my ($self, $check) = @_; | ||
| 20339 | |||
| 20340 | # Local variables | ||
| 20341 | my ($tab, $slWidget); | ||
| 20342 | |||
| 20343 | # Check for improper arguments | ||
| 20344 | if (defined $check) { | ||
| 20345 | |||
| 20346 | return $axmud::CLIENT->writeImproper( | ||
| 20347 | $self->_objClass . '->buttonDump_regionScheme', | ||
| 20348 | @_, | ||
| 20349 | ); | ||
| 20350 | } | ||
| 20351 | |||
| 20352 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20353 | $tab = $self->notebookGetTab(); | ||
| 20354 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20355 | |||
| 20356 | # Unselect everything in the list | ||
| 20357 | $slWidget->get_selection->unselect_all(); | ||
| 20358 | |||
| 20359 | # Display the list | ||
| 20360 | $self->session->pseudoCmd('listregionscheme', $self->pseudoCmdMode); | ||
| 20361 | |||
| 20362 | return 1; | ||
| 20363 | } | ||
| 20364 | |||
| 20365 | # TTS configuration button callbacks | ||
| 20366 | |||
| 20367 | sub buttonAdd_tts { | ||
| 20368 | |||
| 20369 | # Callback: Add a TTS configuration (equivalent to ';addconfig') | ||
| 20370 | # | ||
| 20371 | # Expected arguments | ||
| 20372 | # (none besides $self) | ||
| 20373 | # | ||
| 20374 | # Return values | ||
| 20375 | # 'undef' on improper arguments | ||
| 20376 | # 1 otherwise | ||
| 20377 | |||
| 20378 | my ($self, $check) = @_; | ||
| 20379 | |||
| 20380 | # Local variables | ||
| 20381 | my ($tab, $slWidget, $name, $engine); | ||
| 20382 | |||
| 20383 | # Check for improper arguments | ||
| 20384 | if (defined $check) { | ||
| 20385 | |||
| 20386 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_tts', @_); | ||
| 20387 | } | ||
| 20388 | |||
| 20389 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20390 | $tab = $self->notebookGetTab(); | ||
| 20391 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20392 | |||
| 20393 | # Unselect everything in the list, because we're creating a new TTS configuration | ||
| 20394 | $slWidget->get_selection->unselect_all(); | ||
| 20395 | |||
| 20396 | # Prompt the user for the name of the TTS configuration and the engine to use | ||
| 20397 | ($name, $engine) = $self->showEntryComboDialogue( | ||
| 20398 | 'Add TTS configuration', | ||
| 20399 | 'Enter a name for the object (max 16 chars: A-Z a-z _ 0-9)', | ||
| 20400 | 'Select the speech engine', | ||
| 20401 | [$axmud::CLIENT->constTTSList], | ||
| 20402 | 16, # Max chars | ||
| 20403 | ); | ||
| 20404 | |||
| 20405 | if ($name) { | ||
| 20406 | |||
| 20407 | # Add the new TTS configuration | ||
| 20408 | $self->session->pseudoCmd('addconfig ' . $name . ' ' . $engine, $self->pseudoCmdMode); | ||
| 20409 | |||
| 20410 | # Update the notebook | ||
| 20411 | $self->updateNotebook(); | ||
| 20412 | } | ||
| 20413 | |||
| 20414 | return 1; | ||
| 20415 | } | ||
| 20416 | |||
| 20417 | sub buttonClone_tts { | ||
| 20418 | |||
| 20419 | # Callback: Clones the selected TTS configuration (equivalent to ';cloneconfig') | ||
| 20420 | # | ||
| 20421 | # Expected arguments | ||
| 20422 | # (none besides $self) | ||
| 20423 | # | ||
| 20424 | # Return values | ||
| 20425 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 20426 | # 1 otherwise | ||
| 20427 | |||
| 20428 | my ($self, $check) = @_; | ||
| 20429 | |||
| 20430 | # Local variables | ||
| 20431 | my ( | ||
| 20432 | $dataRef, $name, $cloneName, | ||
| 20433 | @list, @dataList, | ||
| 20434 | ); | ||
| 20435 | |||
| 20436 | # Check for improper arguments | ||
| 20437 | if (defined $check) { | ||
| 20438 | |||
| 20439 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonClone_tts', @_); | ||
| 20440 | } | ||
| 20441 | |||
| 20442 | # Import the currently selected portions of the notebook list | ||
| 20443 | @list = $self->notebookGetSelectedData(); | ||
| 20444 | if (! @list) { | ||
| 20445 | |||
| 20446 | # Nothing selected | ||
| 20447 | return undef; | ||
| 20448 | } | ||
| 20449 | |||
| 20450 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20451 | # a single row of the list | ||
| 20452 | $dataRef = $list[0]; | ||
| 20453 | @dataList = @$dataRef; | ||
| 20454 | # The TTS configuration object name is the first item of data | ||
| 20455 | $name = $dataList[0]; | ||
| 20456 | if (! $name) { | ||
| 20457 | |||
| 20458 | # Can't continue | ||
| 20459 | return undef; | ||
| 20460 | } | ||
| 20461 | |||
| 20462 | # Prompt the user for the name of the clone | ||
| 20463 | $cloneName = $self->showEntryDialogue( | ||
| 20464 | 'Clone TTS configuration', | ||
| 20465 | 'Enter a name for the clone (max 16 chars: A-Z a-z _ 0-9)', | ||
| 20466 | 16, # Max chars | ||
| 20467 | ); | ||
| 20468 | |||
| 20469 | if ($cloneName) { | ||
| 20470 | |||
| 20471 | # Clone the TTS configuration | ||
| 20472 | $self->session->pseudoCmd( | ||
| 20473 | 'cloneconfig ' . $name . ' ' . $cloneName, | ||
| 20474 | $self->pseudoCmdMode, | ||
| 20475 | ); | ||
| 20476 | |||
| 20477 | # Update the notebook | ||
| 20478 | $self->updateNotebook(); | ||
| 20479 | } | ||
| 20480 | |||
| 20481 | return 1; | ||
| 20482 | } | ||
| 20483 | |||
| 20484 | sub buttonEdit_tts { | ||
| 20485 | |||
| 20486 | # Callback: Edits a TTS configuration (equivalent to ';editconfig') | ||
| 20487 | # | ||
| 20488 | # Expected arguments | ||
| 20489 | # (none besides $self) | ||
| 20490 | # | ||
| 20491 | # Return values | ||
| 20492 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 20493 | # object no longer exists | ||
| 20494 | # 1 otherwise | ||
| 20495 | |||
| 20496 | my ($self, $check) = @_; | ||
| 20497 | |||
| 20498 | # Local variables | ||
| 20499 | my ( | ||
| 20500 | $dataRef, $name, $obj, | ||
| 20501 | @list, @dataList, | ||
| 20502 | ); | ||
| 20503 | |||
| 20504 | # Check for improper arguments | ||
| 20505 | if (defined $check) { | ||
| 20506 | |||
| 20507 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_tts', @_); | ||
| 20508 | } | ||
| 20509 | |||
| 20510 | # Import the currently selected portions of the notebook list | ||
| 20511 | @list = $self->notebookGetSelectedData(); | ||
| 20512 | if (! @list) { | ||
| 20513 | |||
| 20514 | # Nothing selected | ||
| 20515 | return undef; | ||
| 20516 | } | ||
| 20517 | |||
| 20518 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20519 | # a single row of the list | ||
| 20520 | $dataRef = $list[0]; | ||
| 20521 | @dataList = @$dataRef; | ||
| 20522 | # The TTS configuration's name is the first item of data | ||
| 20523 | $name = $dataList[0]; | ||
| 20524 | if (! $name) { | ||
| 20525 | |||
| 20526 | # Can't continue | ||
| 20527 | return undef; | ||
| 20528 | } | ||
| 20529 | |||
| 20530 | # Get the TTS configuration itself | ||
| 20531 | $obj = $axmud::CLIENT->ivShow('ttsObjHash', $name); | ||
| 20532 | if (! $obj) { | ||
| 20533 | |||
| 20534 | # Can't continue | ||
| 20535 | return undef; | ||
| 20536 | |||
| 20537 | } else { | ||
| 20538 | |||
| 20539 | # Open up an 'edit' window to edit the object | ||
| 20540 | $self->createFreeWin( | ||
| 20541 | 'Games::Axmud::EditWin::TTS', | ||
| 20542 | $self, | ||
| 20543 | $self->session, | ||
| 20544 | 'Edit text-to-speech configuration \'' . $name . '\'', | ||
| 20545 | $obj, | ||
| 20546 | FALSE, # Not temporary | ||
| 20547 | ); | ||
| 20548 | |||
| 20549 | return 1; | ||
| 20550 | } | ||
| 20551 | } | ||
| 20552 | |||
| 20553 | sub buttonDelete_tts { | ||
| 20554 | |||
| 20555 | # Callback: Deletes a TTS configuration (equivalent to ';deleteconfig') | ||
| 20556 | # | ||
| 20557 | # Expected arguments | ||
| 20558 | # (none besides $self) | ||
| 20559 | # | ||
| 20560 | # Return values | ||
| 20561 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 20562 | # 1 otherwise | ||
| 20563 | |||
| 20564 | my ($self, $check) = @_; | ||
| 20565 | |||
| 20566 | # Local variables | ||
| 20567 | my ( | ||
| 20568 | $dataRef, $name, | ||
| 20569 | @list, @dataList, | ||
| 20570 | ); | ||
| 20571 | |||
| 20572 | # Check for improper arguments | ||
| 20573 | if (defined $check) { | ||
| 20574 | |||
| 20575 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_tts', @_); | ||
| 20576 | } | ||
| 20577 | |||
| 20578 | # Import the currently selected portions of the notebook list | ||
| 20579 | @list = $self->notebookGetSelectedData(); | ||
| 20580 | if (! @list) { | ||
| 20581 | |||
| 20582 | # Nothing selected | ||
| 20583 | return undef; | ||
| 20584 | } | ||
| 20585 | |||
| 20586 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20587 | # a single row of the list | ||
| 20588 | $dataRef = $list[0]; | ||
| 20589 | @dataList = @$dataRef; | ||
| 20590 | # The TTS configuration name is the first item of data | ||
| 20591 | $name = $dataList[0]; | ||
| 20592 | if (! $name) { | ||
| 20593 | |||
| 20594 | # Can't continue | ||
| 20595 | return undef; | ||
| 20596 | } | ||
| 20597 | |||
| 20598 | # Delete the TTS configuration | ||
| 20599 | $self->session->pseudoCmd('deleteconfig ' . $name, $self->pseudoCmdMode); | ||
| 20600 | |||
| 20601 | # Update the notebook | ||
| 20602 | $self->updateNotebook(); | ||
| 20603 | |||
| 20604 | return 1; | ||
| 20605 | } | ||
| 20606 | |||
| 20607 | sub buttonDump_tts { | ||
| 20608 | |||
| 20609 | # Callback: Displays a list of TTS configurations in the 'main' window (equivalent to | ||
| 20610 | # ';listconfig') | ||
| 20611 | # | ||
| 20612 | # Expected arguments | ||
| 20613 | # (none besides $self) | ||
| 20614 | # | ||
| 20615 | # Return values | ||
| 20616 | # 'undef' on improper arguments | ||
| 20617 | # 1 otherwise | ||
| 20618 | |||
| 20619 | my ($self, $check) = @_; | ||
| 20620 | |||
| 20621 | # Local variables | ||
| 20622 | my ($tab, $slWidget); | ||
| 20623 | |||
| 20624 | # Check for improper arguments | ||
| 20625 | if (defined $check) { | ||
| 20626 | |||
| 20627 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_tts', @_); | ||
| 20628 | } | ||
| 20629 | |||
| 20630 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20631 | $tab = $self->notebookGetTab(); | ||
| 20632 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20633 | |||
| 20634 | # Unselect everything in the list | ||
| 20635 | $slWidget->get_selection->unselect_all(); | ||
| 20636 | |||
| 20637 | # Display the list | ||
| 20638 | $self->session->pseudoCmd('listconfig', $self->pseudoCmdMode); | ||
| 20639 | |||
| 20640 | return 1; | ||
| 20641 | } | ||
| 20642 | |||
| 20643 | # Winmap button callbacks | ||
| 20644 | |||
| 20645 | sub buttonAdd_winmap { | ||
| 20646 | |||
| 20647 | # Callback: Add a winmap (equivalent to ';addwinmap') | ||
| 20648 | # | ||
| 20649 | # Expected arguments | ||
| 20650 | # (none besides $self) | ||
| 20651 | # | ||
| 20652 | # Return values | ||
| 20653 | # 'undef' on improper arguments | ||
| 20654 | # 1 otherwise | ||
| 20655 | |||
| 20656 | my ($self, $check) = @_; | ||
| 20657 | |||
| 20658 | # Local variables | ||
| 20659 | my ($tab, $slWidget, $name); | ||
| 20660 | |||
| 20661 | # Check for improper arguments | ||
| 20662 | if (defined $check) { | ||
| 20663 | |||
| 20664 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_winmap', @_); | ||
| 20665 | } | ||
| 20666 | |||
| 20667 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20668 | $tab = $self->notebookGetTab(); | ||
| 20669 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20670 | |||
| 20671 | # Unselect everything in the list, because we're creating a new winmap | ||
| 20672 | $slWidget->get_selection->unselect_all(); | ||
| 20673 | |||
| 20674 | # Prompt the user for the name of the winmap | ||
| 20675 | $name = $self->showEntryDialogue( | ||
| 20676 | 'Add winmap', | ||
| 20677 | 'Enter a name for the object (max 16 chars: A-Z a-z _ 0-9)', | ||
| 20678 | 16, # Max chars | ||
| 20679 | ); | ||
| 20680 | |||
| 20681 | if ($name) { | ||
| 20682 | |||
| 20683 | # Add the new winmap | ||
| 20684 | $self->session->pseudoCmd('addwinmap ' . $name, $self->pseudoCmdMode); | ||
| 20685 | |||
| 20686 | # Update the notebook | ||
| 20687 | $self->updateNotebook(); | ||
| 20688 | } | ||
| 20689 | |||
| 20690 | return 1; | ||
| 20691 | } | ||
| 20692 | |||
| 20693 | sub buttonClone_winmap { | ||
| 20694 | |||
| 20695 | # Callback: Clones the selected winmap (equivalent to ';clonewinmap') | ||
| 20696 | # | ||
| 20697 | # Expected arguments | ||
| 20698 | # (none besides $self) | ||
| 20699 | # | ||
| 20700 | # Return values | ||
| 20701 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 20702 | # 1 otherwise | ||
| 20703 | |||
| 20704 | my ($self, $check) = @_; | ||
| 20705 | |||
| 20706 | # Local variables | ||
| 20707 | my ( | ||
| 20708 | $dataRef, $name, $cloneName, | ||
| 20709 | @list, @dataList, | ||
| 20710 | ); | ||
| 20711 | |||
| 20712 | # Check for improper arguments | ||
| 20713 | if (defined $check) { | ||
| 20714 | |||
| 20715 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonClone_winmap', @_); | ||
| 20716 | } | ||
| 20717 | |||
| 20718 | # Import the currently selected portions of the notebook list | ||
| 20719 | @list = $self->notebookGetSelectedData(); | ||
| 20720 | if (! @list) { | ||
| 20721 | |||
| 20722 | # Nothing selected | ||
| 20723 | return undef; | ||
| 20724 | } | ||
| 20725 | |||
| 20726 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20727 | # a single row of the list | ||
| 20728 | $dataRef = $list[0]; | ||
| 20729 | @dataList = @$dataRef; | ||
| 20730 | # The winmap object name is the third item of data | ||
| 20731 | $name = $dataList[2]; | ||
| 20732 | if (! $name) { | ||
| 20733 | |||
| 20734 | # Can't continue | ||
| 20735 | return undef; | ||
| 20736 | } | ||
| 20737 | |||
| 20738 | # Prompt the user for the name of the clone | ||
| 20739 | $cloneName = $self->showEntryDialogue( | ||
| 20740 | 'Clone winmap', | ||
| 20741 | 'Enter a name for the clone (max 16 chars: A-Z a-z _ 0-9)', | ||
| 20742 | 16, # Max chars | ||
| 20743 | ); | ||
| 20744 | |||
| 20745 | if ($cloneName) { | ||
| 20746 | |||
| 20747 | # Clone the winmap | ||
| 20748 | $self->session->pseudoCmd( | ||
| 20749 | 'clonewinmap ' . $name . ' ' . $cloneName, | ||
| 20750 | $self->pseudoCmdMode, | ||
| 20751 | ); | ||
| 20752 | |||
| 20753 | # Update the notebook | ||
| 20754 | $self->updateNotebook(); | ||
| 20755 | } | ||
| 20756 | |||
| 20757 | return 1; | ||
| 20758 | } | ||
| 20759 | |||
| 20760 | sub buttonEdit_winmap { | ||
| 20761 | |||
| 20762 | # Callback: Edits a winmap (equivalent to ';editwinmap') | ||
| 20763 | # | ||
| 20764 | # Expected arguments | ||
| 20765 | # (none besides $self) | ||
| 20766 | # | ||
| 20767 | # Return values | ||
| 20768 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 20769 | # object no longer exists | ||
| 20770 | # 1 otherwise | ||
| 20771 | |||
| 20772 | my ($self, $check) = @_; | ||
| 20773 | |||
| 20774 | # Local variables | ||
| 20775 | my ( | ||
| 20776 | $dataRef, $name, $obj, | ||
| 20777 | @list, @dataList, | ||
| 20778 | ); | ||
| 20779 | |||
| 20780 | # Check for improper arguments | ||
| 20781 | if (defined $check) { | ||
| 20782 | |||
| 20783 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_winmap', @_); | ||
| 20784 | } | ||
| 20785 | |||
| 20786 | # Import the currently selected portions of the notebook list | ||
| 20787 | @list = $self->notebookGetSelectedData(); | ||
| 20788 | if (! @list) { | ||
| 20789 | |||
| 20790 | # Nothing selected | ||
| 20791 | return undef; | ||
| 20792 | } | ||
| 20793 | |||
| 20794 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20795 | # a single row of the list | ||
| 20796 | $dataRef = $list[0]; | ||
| 20797 | @dataList = @$dataRef; | ||
| 20798 | # The winmap's name is the third item of data | ||
| 20799 | $name = $dataList[2]; | ||
| 20800 | if (! $name) { | ||
| 20801 | |||
| 20802 | # Can't continue | ||
| 20803 | return undef; | ||
| 20804 | } | ||
| 20805 | |||
| 20806 | # Get the winmap itself | ||
| 20807 | $obj = $axmud::CLIENT->ivShow('winmapHash', $name); | ||
| 20808 | if (! $obj) { | ||
| 20809 | |||
| 20810 | # Can't continue | ||
| 20811 | return undef; | ||
| 20812 | |||
| 20813 | } else { | ||
| 20814 | |||
| 20815 | # Open up an 'edit' window to edit the object | ||
| 20816 | $self->createFreeWin( | ||
| 20817 | 'Games::Axmud::EditWin::Winmap', | ||
| 20818 | $self, | ||
| 20819 | $self->session, | ||
| 20820 | 'Edit winmap \'' . $obj->name . '\'', | ||
| 20821 | $obj, | ||
| 20822 | FALSE, # Not temporary | ||
| 20823 | ); | ||
| 20824 | |||
| 20825 | return 1; | ||
| 20826 | } | ||
| 20827 | } | ||
| 20828 | |||
| 20829 | sub buttonDelete_winmap { | ||
| 20830 | |||
| 20831 | # Callback: Deletes a winmap (equivalent to ';deletewinmap') | ||
| 20832 | # | ||
| 20833 | # Expected arguments | ||
| 20834 | # (none besides $self) | ||
| 20835 | # | ||
| 20836 | # Return values | ||
| 20837 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 20838 | # 1 otherwise | ||
| 20839 | |||
| 20840 | my ($self, $check) = @_; | ||
| 20841 | |||
| 20842 | # Local variables | ||
| 20843 | my ( | ||
| 20844 | $dataRef, $name, | ||
| 20845 | @list, @dataList, | ||
| 20846 | ); | ||
| 20847 | |||
| 20848 | # Check for improper arguments | ||
| 20849 | if (defined $check) { | ||
| 20850 | |||
| 20851 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_winmap', @_); | ||
| 20852 | } | ||
| 20853 | |||
| 20854 | # Import the currently selected portions of the notebook list | ||
| 20855 | @list = $self->notebookGetSelectedData(); | ||
| 20856 | if (! @list) { | ||
| 20857 | |||
| 20858 | # Nothing selected | ||
| 20859 | return undef; | ||
| 20860 | } | ||
| 20861 | |||
| 20862 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 20863 | # a single row of the list | ||
| 20864 | $dataRef = $list[0]; | ||
| 20865 | @dataList = @$dataRef; | ||
| 20866 | # The winmap name is the third item of data | ||
| 20867 | $name = $dataList[2]; | ||
| 20868 | if (! $name) { | ||
| 20869 | |||
| 20870 | # Can't continue | ||
| 20871 | return undef; | ||
| 20872 | } | ||
| 20873 | |||
| 20874 | # Delete the winmap | ||
| 20875 | $self->session->pseudoCmd('deletewinmap ' . $name, $self->pseudoCmdMode); | ||
| 20876 | |||
| 20877 | # Update the notebook | ||
| 20878 | $self->updateNotebook(); | ||
| 20879 | |||
| 20880 | return 1; | ||
| 20881 | } | ||
| 20882 | |||
| 20883 | sub buttonDump_winmap { | ||
| 20884 | |||
| 20885 | # Callback: Displays a list of winmaps in the 'main' window (equivalent to ';listwinmap') | ||
| 20886 | # | ||
| 20887 | # Expected arguments | ||
| 20888 | # (none besides $self) | ||
| 20889 | # | ||
| 20890 | # Return values | ||
| 20891 | # 'undef' on improper arguments | ||
| 20892 | # 1 otherwise | ||
| 20893 | |||
| 20894 | my ($self, $check) = @_; | ||
| 20895 | |||
| 20896 | # Local variables | ||
| 20897 | my ($tab, $slWidget); | ||
| 20898 | |||
| 20899 | # Check for improper arguments | ||
| 20900 | if (defined $check) { | ||
| 20901 | |||
| 20902 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_winmap', @_); | ||
| 20903 | } | ||
| 20904 | |||
| 20905 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20906 | $tab = $self->notebookGetTab(); | ||
| 20907 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20908 | |||
| 20909 | # Unselect everything in the list | ||
| 20910 | $slWidget->get_selection->unselect_all(); | ||
| 20911 | |||
| 20912 | # Display the list | ||
| 20913 | $self->session->pseudoCmd('listwinmap', $self->pseudoCmdMode); | ||
| 20914 | |||
| 20915 | return 1; | ||
| 20916 | } | ||
| 20917 | |||
| 20918 | # Zonemap button callbacks | ||
| 20919 | |||
| 20920 | sub buttonAdd_zonemap { | ||
| 20921 | |||
| 20922 | # Callback: Add a zonemap (equivalent to ';addzonemap') | ||
| 20923 | # | ||
| 20924 | # Expected arguments | ||
| 20925 | # (none besides $self) | ||
| 20926 | # | ||
| 20927 | # Return values | ||
| 20928 | # 'undef' on improper arguments | ||
| 20929 | # 1 otherwise | ||
| 20930 | |||
| 20931 | my ($self, $check) = @_; | ||
| 20932 | |||
| 20933 | # Local variables | ||
| 20934 | my ($tab, $slWidget, $name); | ||
| 20935 | |||
| 20936 | # Check for improper arguments | ||
| 20937 | if (defined $check) { | ||
| 20938 | |||
| 20939 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonAdd_zonemap', @_); | ||
| 20940 | } | ||
| 20941 | |||
| 20942 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 20943 | $tab = $self->notebookGetTab(); | ||
| 20944 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 20945 | |||
| 20946 | # Unselect everything in the list, because we're creating a new zonemap | ||
| 20947 | $slWidget->get_selection->unselect_all(); | ||
| 20948 | |||
| 20949 | # Prompt the user for the name of the zonemap | ||
| 20950 | $name = $self->showEntryDialogue( | ||
| 20951 | 'Add zonemap', | ||
| 20952 | 'Enter a name for the object (max 16 chars: A-Z a-z _ 0-9)', | ||
| 20953 | 16, # Max chars | ||
| 20954 | ); | ||
| 20955 | |||
| 20956 | if ($name) { | ||
| 20957 | |||
| 20958 | # Add the new zonemap | ||
| 20959 | $self->session->pseudoCmd('addzonemap ' . $name, $self->pseudoCmdMode); | ||
| 20960 | |||
| 20961 | # Update the notebook | ||
| 20962 | $self->updateNotebook(); | ||
| 20963 | } | ||
| 20964 | |||
| 20965 | return 1; | ||
| 20966 | } | ||
| 20967 | |||
| 20968 | sub buttonClone_zonemap { | ||
| 20969 | |||
| 20970 | # Callback: Clones the selected zonemap (equivalent to ';clonezonemap') | ||
| 20971 | # | ||
| 20972 | # Expected arguments | ||
| 20973 | # (none besides $self) | ||
| 20974 | # | ||
| 20975 | # Return values | ||
| 20976 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 20977 | # 1 otherwise | ||
| 20978 | |||
| 20979 | my ($self, $check) = @_; | ||
| 20980 | |||
| 20981 | # Local variables | ||
| 20982 | my ( | ||
| 20983 | $dataRef, $name, $cloneName, | ||
| 20984 | @list, @dataList, | ||
| 20985 | ); | ||
| 20986 | |||
| 20987 | # Check for improper arguments | ||
| 20988 | if (defined $check) { | ||
| 20989 | |||
| 20990 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonClone_zonemap', @_); | ||
| 20991 | } | ||
| 20992 | |||
| 20993 | # Import the currently selected portions of the notebook list | ||
| 20994 | @list = $self->notebookGetSelectedData(); | ||
| 20995 | if (! @list) { | ||
| 20996 | |||
| 20997 | # Nothing selected | ||
| 20998 | return undef; | ||
| 20999 | } | ||
| 21000 | |||
| 21001 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 21002 | # a single row of the list | ||
| 21003 | $dataRef = $list[0]; | ||
| 21004 | @dataList = @$dataRef; | ||
| 21005 | # The zonemap object name is the fourth item of data | ||
| 21006 | $name = $dataList[3]; | ||
| 21007 | if (! $name) { | ||
| 21008 | |||
| 21009 | # Can't continue | ||
| 21010 | return undef; | ||
| 21011 | } | ||
| 21012 | |||
| 21013 | # Prompt the user for the name of the clone | ||
| 21014 | $cloneName = $self->showEntryDialogue( | ||
| 21015 | 'Clone zonemap', | ||
| 21016 | 'Enter a name for the clone (max 16 chars: A-Z a-z _ 0-9)', | ||
| 21017 | 16, # Max chars | ||
| 21018 | ); | ||
| 21019 | |||
| 21020 | if ($cloneName) { | ||
| 21021 | |||
| 21022 | # Clone the zonemap | ||
| 21023 | $self->session->pseudoCmd( | ||
| 21024 | 'clonezonemap ' . $name . ' ' . $cloneName, | ||
| 21025 | $self->pseudoCmdMode, | ||
| 21026 | ); | ||
| 21027 | |||
| 21028 | # Update the notebook | ||
| 21029 | $self->updateNotebook(); | ||
| 21030 | } | ||
| 21031 | |||
| 21032 | return 1; | ||
| 21033 | } | ||
| 21034 | |||
| 21035 | sub buttonEdit_zonemap { | ||
| 21036 | |||
| 21037 | # Callback: Edits a zonemap (equivalent to ';editzonemap') | ||
| 21038 | # | ||
| 21039 | # Expected arguments | ||
| 21040 | # (none besides $self) | ||
| 21041 | # | ||
| 21042 | # Return values | ||
| 21043 | # 'undef' on improper arguments, if no line is selected in the notebook or if the selected | ||
| 21044 | # object no longer exists | ||
| 21045 | # 1 otherwise | ||
| 21046 | |||
| 21047 | my ($self, $check) = @_; | ||
| 21048 | |||
| 21049 | # Local variables | ||
| 21050 | my ( | ||
| 21051 | $dataRef, $name, $obj, | ||
| 21052 | @list, @dataList, | ||
| 21053 | ); | ||
| 21054 | |||
| 21055 | # Check for improper arguments | ||
| 21056 | if (defined $check) { | ||
| 21057 | |||
| 21058 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonEdit_zonemap', @_); | ||
| 21059 | } | ||
| 21060 | |||
| 21061 | # Import the currently selected portions of the notebook list | ||
| 21062 | @list = $self->notebookGetSelectedData(); | ||
| 21063 | if (! @list) { | ||
| 21064 | |||
| 21065 | # Nothing selected | ||
| 21066 | return undef; | ||
| 21067 | } | ||
| 21068 | |||
| 21069 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 21070 | # a single row of the list | ||
| 21071 | $dataRef = $list[0]; | ||
| 21072 | @dataList = @$dataRef; | ||
| 21073 | # The zonemap's name is the fourth item of data | ||
| 21074 | $name = $dataList[3]; | ||
| 21075 | if (! $name) { | ||
| 21076 | |||
| 21077 | # Can't continue | ||
| 21078 | return undef; | ||
| 21079 | } | ||
| 21080 | |||
| 21081 | # Get the zonemap itself | ||
| 21082 | $obj = $axmud::CLIENT->ivShow('zonemapHash', $name); | ||
| 21083 | if (! $obj) { | ||
| 21084 | |||
| 21085 | # Can't continue | ||
| 21086 | return undef; | ||
| 21087 | |||
| 21088 | } else { | ||
| 21089 | |||
| 21090 | # Open up an 'edit' window to edit the object | ||
| 21091 | $self->createFreeWin( | ||
| 21092 | 'Games::Axmud::EditWin::Zonemap', | ||
| 21093 | $self, | ||
| 21094 | $self->session, | ||
| 21095 | 'Edit zonemap \'' . $obj->name . '\'', | ||
| 21096 | $obj, | ||
| 21097 | FALSE, # Not temporary | ||
| 21098 | ); | ||
| 21099 | |||
| 21100 | return 1; | ||
| 21101 | } | ||
| 21102 | } | ||
| 21103 | |||
| 21104 | sub buttonDelete_zonemap { | ||
| 21105 | |||
| 21106 | # Callback: Deletes a zonemap (equivalent to ';deletezonemap') | ||
| 21107 | # | ||
| 21108 | # Expected arguments | ||
| 21109 | # (none besides $self) | ||
| 21110 | # | ||
| 21111 | # Return values | ||
| 21112 | # 'undef' on improper arguments or if no line is selected in the notebook | ||
| 21113 | # 1 otherwise | ||
| 21114 | |||
| 21115 | my ($self, $check) = @_; | ||
| 21116 | |||
| 21117 | # Local variables | ||
| 21118 | my ( | ||
| 21119 | $dataRef, $name, | ||
| 21120 | @list, @dataList, | ||
| 21121 | ); | ||
| 21122 | |||
| 21123 | # Check for improper arguments | ||
| 21124 | if (defined $check) { | ||
| 21125 | |||
| 21126 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDelete_zonemap', @_); | ||
| 21127 | } | ||
| 21128 | |||
| 21129 | # Import the currently selected portions of the notebook list | ||
| 21130 | @list = $self->notebookGetSelectedData(); | ||
| 21131 | if (! @list) { | ||
| 21132 | |||
| 21133 | # Nothing selected | ||
| 21134 | return undef; | ||
| 21135 | } | ||
| 21136 | |||
| 21137 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 21138 | # a single row of the list | ||
| 21139 | $dataRef = $list[0]; | ||
| 21140 | @dataList = @$dataRef; | ||
| 21141 | # The zonemap name is the fourth item of data | ||
| 21142 | $name = $dataList[3]; | ||
| 21143 | if (! $name) { | ||
| 21144 | |||
| 21145 | # Can't continue | ||
| 21146 | return undef; | ||
| 21147 | } | ||
| 21148 | |||
| 21149 | # Delete the zonemap | ||
| 21150 | $self->session->pseudoCmd('deletezonemap ' . $name, $self->pseudoCmdMode); | ||
| 21151 | |||
| 21152 | # Update the notebook | ||
| 21153 | $self->updateNotebook(); | ||
| 21154 | |||
| 21155 | return 1; | ||
| 21156 | } | ||
| 21157 | |||
| 21158 | sub buttonDump_zonemap { | ||
| 21159 | |||
| 21160 | # Callback: Displays a list of zonemaps in the 'main' window (equivalent to ';listzonemap') | ||
| 21161 | # | ||
| 21162 | # Expected arguments | ||
| 21163 | # (none besides $self) | ||
| 21164 | # | ||
| 21165 | # Return values | ||
| 21166 | # 'undef' on improper arguments | ||
| 21167 | # 1 otherwise | ||
| 21168 | |||
| 21169 | my ($self, $check) = @_; | ||
| 21170 | |||
| 21171 | # Local variables | ||
| 21172 | my ($tab, $slWidget); | ||
| 21173 | |||
| 21174 | # Check for improper arguments | ||
| 21175 | if (defined $check) { | ||
| 21176 | |||
| 21177 | return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonDump_zonemap', @_); | ||
| 21178 | } | ||
| 21179 | |||
| 21180 | # Get the selected tab, and from there the tab's GA::Obj::SimpleList | ||
| 21181 | $tab = $self->notebookGetTab(); | ||
| 21182 | $slWidget = $self->ivShow('notebookDataHash', $tab); | ||
| 21183 | |||
| 21184 | # Unselect everything in the list | ||
| 21185 | $slWidget->get_selection->unselect_all(); | ||
| 21186 | |||
| 21187 | # Display the list | ||
| 21188 | $self->session->pseudoCmd('listzonemap', $self->pseudoCmdMode); | ||
| 21189 | |||
| 21190 | return 1; | ||
| 21191 | } | ||
| 21192 | |||
| 21193 | # Callback support functions | ||
| 21194 | |||
| 21195 | sub profPriorityData { | ||
| 21196 | |||
| 21197 | # Called by $self->buttonMoveTop_profPriority, $self->buttonMoveUp_profPriority, etc | ||
| 21198 | # Works out which part of the currrent notebook's GA::Obj::SimpleList is selected and | ||
| 21199 | # accesses the data on the selected row | ||
| 21200 | # | ||
| 21201 | # Expected arguments | ||
| 21202 | # (none besides $self) | ||
| 21203 | # | ||
| 21204 | # Return values | ||
| 21205 | # An empty list on improper arguments or if no row is selected | ||
| 21206 | # Otherwise returns a list containing three arguments: | ||
| 21207 | # $count - The position of the category within the current priority list, | ||
| 21208 | # $self->session->profPriorityList (or 'undef' if the category is not | ||
| 21209 | # in the priority list) | ||
| 21210 | # $priority - The priority of the category on the selected line (1+, or '-' for not | ||
| 21211 | # in the priority list) | ||
| 21212 | # $category - The category on the selected line | ||
| 21213 | |||
| 21214 | my ($self, $check) = @_; | ||
| 21215 | |||
| 21216 | # Local variables | ||
| 21217 | my ( | ||
| 21218 | $dataRef, $priority, $category, $count, | ||
| 21219 | @emptyList, @list, @dataList, | ||
| 21220 | ); | ||
| 21221 | |||
| 21222 | # Check for improper arguments | ||
| 21223 | if (defined $check) { | ||
| 21224 | |||
| 21225 | $axmud::CLIENT->writeImproper($self->_objClass . '->profPriorityData', @_); | ||
| 21226 | return @emptyList; | ||
| 21227 | } | ||
| 21228 | |||
| 21229 | # Import the currently selected portions of the notebook list | ||
| 21230 | @list = $self->notebookGetSelectedData(); | ||
| 21231 | if (! @list) { | ||
| 21232 | |||
| 21233 | # Nothing selected | ||
| 21234 | return @emptyList; | ||
| 21235 | } | ||
| 21236 | |||
| 21237 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 21238 | # a single row of the list | ||
| 21239 | $dataRef = $list[0]; | ||
| 21240 | @dataList = @$dataRef; | ||
| 21241 | # The current priority (if any) is the first item of data | ||
| 21242 | $priority = $dataList[0]; | ||
| 21243 | # The selected category is the second item of data | ||
| 21244 | $category = $dataList[1]; | ||
| 21245 | |||
| 21246 | # Can't continue if either is unavailable, or if the selected category isn't on the priority | ||
| 21247 | # list yet (use the 'give priority' button instead) | ||
| 21248 | if (! $priority || ! $category) { | ||
| 21249 | |||
| 21250 | # Can't continue | ||
| 21251 | return @emptyList; | ||
| 21252 | |||
| 21253 | } elsif ($priority eq '-') { | ||
| 21254 | |||
| 21255 | # Category isn't in the current priority list | ||
| 21256 | return (undef, $priority, $category); | ||
| 21257 | } | ||
| 21258 | |||
| 21259 | # Import the priority list; check that $category is somewhere to be found within it | ||
| 21260 | $count = -1; | ||
| 21261 | foreach my $item ($self->session->profPriorityList) { | ||
| 21262 | |||
| 21263 | $count++; | ||
| 21264 | |||
| 21265 | if ($category eq $item) { | ||
| 21266 | |||
| 21267 | return ($count, $priority, $category); | ||
| 21268 | } | ||
| 21269 | } | ||
| 21270 | |||
| 21271 | # Category not found (this shouldn't happen unless the IV has been modified, since the | ||
| 21272 | # window last updated its simple list) | ||
| 21273 | return @emptyList; | ||
| 21274 | } | ||
| 21275 | |||
| 21276 | sub initialTaskData { | ||
| 21277 | |||
| 21278 | # Called by $self->buttonMoveUp_initialTask and $self->buttonMoveUp_profPriority | ||
| 21279 | # Works out which part of the currrent notebook's GA::Obj::SimpleList is selected and | ||
| 21280 | # accesses the data on the selected row | ||
| 21281 | # | ||
| 21282 | # Expected arguments | ||
| 21283 | # (none besides $self) | ||
| 21284 | # | ||
| 21285 | # Return values | ||
| 21286 | # An empty list on improper arguments or if no row is selected | ||
| 21287 | # Otherwise returns a list containing two arguments: | ||
| 21288 | # $count - The position of the category within the current priority list, | ||
| 21289 | # $self->session->profPriorityList (or 'undef' if the category is not | ||
| 21290 | # in the priority list) | ||
| 21291 | # $priority - The priority of the category on the selected line (1+, or '-' for not | ||
| 21292 | # in the priority list) | ||
| 21293 | # $category - The category on the selected line | ||
| 21294 | |||
| 21295 | my ($self, $check) = @_; | ||
| 21296 | |||
| 21297 | # Local variables | ||
| 21298 | my ( | ||
| 21299 | $dataRef, $taskName, $count, | ||
| 21300 | @emptyList, @list, @dataList, | ||
| 21301 | ); | ||
| 21302 | |||
| 21303 | # Check for improper arguments | ||
| 21304 | if (defined $check) { | ||
| 21305 | |||
| 21306 | $axmud::CLIENT->writeImproper($self->_objClass . '->profPriorityData', @_); | ||
| 21307 | return @emptyList; | ||
| 21308 | } | ||
| 21309 | |||
| 21310 | # Import the currently selected portions of the notebook list | ||
| 21311 | @list = $self->notebookGetSelectedData(); | ||
| 21312 | if (! @list) { | ||
| 21313 | |||
| 21314 | # Nothing selected | ||
| 21315 | return @emptyList; | ||
| 21316 | } | ||
| 21317 | |||
| 21318 | # @list is a list of references to anonymous lists; each of these anonymous lists contains | ||
| 21319 | # a single row of the list | ||
| 21320 | $dataRef = $list[0]; | ||
| 21321 | @dataList = @$dataRef; | ||
| 21322 | # The selected initial task is the first item of data | ||
| 21323 | $taskName = $dataList[0]; | ||
| 21324 | if (! defined $taskName) { | ||
| 21325 | |||
| 21326 | return @emptyList; | ||
| 21327 | } | ||
| 21328 | |||
| 21329 | # Import the ordered list of global initial tasks; check that $taskName is somewhere to be | ||
| 21330 | # found within it | ||
| 21331 | $count = -1; | ||
| 21332 | foreach my $item ($axmud::CLIENT->initTaskOrderList) { | ||
| 21333 | |||
| 21334 | $count++; | ||
| 21335 | |||
| 21336 | if ($taskName eq $item) { | ||
| 21337 | |||
| 21338 | return ($count, $taskName); | ||
| 21339 | } | ||
| 21340 | } | ||
| 21341 | |||
| 21342 | # Task not found (this shouldn't happen unless the IV has been modified, since the | ||
| 21343 | # window last updated its simple list) | ||
| 21344 | return @emptyList; | ||
| 21345 | } | ||
| 21346 | |||
| 21347 | ################## | ||
| 21348 | # Accessors - set | ||
| 21349 | |||
| 21350 | ################## | ||
| 21351 | # Accessors - get | ||
| 21352 | |||
| 21353 | sub hPaned | ||
| 21354 | { $_[0]->{hPaned} } | ||
| 21355 | sub treeViewModel | ||
| 21356 | { $_[0]->{treeViewModel} } | ||
| 21357 | sub treeView | ||
| 21358 | { $_[0]->{treeView} } | ||
| 21359 | sub treeViewScroller | ||
| 21360 | { $_[0]->{treeViewScroller} } | ||
| 21361 | sub hPaned2 | ||
| 21362 | { $_[0]->{hPaned2} } | ||
| 21363 | sub notebook | ||
| 21364 | { $_[0]->{notebook} } | ||
| 21365 | sub vBox | ||
| 21366 | { $_[0]->{vBox} } | ||
| 21367 | sub buttonList | ||
| 21368 | { my $self = shift; return @{$self->{buttonList}}; } | ||
| 21369 | |||
| 21370 | sub leftWidth | ||
| 21371 | { $_[0]->{leftWidth} } | ||
| 21372 | sub centreWidth | ||
| 21373 | { $_[0]->{centreWidth} } | ||
| 21374 | sub rightWidth | ||
| 21375 | { $_[0]->{rightWidth} } | ||
| 21376 | |||
| 21377 | sub notebookMode | ||
| 21378 | { $_[0]->{notebookMode} } | ||
| 21379 | sub notebookCurrentHeader | ||
| 21380 | { $_[0]->{notebookCurrentHeader} } | ||
| 21381 | sub notebookSelectRef | ||
| 21382 | { $_[0]->{notebookSelectRef} } | ||
| 21383 | |||
| 21384 | sub headerHash | ||
| 21385 | { my $self = shift; return %{$self->{headerHash}}; } | ||
| 21386 | |||
| 21387 | sub notebookTabList | ||
| 21388 | { my $self = shift; return @{$self->{notebookTabList}}; } | ||
| 21389 | sub notebookTabHash | ||
| 21390 | { my $self = shift; return %{$self->{notebookTabHash}}; } | ||
| 21391 | sub notebookDataHash | ||
| 21392 | { my $self = shift; return %{$self->{notebookDataHash}}; } | ||
| 21393 | |||
| 21394 | sub dummyScriptObj | ||
| 21395 | { $_[0]->{dummyScriptObj} } | ||
| 21396 | } | ||
| 21397 | |||
| 21398 | # Package must return a true value | ||
| 21399 | 1 |