| 1 | # Copyright (C) 2011-2024 A S Lewis | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify it under the terms of the GNU | ||
| 4 | # General Public License as published by the Free Software Foundation, either version 3 of the | ||
| 5 | # License, or (at your option) any later version. | ||
| 6 | # | ||
| 7 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| 8 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 9 | # General Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU General Public License along with this program. If not, | ||
| 12 | # see <http://www.gnu.org/licenses/>. | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # Games::Axmud::Obj::WorkspaceGrid | ||
| 16 | # The workspace grid object, on which windows on a single workspace are arranged | ||
| 17 | |||
| 18 | { package Games::Axmud::Obj::WorkspaceGrid; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | # use diagnostics; | ||
| 23 | |||
| 24 | use Glib qw(TRUE FALSE); | ||
| 25 | |||
| 26 | our @ISA = qw(Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Called by GA::Obj::Desktop->add_grid() if the parent workspace object's ->gridEnableFlag | ||
| 34 | # is TRUE ('grid' windows are not arranged on a workspace grid if FALSE) | ||
| 35 | # | ||
| 36 | # Expected arguments | ||
| 37 | # $number - Number for this workspace grid object, unique to its workspace | ||
| 38 | # $workspaceObj - The GA::Obj::Workspace object for the workspace on which this | ||
| 39 | # workspace grid is displayed | ||
| 40 | # | ||
| 41 | # Optional arguments | ||
| 42 | # $owner - (GA::Client->shareMainWinFlag = TRUE) The GA::Session object which | ||
| 43 | # controls this workspace grid | ||
| 44 | # - (GA::Client->shareMainWinFlag = FALSE) 'undef' (the grid is shared | ||
| 45 | # between all sessions) | ||
| 46 | # | ||
| 47 | # Return values | ||
| 48 | # 'undef' on improper arguments | ||
| 49 | # Blessed reference to the newly-created object on success | ||
| 50 | |||
| 51 | my ($class, $number, $workspaceObj, $owner, $check) = @_; | ||
| 52 | |||
| 53 | # Check for improper arguments | ||
| 54 | if (! defined $class || ! defined $number || ! defined $workspaceObj || defined $check) { | ||
| 55 | |||
| 56 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 57 | } | ||
| 58 | |||
| 59 | # Setup | ||
| 60 | my $self = { | ||
| 61 | _objName => 'workspace_grid_' . $number, | ||
| 62 | _objClass => $class, | ||
| 63 | _parentFile => undef, # No parent file object | ||
| 64 | _parentWorld => undef, # No parent file object | ||
| 65 | _privFlag => TRUE, # All IVs are private | ||
| 66 | |||
| 67 | # IVs | ||
| 68 | # --- | ||
| 69 | |||
| 70 | # Number for this workspace grid object, unique to its workspace | ||
| 71 | number => $number, | ||
| 72 | # The GA::Obj::Workspace object for the workspace on which this workspace grid is | ||
| 73 | # displayed | ||
| 74 | workspaceObj => $workspaceObj, | ||
| 75 | # (GA::Client->shareMainWinFlag = TRUE) The GA::Session object which controls this | ||
| 76 | # workspace grid | ||
| 77 | # (GA::Client->shareMainWinFlag = FALSE) 'undef' (the grid is shared between all | ||
| 78 | # sessions) | ||
| 79 | owner => $owner, | ||
| 80 | |||
| 81 | # The name of the zonemap used by this workspace grid to create zones | ||
| 82 | zonemap => undef, | ||
| 83 | |||
| 84 | # Maximum number of layers in this workspace grid | ||
| 85 | maxLayers => 16, | ||
| 86 | # The default layer in this workspace grid for new windows (a number from 0 to | ||
| 87 | # ($self->maxLayers - 1) ) | ||
| 88 | defaultLayer => 0, # The bottom layer | ||
| 89 | # The currently visible layer ('undef' if not set yet) | ||
| 90 | currentLayer => undef, | ||
| 91 | |||
| 92 | # The size of this grid, in gridblocks, once it's been set up (the size of the whole | ||
| 93 | # workspace, minus any areas used by panels/taskbars) | ||
| 94 | widthBlocks => undef, | ||
| 95 | heightBlocks => undef, | ||
| 96 | # The coordinates of the top-left pixel of the workspace grid on the workspace - must be | ||
| 97 | # added to a window's actual coordinates on the workspace whenever the window is | ||
| 98 | # created, resized or moved (if there are no panels to the top and to the left, both | ||
| 99 | # set to 0) | ||
| 100 | xPosPixels => undef, | ||
| 101 | yPosPixels => undef, | ||
| 102 | |||
| 103 | # The workspace grid itself covers the whole available workspace (minus any panels, | ||
| 104 | # etc). | ||
| 105 | # It consists of a hash of zone objects (GA::Obj::Zone), each of which defines a zone | ||
| 106 | # of the grid into which one or more windows can be inserted. The 'plan' by which the | ||
| 107 | # workspace grid is divided into zones is the zonemap object (GA::Obj::Zonemap). | ||
| 108 | # Each zone object stores details about its size and position on this workspace grid, | ||
| 109 | # and the windows it contains | ||
| 110 | # The top-left gridblock always has the coordinates 0,0 - so if this workspace grid is | ||
| 111 | # sized 100x100 gridblocks, the bottom-right gridblock has the coordinates 99,99 | ||
| 112 | # Rather than using a 2D array, we use calls to $self->checkPosn to check that a zone of | ||
| 113 | # the grid is/is not occupied by a zone object (GA::Obj::Zone) | ||
| 114 | # Hash in the form | ||
| 115 | # $zoneHash{number} = blessed_reference_to_zone_object | ||
| 116 | zoneHash => {}, | ||
| 117 | # Number of zone objects ever created for this workspace grid (used to give every zone | ||
| 118 | # object a number unique to the workspace grid) | ||
| 119 | # Is reset to 0 when $self->resetGrid is called (because this operation removes all | ||
| 120 | # zones) | ||
| 121 | zoneCount => 0, | ||
| 122 | # Zonemaps have a fixed size (60x60), but workspace grids have an arbitrary size (which | ||
| 123 | # may or may not be the same) | ||
| 124 | # In order to make sure zones are spaced equally, and that there are no gaps between | ||
| 125 | # them because of rounding errors, as soon as this workspace grid is created (or | ||
| 126 | # reset), decide which part of the grid corresponds to which part of the zonemap's | ||
| 127 | # 60x60 grid | ||
| 128 | # e.g If the whole workspace is free, and is sized 1200x800, | ||
| 129 | # $zonemapXCoordHash{0} = 0 First part of 60x60 grid is in top-left corner of the | ||
| 130 | # workspace grid | ||
| 131 | # $zonemapXCoordHash{1} = 20 Second part of 60x60 grid starts at the workspace grid, | ||
| 132 | # x = 20 | ||
| 133 | # $zonemapXCoordHash{2} = 40 Second part of 60x60 grid starts at the workspace grid, | ||
| 134 | # x = 40 | ||
| 135 | zonemapXCoordHash => {}, | ||
| 136 | zonemapYCoordHash => {}, | ||
| 137 | |||
| 138 | # Registry hash of grid windows that have been placed onto this workspace grid (a subset | ||
| 139 | # of GA::Obj::Desktop->gridWinHash). Hash in the form | ||
| 140 | # $gridWinHash{unique_number} = blessed_reference_to_grid_window_object | ||
| 141 | gridWinHash => {}, | ||
| 142 | }; | ||
| 143 | |||
| 144 | # Bless the object into existence | ||
| 145 | bless $self, $class; | ||
| 146 | |||
| 147 | return $self; | ||
| 148 | } | ||
| 149 | |||
| 150 | ################## | ||
| 151 | # Methods | ||
| 152 | |||
| 153 | sub start { | ||
| 154 | |||
| 155 | # Called by GA::Obj::Workspace->addWorkspaceGrid | ||
| 156 | # Sets up this workspace grid using a specified zonemap | ||
| 157 | # | ||
| 158 | # Expected arguments | ||
| 159 | # $zonemap - The GA::Obj::Zonemap which specifies how zones should be arranged on the | ||
| 160 | # workspace grid | ||
| 161 | # | ||
| 162 | # Return values | ||
| 163 | # 'undef' on improper arguments | ||
| 164 | # 1 on success | ||
| 165 | |||
| 166 | my ($self, $zonemap, $check) = @_; | ||
| 167 | |||
| 168 | # Check for improper arguments | ||
| 169 | if (! defined $zonemap || defined $check) { | ||
| 170 | |||
| 171 | return $axmud::CLIENT->writeImproper($self->_objClass . '->start', @_); | ||
| 172 | } | ||
| 173 | |||
| 174 | # The new current zonemap is the default one | ||
| 175 | $self->ivPoke('zonemap', $zonemap); | ||
| 176 | |||
| 177 | # Set up the workspace grid | ||
| 178 | $self->resetGrid(); | ||
| 179 | # Set up zones on the newly-created grid | ||
| 180 | $self->resetZones(); | ||
| 181 | |||
| 182 | return 1; | ||
| 183 | } | ||
| 184 | |||
| 185 | sub stop { | ||
| 186 | |||
| 187 | # Called by GA::Obj::Desktop->del_grid | ||
| 188 | # Closes any 'grid' windows on this workspace grid | ||
| 189 | # | ||
| 190 | # Expected arguments | ||
| 191 | # (none besides $self) | ||
| 192 | # | ||
| 193 | # Optional arguments | ||
| 194 | # $session - When a GA::Session is closing, that session. When specified, the | ||
| 195 | # session's 'main' window is disengaged (removed from its workspace grid), | ||
| 196 | # not closed, in the expectation that GA::Session->close might want to | ||
| 197 | # preserve it | ||
| 198 | # | ||
| 199 | # Return values | ||
| 200 | # 'undef' on improper arguments | ||
| 201 | # 1 otherwise | ||
| 202 | |||
| 203 | my ($self, $session, $check) = @_; | ||
| 204 | |||
| 205 | # Local variables | ||
| 206 | my ($count, $msg); | ||
| 207 | |||
| 208 | # Check for improper arguments | ||
| 209 | if (defined $check) { | ||
| 210 | |||
| 211 | return $axmud::CLIENT->writeImproper($self->_objClass . '->stop', @_); | ||
| 212 | } | ||
| 213 | |||
| 214 | # Tell any remaining 'grid' window objects to close their windows. If $session is | ||
| 215 | # defined, 'main' windows merely remove themselves from the workspace grid, but the | ||
| 216 | # window itself is not closed (exception: when Axmud is shutting down, all windows are | ||
| 217 | # closed) | ||
| 218 | # Do this in the reverse order they were created, in the expectation that 'main' windows | ||
| 219 | # will be closed last | ||
| 220 | foreach my $winObj (sort {$b->number <=> $a->number} ($self->ivValues('gridWinHash'))) { | ||
| 221 | |||
| 222 | if (! $axmud::CLIENT->shutdownFlag && $session && $session->mainWin eq $winObj) { | ||
| 223 | |||
| 224 | # (The ->winDisengage function calls $self->del_gridWin in turn) | ||
| 225 | $winObj->winDisengage($session); | ||
| 226 | |||
| 227 | } else { | ||
| 228 | |||
| 229 | # (The ->winDestroy function calls $self->del_gridWin in turn) | ||
| 230 | $winObj->winDestroy(); | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | # Check there are no 'grid' windows left (for error-detection purposes) | ||
| 235 | $count = $self->ivPairs('gridWinHash'); | ||
| 236 | if ($count) { | ||
| 237 | |||
| 238 | if ($count == 1) { | ||
| 239 | $msg = 'There was 1'; | ||
| 240 | } else { | ||
| 241 | $msg = 'There were ' . $count; | ||
| 242 | } | ||
| 243 | |||
| 244 | $msg .= ' un-closed \'grid\' window when the parent workspace grid closed'; | ||
| 245 | |||
| 246 | $axmud::CLIENT->writeWarning($msg, $self->_objClass . '->stop'); | ||
| 247 | } | ||
| 248 | |||
| 249 | return 1; | ||
| 250 | } | ||
| 251 | |||
| 252 | sub fineTuneWinSize { | ||
| 253 | |||
| 254 | # Called by GA::Obj::Workspace->chooseWinPosn, $self->changeWinzone, | ||
| 255 | # GA::Obj::Zone->adjustMultipleWin and ->replaceAreaSpace | ||
| 256 | # Makes small adjustments to a window's size and position to close any gaps on the right and | ||
| 257 | # bottom edges of the workspace grid (because of an arkwardly-sized available workspace) | ||
| 258 | # Makes more small adjustments to correct for window controls, usually before a call to | ||
| 259 | # GA::Obj::Workspace->moveResizeWin. (If the desktop theme uses window controls, we have | ||
| 260 | # to take them into account, changing the size of the window accordingly; $widthPixels and | ||
| 261 | # $heightPixels must now refer to the client area, not the whole window including the | ||
| 262 | # window controls) | ||
| 263 | # | ||
| 264 | # Expected arguments | ||
| 265 | # $winType - The window type; one of the 'grid' window types specified by | ||
| 266 | # GA::Client->constGridWinTypeHash | ||
| 267 | # $xPosPixels, $yPosPixels | ||
| 268 | # - The position of the window to be fine-tuned | ||
| 269 | # $widthPixels, $heightPixels | ||
| 270 | # - The size of the window to be fine-tuned | ||
| 271 | # | ||
| 272 | # Return values | ||
| 273 | # An empty list on improper arguments | ||
| 274 | # Otherwise returns the adjusted list, in the form | ||
| 275 | # ($xPosPixels, $yPosPixels, $widthPixels, $heightPixels) | ||
| 276 | |||
| 277 | my ($self, $winType, $xPosPixels, $yPosPixels, $widthPixels, $heightPixels, $check) = @_; | ||
| 278 | |||
| 279 | # Local variables | ||
| 280 | my ( | ||
| 281 | $gridRightEdge, $winRightEdge, $gridBottomEdge, $winBottomEdge, $rightGap, $bottomGap, | ||
| 282 | @emptyList, | ||
| 283 | ); | ||
| 284 | |||
| 285 | # Check for improper arguments | ||
| 286 | if ( | ||
| 287 | ! defined $winType || ! defined $xPosPixels || ! defined $yPosPixels | ||
| 288 | || ! defined $widthPixels || ! defined $heightPixels || defined $check | ||
| 289 | ) { | ||
| 290 | $axmud::CLIENT->writeImproper($self->_objClass . '->fineTuneWinSize', @_); | ||
| 291 | return @emptyList; | ||
| 292 | } | ||
| 293 | |||
| 294 | # Close the gap between the workspace grid and the right and bottom edges of the available | ||
| 295 | # workspace, if there is one, and if the global flag is set | ||
| 296 | if ($axmud::CLIENT->gridEdgeCorrectionFlag) { | ||
| 297 | |||
| 298 | # Get the position of the right boundary of the workspace grid, and the right edge of | ||
| 299 | # the window, in pixels | ||
| 300 | $gridRightEdge | ||
| 301 | = $self->xPosPixels + ($self->widthBlocks * $axmud::CLIENT->gridBlockSize) - 1; | ||
| 302 | $winRightEdge = $xPosPixels + $widthPixels - 1; | ||
| 303 | |||
| 304 | $gridBottomEdge | ||
| 305 | = $self->yPosPixels + ($self->heightBlocks * $axmud::CLIENT->gridBlockSize) -1; | ||
| 306 | $winBottomEdge = $yPosPixels + $heightPixels - 1; | ||
| 307 | |||
| 308 | # For windows on the right edge of the workspace grid, look for a gap between that edge | ||
| 309 | # and the edge of the available workspace that's smaller than a gridblock | ||
| 310 | if ($gridRightEdge == $winRightEdge) { | ||
| 311 | |||
| 312 | $rightGap = $self->workspaceObj->currentWidth | ||
| 313 | - $self->workspaceObj->panelRightSize - 1 - $gridRightEdge; | ||
| 314 | |||
| 315 | if ($rightGap > 0 && $rightGap < $axmud::CLIENT->gridBlockSize) { | ||
| 316 | |||
| 317 | # Increase the width of the window, therefore closing the gap | ||
| 318 | $widthPixels += $rightGap; | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | # For windows on the bottom edge of the workspace grid, look for a gap between that edge | ||
| 323 | # and the edge of the available workspace that's smaller than a gridblock | ||
| 324 | if ($gridBottomEdge == $winBottomEdge) { | ||
| 325 | |||
| 326 | $bottomGap = $self->workspaceObj->currentHeight | ||
| 327 | - $self->workspaceObj->panelBottomSize - 1 - $gridBottomEdge; | ||
| 328 | |||
| 329 | if ($bottomGap > 0 && $bottomGap < $axmud::CLIENT->gridBlockSize) { | ||
| 330 | |||
| 331 | # Increase the height of the window by the amount, therefore closing the gap | ||
| 332 | $heightPixels += $bottomGap; | ||
| 333 | } | ||
| 334 | } | ||
| 335 | } | ||
| 336 | |||
| 337 | # Adjust the size of the window to account for window controls for this workspace | ||
| 338 | # NB 'external' windows aren't fine-tuned in this way - instead, | ||
| 339 | # GA::Obj::Workspace->createGridWin takes window controls into account in its call to | ||
| 340 | # ->moveResizeWin | ||
| 341 | if ($winType ne 'external') { | ||
| 342 | |||
| 343 | $widthPixels -= ($self->workspaceObj->controlsLeftSize | ||
| 344 | + $self->workspaceObj->controlsRightSize); | ||
| 345 | $heightPixels -= ($self->workspaceObj->controlsTopSize | ||
| 346 | + $self->workspaceObj->controlsBottomSize); | ||
| 347 | } | ||
| 348 | |||
| 349 | return ($xPosPixels, $yPosPixels, $widthPixels, $heightPixels); | ||
| 350 | } | ||
| 351 | |||
| 352 | sub applyZonemap { | ||
| 353 | |||
| 354 | # Called by GA::Cmd::ResetGrid->do and GA::Obj::File->extractData | ||
| 355 | # Resets this workspace grid and all windows on it, using a new zonemap if specified, or | ||
| 356 | # re-using the existing one if not | ||
| 357 | # If a temporary zonemap is specified, calls $self->applyTempZonemap to do the job | ||
| 358 | # | ||
| 359 | # Expected arguments | ||
| 360 | # (none besides $self) | ||
| 361 | # | ||
| 362 | # Optional arguments | ||
| 363 | # $zonemapObj - The zonemap object (GA::Obj::Zonemap) to use ('undef' to re-use the | ||
| 364 | # existing zonemap) | ||
| 365 | # | ||
| 366 | # Return values | ||
| 367 | # 'undef' on improper arguments | ||
| 368 | # 1 otherwise | ||
| 369 | |||
| 370 | my ($self, $zonemapObj, $check) = @_; | ||
| 371 | |||
| 372 | # Local variables | ||
| 373 | my $errorFlag; | ||
| 374 | |||
| 375 | # Check for improper arguments | ||
| 376 | if (defined $check) { | ||
| 377 | |||
| 378 | return $axmud::CLIENT->writeImproper($self->_objClass . '->applyZonemap', @_); | ||
| 379 | } | ||
| 380 | |||
| 381 | # If using a temporary zonemap (created by MXP), check that the zonemap 'belongs' to | ||
| 382 | # the same session that controls this workspace grid (not a concern if all sessions share | ||
| 383 | # workspace grids) | ||
| 384 | # $self->applyTempZonemap is then called to preserve the size and position of existing | ||
| 385 | # windows (as far as possible) | ||
| 386 | if ($zonemapObj && $zonemapObj->tempFlag) { | ||
| 387 | |||
| 388 | if ($self->owner && $zonemapObj->tempSession ne $self->owner) { | ||
| 389 | return undef; | ||
| 390 | } else { | ||
| 391 | return $self->applyTempZonemap($zonemapObj); | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | # Update IVs | ||
| 396 | if ($zonemapObj) { | ||
| 397 | |||
| 398 | $self->ivPoke('zonemap', $zonemapObj->name); | ||
| 399 | } | ||
| 400 | |||
| 401 | # Reset the grid itself, emptying it of zones | ||
| 402 | $self->resetGrid(); | ||
| 403 | # Reset zones on the newly-emptied grid, using zone models from the zonemap | ||
| 404 | $self->resetZones(); | ||
| 405 | |||
| 406 | # For each 'grid' window object on this workspace grid, find a new position on the grid and | ||
| 407 | # give it a new area object (GA::Obj::Area) storing details of that position | ||
| 408 | OUTER: foreach my $winObj ( | ||
| 409 | sort {$a->number <=> $b->number} ($self->ivValues('gridWinHash')) | ||
| 410 | ) { | ||
| 411 | if (! $self->repositionGridWin($winObj)) { | ||
| 412 | |||
| 413 | $errorFlag = TRUE; | ||
| 414 | last OUTER; | ||
| 415 | } | ||
| 416 | } | ||
| 417 | |||
| 418 | if ($errorFlag) { | ||
| 419 | |||
| 420 | # In the unlikely event of an error, disable grids in this workspace - destroying/ | ||
| 421 | # disengaging windows adds too many complications | ||
| 422 | $self->workspaceObj->disableWorkspaceGrids(); | ||
| 423 | |||
| 424 | return undef; | ||
| 425 | |||
| 426 | } else { | ||
| 427 | |||
| 428 | return 1; | ||
| 429 | } | ||
| 430 | } | ||
| 431 | |||
| 432 | sub applyTempZonemap { | ||
| 433 | |||
| 434 | # Called by $self->applyZonemap, whenever a temporary zonemap is specified (which has | ||
| 435 | # passed some basic checks) | ||
| 436 | # Resets this workspace grid using the temporary zonemap (which should have a single zone | ||
| 437 | # model, encompassing the whole of the zonemap's internal grid) | ||
| 438 | # Tries to place existing 'grid' windows on the reset grid at their former size and | ||
| 439 | # position | ||
| 440 | # If successful, the user won't realise (immediately) that a new zonemap has been applied | ||
| 441 | # | ||
| 442 | # Expected arguments | ||
| 443 | # $zonemapObj - The temporary zonemap object (GA::Obj::Zonemap) to use. This | ||
| 444 | # function assumes it was created by GA::Client->createTempZonemap, | ||
| 445 | # and that it has a single zone model (and is not editable) | ||
| 446 | # | ||
| 447 | # Return values | ||
| 448 | # 'undef' on improper arguments | ||
| 449 | # 1 otherwise | ||
| 450 | |||
| 451 | my ($self, $zonemapObj, $check) = @_; | ||
| 452 | |||
| 453 | # Local variables | ||
| 454 | my ( | ||
| 455 | $errorFlag, | ||
| 456 | @failList, | ||
| 457 | %gridWinHash, | ||
| 458 | ); | ||
| 459 | |||
| 460 | # Check for improper arguments | ||
| 461 | if (defined $check) { | ||
| 462 | |||
| 463 | return $axmud::CLIENT->writeImproper($self->_objClass . '->applyTempZonemap', @_); | ||
| 464 | } | ||
| 465 | |||
| 466 | # Remember the current size/position of 'grid' windows | ||
| 467 | %gridWinHash = $self->gridWinHash; | ||
| 468 | |||
| 469 | # Update IVs | ||
| 470 | $self->ivPoke('zonemap', $zonemapObj->name); | ||
| 471 | # Reset the grid itself, emptying it of zones | ||
| 472 | $self->resetGrid(); | ||
| 473 | # Reset zones on the newly-emptied grid, using zone models from the zonemap | ||
| 474 | $self->resetZones(); | ||
| 475 | |||
| 476 | # For each 'grid' window object on this workspace grid, try to place the window on the grid | ||
| 477 | # at its former size and position, giving it a new area object | ||
| 478 | foreach my $winObj (sort {$a->number <=> $b->number} (values %gridWinHash)) { | ||
| 479 | |||
| 480 | if (! $self->restoreGridWin($winObj)) { | ||
| 481 | |||
| 482 | push (@failList, $winObj); | ||
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | # Any windows that couldn't be restored to their former size and position can be placed | ||
| 487 | # onto the grid as normal | ||
| 488 | OUTER: foreach my $winObj (@failList) { | ||
| 489 | |||
| 490 | if (! $self->repositionGridWin($winObj)) { | ||
| 491 | |||
| 492 | $errorFlag = TRUE; | ||
| 493 | last OUTER; | ||
| 494 | } | ||
| 495 | } | ||
| 496 | |||
| 497 | if ($errorFlag) { | ||
| 498 | |||
| 499 | # In the unlikely event of an error, disable grids in this workspace - destroying/ | ||
| 500 | # disengaging windows adds too many complications | ||
| 501 | $self->workspaceObj->disableWorkspaceGrids(); | ||
| 502 | |||
| 503 | return undef; | ||
| 504 | |||
| 505 | } else { | ||
| 506 | |||
| 507 | return 1; | ||
| 508 | } | ||
| 509 | } | ||
| 510 | |||
| 511 | sub resetGrid { | ||
| 512 | |||
| 513 | # Called by $self->start or $self->applyZonemap | ||
| 514 | # Resets the workspace grid, deleting any existing zones. The new size of the grid is the | ||
| 515 | # whole workspace, minus any areas reserved for panels (taskbars) | ||
| 516 | # Given the size of the available workspace, also works out which parts of the workspace | ||
| 517 | # grid correspond to each gridblock on the zonemap's 60x60 grid | ||
| 518 | # | ||
| 519 | # Expected arguments | ||
| 520 | # (none besides $self) | ||
| 521 | # | ||
| 522 | # Optional argument | ||
| 523 | # $zonemap - The name of the new zonemap to use; if specified, stored in | ||
| 524 | # $self->zonemap; if 'undef', the zonemap stored in $self->zonemap is not | ||
| 525 | # modified | ||
| 526 | # | ||
| 527 | # Return values | ||
| 528 | # 'undef' on improper arguments | ||
| 529 | # 1 otherwise | ||
| 530 | |||
| 531 | my ($self, $zonemap, $check) = @_; | ||
| 532 | |||
| 533 | # Local variables | ||
| 534 | my ( | ||
| 535 | $availableWidth, $availableHeight, | ||
| 536 | %xCoordHash, %yCoordHash, | ||
| 537 | ); | ||
| 538 | |||
| 539 | # Check for improper arguments | ||
| 540 | if (defined $check) { | ||
| 541 | |||
| 542 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetGrid', @_); | ||
| 543 | } | ||
| 544 | |||
| 545 | # Set the new zonemap, if one was specified (and it exists) | ||
| 546 | if ($zonemap && $axmud::CLIENT->ivExists('zonemapHash', $zonemap)) { | ||
| 547 | |||
| 548 | $self->ivPoke('zonemap', $zonemap); | ||
| 549 | } | ||
| 550 | |||
| 551 | # The size of the available workspace is the current width and height, minus any space | ||
| 552 | # reserved for panels | ||
| 553 | $availableWidth = $self->workspaceObj->currentWidth - $self->workspaceObj->panelLeftSize | ||
| 554 | - $self->workspaceObj->panelRightSize; | ||
| 555 | $availableHeight = $self->workspaceObj->currentHeight - $self->workspaceObj->panelTopSize | ||
| 556 | - $self->workspaceObj->panelBottomSize; | ||
| 557 | |||
| 558 | # Now work out the size of the grid, rounding down if necessary (this may create small areas | ||
| 559 | # near the right and bottom edges of the workspace, if it's an arkward size like 1047x731) | ||
| 560 | $self->ivPoke('widthBlocks', int($availableWidth / $axmud::CLIENT->gridBlockSize)); | ||
| 561 | $self->ivPoke('heightBlocks', int($availableHeight / $axmud::CLIENT->gridBlockSize)); | ||
| 562 | |||
| 563 | |||
| 564 | # Set the x/y coordinates, in pixels, of the top-left corner of the grid on the wprkspace | ||
| 565 | $self->ivPoke('xPosPixels', $self->workspaceObj->panelLeftSize); | ||
| 566 | $self->ivPoke('yPosPixels', $self->workspaceObj->panelTopSize); | ||
| 567 | |||
| 568 | # Empty the workspace grid, which deletes any existing zones | ||
| 569 | $self->ivEmpty('zoneHash'); | ||
| 570 | $self->ivPoke('zoneCount', 0); | ||
| 571 | |||
| 572 | # Work out which parts of the workspace grid correspond to each block on the zonemap's 60x60 | ||
| 573 | # grid | ||
| 574 | for (my $count = 0; $count < 60; $count++) { | ||
| 575 | |||
| 576 | $xCoordHash{$count} = int (($count * $self->widthBlocks) / 60); | ||
| 577 | } | ||
| 578 | |||
| 579 | for (my $count = 0; $count < 60; $count++) { | ||
| 580 | |||
| 581 | $yCoordHash{$count} = int (($count * $self->heightBlocks) / 60); | ||
| 582 | } | ||
| 583 | |||
| 584 | # Store the hashes | ||
| 585 | $self->ivPoke('zonemapXCoordHash', %xCoordHash); | ||
| 586 | $self->ivPoke('zonemapYCoordHash', %yCoordHash); | ||
| 587 | |||
| 588 | # Set the currently visible layer to the default one | ||
| 589 | $self->ivPoke('currentLayer', $self->defaultLayer); | ||
| 590 | |||
| 591 | # Grid reset complete | ||
| 592 | return 1; | ||
| 593 | } | ||
| 594 | |||
| 595 | sub resetZones { | ||
| 596 | |||
| 597 | # Called by $self->start or ->applyZonemap | ||
| 598 | # Sets up all zones on the workspace grid, according to the instructions provided by the | ||
| 599 | # current zonemap | ||
| 600 | # This function assumes that the workspace grid is currently empty | ||
| 601 | # | ||
| 602 | # Expected arguments | ||
| 603 | # (none besides $self) | ||
| 604 | # | ||
| 605 | # Return values | ||
| 606 | # 'undef' on improper arguments, if the current GA::Obj::Zonemap can't be found or if a | ||
| 607 | # GA::Obj::Zone can't be created | ||
| 608 | # 1 otherwise | ||
| 609 | |||
| 610 | my ($self, $check) = @_; | ||
| 611 | |||
| 612 | # Local variables | ||
| 613 | my ( | ||
| 614 | $zonemapObj, $count, | ||
| 615 | %modelHash, | ||
| 616 | ); | ||
| 617 | |||
| 618 | # Check for improper arguments | ||
| 619 | if (defined $check) { | ||
| 620 | |||
| 621 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetZones', @_); | ||
| 622 | } | ||
| 623 | |||
| 624 | # Import IVs | ||
| 625 | $zonemapObj = $axmud::CLIENT->ivShow('zonemapHash', $self->zonemap); | ||
| 626 | if (! $zonemapObj) { | ||
| 627 | |||
| 628 | # The current zonemap seems to be missing | ||
| 629 | return $self->writeError( | ||
| 630 | 'Missing zonemap \'' . $self->zonemap . '\'', | ||
| 631 | $self->_objClass . '->resetZones', | ||
| 632 | ); | ||
| 633 | |||
| 634 | } else { | ||
| 635 | |||
| 636 | # Import the zonemap's GA::Obj::ZoneModel objects | ||
| 637 | %modelHash = $zonemapObj->modelHash; | ||
| 638 | } | ||
| 639 | |||
| 640 | # Create new zones for each zone model in the list in ascending order | ||
| 641 | $count = 0; | ||
| 642 | foreach my $modelObj ( | ||
| 643 | sort {$a->number <=> $b->number} ($zonemapObj->ivValues('modelHash')) | ||
| 644 | ) { | ||
| 645 | my ($zoneObj, $leftBlocks, $rightBlocks, $topBlocks, $bottomBlocks); | ||
| 646 | |||
| 647 | # Create a new zone object | ||
| 648 | $zoneObj = Games::Axmud::Obj::Zone->new($count, $self); | ||
| 649 | if (! $zoneObj) { | ||
| 650 | |||
| 651 | # This is a fatal error | ||
| 652 | return undef; | ||
| 653 | |||
| 654 | } else { | ||
| 655 | |||
| 656 | $count++; | ||
| 657 | } | ||
| 658 | |||
| 659 | # Set the zone's variables using the zone model's variables | ||
| 660 | |||
| 661 | # Translate the zone model's coordinates on the the zonemap's 60x60 grid into the | ||
| 662 | # coordinates of a zone on the workspace grid | ||
| 663 | # For the top left corner, use the actual values specified by the zone model. For | ||
| 664 | # the bottom right corner, use one block to the left/above the value of the NEXT | ||
| 665 | # block to the right/below (unless we're on the right or bottom edge of the | ||
| 666 | # available workspace; in that case, use the gridblock touching the edge) | ||
| 667 | |||
| 668 | # Top-left corner | ||
| 669 | $leftBlocks = $self->ivShow('zonemapXCoordHash', $modelObj->left); | ||
| 670 | $topBlocks = $self->ivShow('zonemapYCoordHash', $modelObj->top); | ||
| 671 | |||
| 672 | # Bottom-right corner | ||
| 673 | if ($modelObj->right == ($zonemapObj->gridSize - 1)) { | ||
| 674 | |||
| 675 | # Furthest right gridblock has x co-ord (width - 1) | ||
| 676 | $rightBlocks = ($self->widthBlocks - 1); | ||
| 677 | |||
| 678 | } else { | ||
| 679 | |||
| 680 | $rightBlocks | ||
| 681 | = $self->ivShow('zonemapXCoordHash', ($modelObj->right + 1)) - 1; | ||
| 682 | } | ||
| 683 | |||
| 684 | if ($modelObj->bottom == ($zonemapObj->gridSize - 1)) { | ||
| 685 | |||
| 686 | # Furthest down gridblock has y co-ord (height - 1) | ||
| 687 | $bottomBlocks = ($self->heightBlocks - 1); | ||
| 688 | |||
| 689 | } else { | ||
| 690 | |||
| 691 | $bottomBlocks | ||
| 692 | = $self->ivShow('zonemapYCoordHash',($modelObj->bottom + 1)) - 1; | ||
| 693 | } | ||
| 694 | |||
| 695 | # Check that the workspace grid is free at those locations | ||
| 696 | $self->checkPosn($leftBlocks, $rightBlocks, $topBlocks, $bottomBlocks); | ||
| 697 | |||
| 698 | # Now mark the workspace as occupied at these points | ||
| 699 | $self->ivAdd('zoneHash', $zoneObj->number, $zoneObj); | ||
| 700 | $self->ivPoke('zoneCount', $count); | ||
| 701 | |||
| 702 | # Set the zone's coordinates and size | ||
| 703 | $zoneObj->set_posn($leftBlocks, $topBlocks); | ||
| 704 | $zoneObj->set_size( | ||
| 705 | ($rightBlocks - $leftBlocks + 1), | ||
| 706 | ($bottomBlocks - $topBlocks + 1), | ||
| 707 | ); | ||
| 708 | |||
| 709 | # Set the reserved window variables | ||
| 710 | $zoneObj->set_reserved( | ||
| 711 | $modelObj->multipleLayerFlag, | ||
| 712 | $modelObj->reservedFlag, | ||
| 713 | $modelObj->reservedHash, | ||
| 714 | ); | ||
| 715 | |||
| 716 | # Setup the zone's internal grid | ||
| 717 | $zoneObj->resetInternalGrid(); | ||
| 718 | |||
| 719 | # Set the orientation variables | ||
| 720 | $zoneObj->set_orientation($modelObj->startCorner, $modelObj->orientation); | ||
| 721 | |||
| 722 | # Set the winmap variables | ||
| 723 | $zoneObj->set_winmap( | ||
| 724 | $modelObj->defaultEnabledWinmap, | ||
| 725 | $modelObj->defaultDisabledWinmap, | ||
| 726 | $modelObj->defaultInternalWinmap, | ||
| 727 | ); | ||
| 728 | |||
| 729 | # Set the area variables (each GA::Obj::Area object handles a single window and | ||
| 730 | # reserves an area of the zone for that window) | ||
| 731 | $zoneObj->set_areaVars($modelObj->areaMax, $modelObj->visibleAreaMax, 0); | ||
| 732 | |||
| 733 | # Set the string specifying an owner | ||
| 734 | $zoneObj->set_ownerString($modelObj->ownerString); | ||
| 735 | |||
| 736 | # Set the default area sizes | ||
| 737 | if ($zoneObj->visibleAreaMax) { | ||
| 738 | |||
| 739 | # If there's a maximum number of visible areas, set the default area sizes | ||
| 740 | # around that | ||
| 741 | if ($zoneObj->orientation eq 'horizontal') { | ||
| 742 | |||
| 743 | $zoneObj->set_areaWidth(int($zoneObj->widthBlocks / $zoneObj->visibleAreaMax)); | ||
| 744 | $zoneObj->set_areaHeight($zoneObj->heightBlocks); | ||
| 745 | |||
| 746 | } elsif ($zoneObj->orientation eq 'vertical') { | ||
| 747 | |||
| 748 | $zoneObj->set_areaWidth($zoneObj->widthBlocks); | ||
| 749 | $zoneObj->set_areaHeight( | ||
| 750 | int($zoneObj->heightBlocks / $zoneObj->visibleAreaMax), | ||
| 751 | ); | ||
| 752 | } | ||
| 753 | |||
| 754 | } else { | ||
| 755 | |||
| 756 | # If the zone model specifies a default area size, use that. Otherwise set the | ||
| 757 | # default area sizes using global defaults | ||
| 758 | if ($modelObj->defaultAreaWidth) { | ||
| 759 | |||
| 760 | $zoneObj->set_areaWidth( | ||
| 761 | # (Convert a 60x60 grid to workspace gridblocks) | ||
| 762 | int($zoneObj->widthBlocks * ($modelObj->defaultAreaWidth / 60)), | ||
| 763 | ); | ||
| 764 | |||
| 765 | } else { | ||
| 766 | |||
| 767 | $zoneObj->set_areaHeight( | ||
| 768 | int($axmud::CLIENT->customGridWinWidth / $axmud::CLIENT->gridBlockSize), | ||
| 769 | ); | ||
| 770 | } | ||
| 771 | |||
| 772 | if ($modelObj->defaultAreaHeight) { | ||
| 773 | |||
| 774 | $zoneObj->set_areaWidth( | ||
| 775 | # (Convert a 60x60 grid to workspace gridblocks) | ||
| 776 | int($zoneObj->heightBlocks * ($modelObj->defaultAreaHeight / 60)), | ||
| 777 | ); | ||
| 778 | |||
| 779 | } else { | ||
| 780 | |||
| 781 | $zoneObj->set_areaHeight( | ||
| 782 | int($axmud::CLIENT->customGridWinHeight / $axmud::CLIENT->gridBlockSize), | ||
| 783 | ); | ||
| 784 | } | ||
| 785 | } | ||
| 786 | } | ||
| 787 | |||
| 788 | return 1; | ||
| 789 | } | ||
| 790 | |||
| 791 | sub repositionGridWin{ | ||
| 792 | |||
| 793 | # Called by $self->applyZonemap and GA::Obj::Desktop->convertSpareMainWin | ||
| 794 | # New 'grid' windows are placed onto a workspace grid via a call to | ||
| 795 | # GA::Obj::Workspace->createGridWin | ||
| 796 | # Existing 'grid' windows are given a new position on the same grid by calling this | ||
| 797 | # function, which creates a new area object (GA::Obj::Area) storing details of the new | ||
| 798 | # position | ||
| 799 | # | ||
| 800 | # Expected arguments | ||
| 801 | # $winObj - The existing window object (inheriting from GA::Generic::Win) | ||
| 802 | # | ||
| 803 | # Return values | ||
| 804 | # 'undef' on improper arguments or if the window can't be repositioned | ||
| 805 | # 1 on success | ||
| 806 | |||
| 807 | my ($self, $winObj, $check) = @_; | ||
| 808 | |||
| 809 | # Local variables | ||
| 810 | my ( | ||
| 811 | $zoneObj, $widthPixels, $heightPixels, $layer, $xPosBlocks, $yPosBlocks, | ||
| 812 | $widthBlocks, $heightBlocks, $xPosPixels, $yPosPixels, $areaObj, | ||
| 813 | ); | ||
| 814 | |||
| 815 | # Check for improper arguments | ||
| 816 | if (! defined $winObj || defined $check) { | ||
| 817 | |||
| 818 | return $axmud::CLIENT->writeImproper($self->_objClass . '->repositionGridWin', @_); | ||
| 819 | } | ||
| 820 | |||
| 821 | # Choose the new zone | ||
| 822 | $zoneObj = $self->workspaceObj->chooseZone( | ||
| 823 | $self, | ||
| 824 | $winObj->winType, | ||
| 825 | $winObj->winName, | ||
| 826 | $winObj->winWidget, | ||
| 827 | undef, | ||
| 828 | $winObj->owner, | ||
| 829 | $winObj->session, | ||
| 830 | ); | ||
| 831 | |||
| 832 | if (! $zoneObj) { | ||
| 833 | |||
| 834 | # No available zones | ||
| 835 | return undef; | ||
| 836 | } | ||
| 837 | |||
| 838 | # Choose the window size within the zone | ||
| 839 | ($widthPixels, $heightPixels) = $self->workspaceObj->chooseWinSize( | ||
| 840 | $winObj->winType, | ||
| 841 | $self, | ||
| 842 | $zoneObj, | ||
| 843 | ); | ||
| 844 | |||
| 845 | # Choose the exact size and position of the window inside its zone, taking into account such | ||
| 846 | # factors as other windows in the zone | ||
| 847 | ( | ||
| 848 | $layer, $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $xPosPixels, | ||
| 849 | $yPosPixels, $widthPixels, $heightPixels, | ||
| 850 | ) = $self->workspaceObj->chooseWinPosn( | ||
| 851 | $winObj->session, # Write error messages here | ||
| 852 | $winObj->winType, | ||
| 853 | TRUE, # Use the zone allocated above | ||
| 854 | $self, | ||
| 855 | $widthPixels, | ||
| 856 | $heightPixels, | ||
| 857 | $zoneObj, | ||
| 858 | ); | ||
| 859 | |||
| 860 | if (! defined $layer) { | ||
| 861 | |||
| 862 | # Zone is full | ||
| 863 | return undef; | ||
| 864 | } | ||
| 865 | |||
| 866 | # Create a GA::Obj::Area within the zone (which handles the existing window, and is the | ||
| 867 | # same size as it) | ||
| 868 | $areaObj = $zoneObj->addArea( | ||
| 869 | $layer, | ||
| 870 | $xPosBlocks, | ||
| 871 | $yPosBlocks, | ||
| 872 | $widthBlocks, | ||
| 873 | $heightBlocks, | ||
| 874 | $xPosPixels, | ||
| 875 | $yPosPixels, | ||
| 876 | $widthPixels, | ||
| 877 | $heightPixels, | ||
| 878 | $winObj->session, | ||
| 879 | ); | ||
| 880 | |||
| 881 | if (! $areaObj) { | ||
| 882 | |||
| 883 | # Checks failed | ||
| 884 | return undef; | ||
| 885 | |||
| 886 | } else { | ||
| 887 | |||
| 888 | $winObj->set_areaObj($areaObj); | ||
| 889 | $areaObj->set_win($winObj); | ||
| 890 | } | ||
| 891 | |||
| 892 | # Move the window to its correct size and position | ||
| 893 | $self->workspaceObj->moveResizeWin( | ||
| 894 | $winObj, | ||
| 895 | $xPosPixels, | ||
| 896 | $yPosPixels, | ||
| 897 | $widthPixels, | ||
| 898 | $heightPixels, | ||
| 899 | ); | ||
| 900 | |||
| 901 | # This object's new current layer is the layer in which this window will be placed (so that | ||
| 902 | # it's visible to the user immediately) | ||
| 903 | $self->ivPoke('currentLayer', $layer); | ||
| 904 | |||
| 905 | # Make the usual sensible adjustments to window sizes (see the comments in | ||
| 906 | # GA::Obj::Workspace->createGridWin) | ||
| 907 | if ( | ||
| 908 | $axmud::CLIENT->gridAdjustmentFlag | ||
| 909 | && $zoneObj->areaHash | ||
| 910 | && $zoneObj->areaMax != 1 | ||
| 911 | && ( | ||
| 912 | # Windows are stacked horizontally, and there's only room for one (default-size) | ||
| 913 | # window in each row | ||
| 914 | ( | ||
| 915 | $zoneObj->orientation eq 'horizontal' | ||
| 916 | && $zoneObj->heightBlocks >= $zoneObj->defaultAreaHeight | ||
| 917 | && $zoneObj->heightBlocks < ($zoneObj->defaultAreaHeight * 2) | ||
| 918 | # Windows are stacked vertically, and there's only room for one (default-size) | ||
| 919 | # window in each column | ||
| 920 | ) || ( | ||
| 921 | $zoneObj->orientation eq 'vertical' | ||
| 922 | && $zoneObj->widthBlocks >= $zoneObj->defaultAreaWidth | ||
| 923 | && $zoneObj->widthBlocks < ($zoneObj->defaultAreaWidth * 2) | ||
| 924 | ) | ||
| 925 | ) | ||
| 926 | ) { | ||
| 927 | $zoneObj->adjustMultipleWin($areaObj->layer); | ||
| 928 | } | ||
| 929 | |||
| 930 | # Operation complete | ||
| 931 | return 1; | ||
| 932 | } | ||
| 933 | |||
| 934 | sub restoreGridWin{ | ||
| 935 | |||
| 936 | # Called by $self->applyTempZonemap; counterpart to $self->repositionGridWin (which is | ||
| 937 | # called by $self->applyZonemap) | ||
| 938 | # After the grid has been reset, tries to place a 'grid' window onto the grid at its former | ||
| 939 | # size and position, creating a new area object (GA::Obj::Area) | ||
| 940 | # This function assumes the new zonemap is a temporary zonemap with a single zone model, | ||
| 941 | # encompassing the whole of the zonemap's internal grid) | ||
| 942 | # | ||
| 943 | # Expected arguments | ||
| 944 | # $winObj - The existing window object (inheriting from GA::Generic::Win) | ||
| 945 | # | ||
| 946 | # Return values | ||
| 947 | # 'undef' on improper arguments or if the window can't be restored | ||
| 948 | # 1 on success | ||
| 949 | |||
| 950 | my ($self, $winObj, $check) = @_; | ||
| 951 | |||
| 952 | # Local variables | ||
| 953 | my ($zoneObj, $oldAreaObj, $newAreaObj); | ||
| 954 | |||
| 955 | # Check for improper arguments | ||
| 956 | if (! defined $winObj || defined $check) { | ||
| 957 | |||
| 958 | return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreGridWin', @_); | ||
| 959 | } | ||
| 960 | |||
| 961 | # Get the (single) zone | ||
| 962 | $zoneObj = $self->ivShow('zoneHash', 0); | ||
| 963 | if (! $zoneObj) { | ||
| 964 | |||
| 965 | return undef; | ||
| 966 | } | ||
| 967 | |||
| 968 | # Create a GA::Obj::Area within the zone (which handles the existing window, and is the | ||
| 969 | # same size as it) | ||
| 970 | $oldAreaObj = $winObj->areaObj; | ||
| 971 | $newAreaObj = $zoneObj->addArea( | ||
| 972 | $oldAreaObj->layer, | ||
| 973 | $oldAreaObj->zoneObj->xPosBlocks + $oldAreaObj->leftBlocks, | ||
| 974 | $oldAreaObj->zoneObj->yPosBlocks + $oldAreaObj->topBlocks, | ||
| 975 | $oldAreaObj->widthBlocks, | ||
| 976 | $oldAreaObj->heightBlocks, | ||
| 977 | $oldAreaObj->xPosPixels, | ||
| 978 | $oldAreaObj->yPosPixels, | ||
| 979 | $oldAreaObj->widthPixels, | ||
| 980 | $oldAreaObj->heightPixels, | ||
| 981 | $winObj->session, | ||
| 982 | ); | ||
| 983 | |||
| 984 | if (! $newAreaObj) { | ||
| 985 | |||
| 986 | # Checks failed | ||
| 987 | return undef; | ||
| 988 | |||
| 989 | } else { | ||
| 990 | |||
| 991 | $winObj->set_areaObj($newAreaObj); | ||
| 992 | $newAreaObj->set_win($winObj); | ||
| 993 | |||
| 994 | return 1; | ||
| 995 | } | ||
| 996 | } | ||
| 997 | |||
| 998 | sub checkPosn { | ||
| 999 | |||
| 1000 | # Called by $self->resetZones | ||
| 1001 | # Check to see if a proposed zone would fit onto a region of the workspace grid, at a | ||
| 1002 | # specified position, without overlapping existing zones | ||
| 1003 | # | ||
| 1004 | # Expected arguments | ||
| 1005 | # $leftBlocks, $rightBlocks, $topBlocks, $bottomBlocks | ||
| 1006 | # - The boundaries of the region to check | ||
| 1007 | # | ||
| 1008 | # Return values | ||
| 1009 | # 'undef' on improper arguments or if the zone overlaps another zone | ||
| 1010 | # 1 otherwise | ||
| 1011 | |||
| 1012 | my ($self, $leftBlocks, $rightBlocks, $topBlocks, $bottomBlocks, $check) = @_; | ||
| 1013 | |||
| 1014 | # Check for improper arguments | ||
| 1015 | |||
| 1016 | if ( | ||
| 1017 | ! defined $leftBlocks || ! defined $rightBlocks || ! defined $topBlocks | ||
| 1018 | || ! defined $bottomBlocks || defined $check | ||
| 1019 | ) { | ||
| 1020 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPosn', @_); | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | # Check each existing zone in turn | ||
| 1024 | foreach my $zoneObj ($self->ivValues('zoneHash')) { | ||
| 1025 | |||
| 1026 | my ($x1, $x2, $y1, $y2); | ||
| 1027 | |||
| 1028 | $x1 = $zoneObj->xPosBlocks; | ||
| 1029 | $x2 = $x1 + $zoneObj->widthBlocks - 1; | ||
| 1030 | $y1 = $zoneObj->yPosBlocks; | ||
| 1031 | $y2 = $y1 + $zoneObj->heightBlocks - 1; | ||
| 1032 | |||
| 1033 | if ( | ||
| 1034 | ( | ||
| 1035 | ($x1 >= $leftBlocks && $x1 <= $rightBlocks) | ||
| 1036 | || ($x2 >= $leftBlocks && $x2 <= $rightBlocks) | ||
| 1037 | ) && ( | ||
| 1038 | ($y1 >= $topBlocks && $y1 <= $bottomBlocks) | ||
| 1039 | || ($y2 >= $topBlocks && $y2 <= $bottomBlocks) | ||
| 1040 | ) | ||
| 1041 | ) { | ||
| 1042 | return undef; | ||
| 1043 | } | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | # The proposed zone fits at the specified position without overlapping existing zones | ||
| 1047 | return 1; | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | sub findZone { | ||
| 1051 | |||
| 1052 | # Called by GA::Obj::Workspace->createGridWin and GA::Cmd::FixWindow->do to find out | ||
| 1053 | # which zone occupies a specified position (in pixels) on the workspace | ||
| 1054 | # | ||
| 1055 | # Expected arguments | ||
| 1056 | # $xPosPixels, $yPosPixels | ||
| 1057 | # - The coordinates of a pixel on the workspace (the top-left pixel has co-ords 0, 0) | ||
| 1058 | # | ||
| 1059 | # Return values | ||
| 1060 | # 'undef' on improper arguments or if no zone occupies the specified pixel | ||
| 1061 | # Otherwise returns the GA::Obj::Zone that occupies the specified pixel | ||
| 1062 | |||
| 1063 | my ($self, $xPosPixels, $yPosPixels, $check) = @_; | ||
| 1064 | |||
| 1065 | # Local variables | ||
| 1066 | my ($xPosBlocks, $yPosBlocks); | ||
| 1067 | |||
| 1068 | # Check for improper arguments | ||
| 1069 | if (! defined $xPosPixels || ! defined $yPosPixels || defined $check) { | ||
| 1070 | |||
| 1071 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findZone', @_); | ||
| 1072 | } | ||
| 1073 | |||
| 1074 | # Work out which gridblock occupies this position | ||
| 1075 | $xPosBlocks = ($xPosPixels - $self->xPosPixels) / $axmud::CLIENT->gridBlockSize; | ||
| 1076 | $yPosBlocks = ($yPosPixels - $self->yPosPixels) / $axmud::CLIENT->gridBlockSize; | ||
| 1077 | |||
| 1078 | # Return the zone at this gridblock | ||
| 1079 | foreach my $zoneObj ($self->ivValues('zoneHash')) { | ||
| 1080 | |||
| 1081 | if ( | ||
| 1082 | $xPosBlocks >= $zoneObj->xPosBlocks | ||
| 1083 | && $xPosBlocks <= ($zoneObj->xPosBlocks + $zoneObj->widthBlocks - 1) | ||
| 1084 | && $yPosBlocks >= $zoneObj->yPosBlocks | ||
| 1085 | && $yPosBlocks <= ($zoneObj->yPosBlocks + $zoneObj->heightBlocks - 1) | ||
| 1086 | ) { | ||
| 1087 | return $zoneObj; | ||
| 1088 | } | ||
| 1089 | } | ||
| 1090 | |||
| 1091 | # This part of the workspace grid is unoccupied | ||
| 1092 | return undef; | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | sub buildLayerList { | ||
| 1096 | |||
| 1097 | # Called by GA::Obj::Zone->placeWin() when deciding where in a zone to place a window | ||
| 1098 | # Compiles a list of layers in the workspace grid, starting with the specified one, then all | ||
| 1099 | # layers above it, then all layers below | ||
| 1100 | # If no layer is specified, the list starts with the default layer | ||
| 1101 | # e.g. if $self->maxLayers = 16 and $self->defaultLayer = 0 (the default values), | ||
| 1102 | # @layerList = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) | ||
| 1103 | # e.g. if $self->maxLayers = 9 and $self->defaultLayer = 4, | ||
| 1104 | # @layerList = (4 5 6 7 8 3 2 1 0) | ||
| 1105 | # | ||
| 1106 | # Expected arguments | ||
| 1107 | # (none besides $self) | ||
| 1108 | # | ||
| 1109 | # Optional arguments | ||
| 1110 | # $layer - Which layer should start the list. If 'undef', $self->defaultLayer is used | ||
| 1111 | # | ||
| 1112 | # Return values | ||
| 1113 | # Returns an empty list on improper arguments | ||
| 1114 | # Otherwise returns the ordered list of layers | ||
| 1115 | |||
| 1116 | my ($self, $layer, $check) = @_; | ||
| 1117 | |||
| 1118 | # Local variables | ||
| 1119 | my (@emptyList, @layerList); | ||
| 1120 | |||
| 1121 | # Check for improper arguments | ||
| 1122 | if (defined $check) { | ||
| 1123 | |||
| 1124 | $axmud::CLIENT->writeImproper($self->_objClass . '->buildLayerList', @_); | ||
| 1125 | return @emptyList; | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | if (! defined $layer) { | ||
| 1129 | |||
| 1130 | $layer = $self->defaultLayer; | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | # Build the layer list | ||
| 1134 | if ($layer == 0) { | ||
| 1135 | |||
| 1136 | # e.g. @layerList = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) | ||
| 1137 | for (my $num = 0; $num < $self->maxLayers; $num++) { | ||
| 1138 | |||
| 1139 | push (@layerList, $num); | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | } elsif ($layer == ($self->maxLayers - 1) ) { | ||
| 1143 | |||
| 1144 | # e.g. @layerList = (15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) | ||
| 1145 | for (my $num = ($self->maxLayers - 1); $num >= 0; $num--) { | ||
| 1146 | |||
| 1147 | push (@layerList, $num); | ||
| 1148 | } | ||
| 1149 | |||
| 1150 | } else { | ||
| 1151 | |||
| 1152 | # e.g. $layer = 8, @layerList = (8 9 10 11 12 13 14 15 7 6 5 4 3 2 1 0) | ||
| 1153 | for (my $num = $layer; $num < $self->maxLayers; $num++) { | ||
| 1154 | |||
| 1155 | push (@layerList, $num); | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | for (my $num = ($layer - 1); $num >= 0; $num--) { | ||
| 1159 | |||
| 1160 | push (@layerList, $num); | ||
| 1161 | } | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | return @layerList; | ||
| 1165 | } | ||
| 1166 | |||
| 1167 | sub changeWinzone { | ||
| 1168 | |||
| 1169 | # Called by GA::Session->setMainWin, and also by GA::Cmd::MoveWindow->do, FixWindow->do | ||
| 1170 | # Moves a window from one zone into any available space in another zone, the latter being | ||
| 1171 | # a zone in this workspace grid | ||
| 1172 | # If the new zone is the same as the old one, moves the window to the space it would have | ||
| 1173 | # occupied, if it were being moved into this zone from a different one | ||
| 1174 | # | ||
| 1175 | # Expected arguments | ||
| 1176 | # $winObj - Blessed reference to the window object to be moved (inheriting | ||
| 1177 | # from GA::Generic::GridWin) | ||
| 1178 | # $zoneObj - Blessed reference to the zone object (GA::Obj::Zone) into which | ||
| 1179 | # the window should be moved | ||
| 1180 | # | ||
| 1181 | # Optional arguments | ||
| 1182 | # $defaultSizeFlag - If TRUE, the window is resized to fit the zone's default size. If | ||
| 1183 | # FALSE or 'undef', the window keeps its current size (subject to | ||
| 1184 | # small adjustments to fill small gaps) | ||
| 1185 | # $fixWidthPixels, $fixHeightPixels | ||
| 1186 | # - Only specified when called by GA::Cmd::FixWindow->do. If the | ||
| 1187 | # user has changed the window's size, these variables specify that | ||
| 1188 | # size. Both must be specified or both must be set to 'undef' | ||
| 1189 | # | ||
| 1190 | # Return values | ||
| 1191 | # 'undef' on improper arguments or if there's an error | ||
| 1192 | # 1 otherwise | ||
| 1193 | |||
| 1194 | my ( | ||
| 1195 | $self, $winObj, $zoneObj, $defaultSizeFlag, $fixWidthPixels, $fixHeightPixels, $check, | ||
| 1196 | ) = @_; | ||
| 1197 | |||
| 1198 | # Local variables | ||
| 1199 | my ( | ||
| 1200 | $blockSize, $widthPixels, $heightPixels, $widthBlocks, $heightBlocks, $xPosBlocks, | ||
| 1201 | $yPosBlocks, $successFlag, $layer, $oldZoneObj, $xPosPixels, $yPosPixels, $areaObj, | ||
| 1202 | ); | ||
| 1203 | |||
| 1204 | # Check for improper arguments | ||
| 1205 | if ( | ||
| 1206 | ! defined $winObj || ! defined $zoneObj || defined $check | ||
| 1207 | || (defined $fixWidthPixels && ! defined $fixHeightPixels) | ||
| 1208 | || (! defined $fixWidthPixels && defined $fixHeightPixels) | ||
| 1209 | ) { | ||
| 1210 | return $axmud::CLIENT->writeImproper($self->_objClass . '->changeWinzone', @_); | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | # Check that the window is a 'grid' window | ||
| 1214 | if ( | ||
| 1215 | $winObj->winCategory ne 'grid' | ||
| 1216 | || ! $axmud::CLIENT->desktopObj->ivExists('gridWinHash', $winObj->number) | ||
| 1217 | || ! $winObj->areaObj | ||
| 1218 | || ! $winObj->areaObj->zoneObj | ||
| 1219 | ) { | ||
| 1220 | return $axmud::CLIENT->writeError( | ||
| 1221 | 'Can\'t move the window - window is not a grid window', | ||
| 1222 | $self->_objClass . '->changeWinzone', | ||
| 1223 | ); | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | # Check that the window is allowed in the new zone | ||
| 1227 | if ( | ||
| 1228 | ! $zoneObj->checkWinAllowed( | ||
| 1229 | $winObj->winType, | ||
| 1230 | $winObj->winName, | ||
| 1231 | $winObj->session, | ||
| 1232 | ) | ||
| 1233 | ) { | ||
| 1234 | return $axmud::CLIENT->writeError( | ||
| 1235 | 'Can\'t move the window - window is not allowed in zone #' . $zoneObj->number, | ||
| 1236 | $self->_objClass . '->changeWinzone', | ||
| 1237 | ); | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | # Set the provisional size of the window in its new zone | ||
| 1241 | # If called by GA::Cmd::FixWindow->do after the user manually changed the window's size, | ||
| 1242 | # use that size | ||
| 1243 | # If the default flag has been set, use the new zone's default size, otherwise use the | ||
| 1244 | # window's current size | ||
| 1245 | $blockSize = $axmud::CLIENT->gridBlockSize; | ||
| 1246 | |||
| 1247 | if ($fixWidthPixels) { | ||
| 1248 | |||
| 1249 | $widthPixels = $fixWidthPixels; | ||
| 1250 | $heightPixels = $fixHeightPixels; | ||
| 1251 | |||
| 1252 | # When the window object was first created, the call to $self->fineTuneWinSize modified | ||
| 1253 | # the size of the window due to window controls. We must reverse those changes (if | ||
| 1254 | # they were applied), so that our call to $zoneObj->placeWin() will have the same | ||
| 1255 | # initial window size as it would have had, if GA::Obj::Workspace->chooseWinPosn had | ||
| 1256 | # been calling it | ||
| 1257 | if ($winObj->winType ne 'external') { | ||
| 1258 | |||
| 1259 | $widthPixels += ( | ||
| 1260 | $winObj->workspaceObj->controlsLeftSize | ||
| 1261 | + $winObj->workspaceObj->controlsRightSize | ||
| 1262 | ); | ||
| 1263 | |||
| 1264 | $heightPixels += ( | ||
| 1265 | $winObj->workspaceObj->controlsTopSize | ||
| 1266 | + $winObj->workspaceObj->controlsBottomSize | ||
| 1267 | ); | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | } elsif ($defaultSizeFlag) { | ||
| 1271 | |||
| 1272 | $widthPixels = $zoneObj->defaultAreaWidth * $blockSize; | ||
| 1273 | $heightPixels = $zoneObj->defaultAreaHeight * $blockSize; | ||
| 1274 | |||
| 1275 | } else { | ||
| 1276 | |||
| 1277 | $widthPixels = $winObj->areaObj->widthBlocks * $blockSize; | ||
| 1278 | $heightPixels = $winObj->areaObj->heightBlocks * $blockSize; | ||
| 1279 | } | ||
| 1280 | |||
| 1281 | # Try to find room for the window in the new zone | ||
| 1282 | # First define a provisional position for the window at the zone's start corner | ||
| 1283 | ($widthBlocks, $heightBlocks, $xPosBlocks, $yPosBlocks) | ||
| 1284 | = $zoneObj->findProvWinPosn($widthPixels, $heightPixels); | ||
| 1285 | |||
| 1286 | # Try to find room for the window in the new zone. Start at the default layer, then check | ||
| 1287 | # other layers | ||
| 1288 | ($successFlag, $layer, $xPosBlocks, $yPosBlocks) = $zoneObj->placeWin( | ||
| 1289 | $self->defaultLayer, | ||
| 1290 | $xPosBlocks, | ||
| 1291 | $yPosBlocks, | ||
| 1292 | $widthBlocks, | ||
| 1293 | $heightBlocks, | ||
| 1294 | # In case the window already exists in the zone, any space it currently occupies is | ||
| 1295 | # available | ||
| 1296 | $winObj, | ||
| 1297 | ); | ||
| 1298 | |||
| 1299 | if (!$successFlag) { | ||
| 1300 | |||
| 1301 | # There is no room for the window in this zone | ||
| 1302 | return $axmud::CLIENT->writeError( | ||
| 1303 | 'Can\'t move the window - ouldn\'t find room for the \'' . $winObj->winType | ||
| 1304 | . '\' window anywhere in zone #' . $zoneObj->number, | ||
| 1305 | $self->_objClass . '->changeWinzone', | ||
| 1306 | ); | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | # If the window position on the grid puts it rather close to the edge (or edges) of the | ||
| 1310 | # zone, and if the gaps between the window and the zone's edge are empty, adjust the size | ||
| 1311 | # of the window to fill the gap (this prevents small areas of the zone from always being | ||
| 1312 | # empty: makes the desktop look nice). If the maximum allowable gap size is 0, don't fill | ||
| 1313 | # gaps at all | ||
| 1314 | if ($axmud::CLIENT->gridGapMaxSize) { | ||
| 1315 | |||
| 1316 | ($xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks) | ||
| 1317 | = $zoneObj->adjustSingleWin( | ||
| 1318 | $layer, | ||
| 1319 | $xPosBlocks, | ||
| 1320 | $yPosBlocks, | ||
| 1321 | $widthBlocks, | ||
| 1322 | $heightBlocks, | ||
| 1323 | ); | ||
| 1324 | } | ||
| 1325 | |||
| 1326 | # There is room for the window in the specified zone, at layer $layer and grid coordinates | ||
| 1327 | # $xPosBlocks, $yPosBlocks | ||
| 1328 | $oldZoneObj = $winObj->areaObj->zoneObj; | ||
| 1329 | if ($oldZoneObj) { | ||
| 1330 | |||
| 1331 | if ($oldZoneObj ne $zoneObj) { | ||
| 1332 | |||
| 1333 | $successFlag = $oldZoneObj->removeArea($winObj->areaObj); | ||
| 1334 | |||
| 1335 | } else { | ||
| 1336 | |||
| 1337 | # The original and destination zones are the same, but the window's old and new size | ||
| 1338 | # and position on the workspace won't necessarily be the same. Don't call | ||
| 1339 | # $oldZoneObj->replaceAreaSpace to reshuffle window positions yet, because that | ||
| 1340 | # will mess up everything | ||
| 1341 | $successFlag = $oldZoneObj->removeArea( | ||
| 1342 | $winObj->areaObj, | ||
| 1343 | TRUE, | ||
| 1344 | ); | ||
| 1345 | } | ||
| 1346 | |||
| 1347 | if (! $successFlag) { | ||
| 1348 | |||
| 1349 | return $axmud::CLIENT->writeError( | ||
| 1350 | 'Can\'t move the window - attempt to move it from its current zone failed', | ||
| 1351 | $self->_objClass . '->changeWinzone', | ||
| 1352 | ); | ||
| 1353 | } | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | # Work out the window object's size and position on the desktop in pixels | ||
| 1357 | $xPosPixels = $self->xPosPixels + (($zoneObj->xPosBlocks + $xPosBlocks) * $blockSize); | ||
| 1358 | $yPosPixels = $self->yPosPixels + (($zoneObj->yPosBlocks + $yPosBlocks) * $blockSize); | ||
| 1359 | $widthPixels = ($widthBlocks * $blockSize); | ||
| 1360 | $heightPixels = ($heightBlocks * $blockSize); | ||
| 1361 | |||
| 1362 | # Correct for small gaps in the grid and for window controls | ||
| 1363 | ($xPosPixels, $yPosPixels, $widthPixels, $heightPixels) = $self->fineTuneWinSize( | ||
| 1364 | $winObj->winType, | ||
| 1365 | $xPosPixels, | ||
| 1366 | $yPosPixels, | ||
| 1367 | $widthPixels, | ||
| 1368 | $heightPixels, | ||
| 1369 | ); | ||
| 1370 | |||
| 1371 | # Mark the window as added to the new zone | ||
| 1372 | $areaObj = $zoneObj->addArea( | ||
| 1373 | $layer, | ||
| 1374 | $xPosBlocks, | ||
| 1375 | $yPosBlocks, | ||
| 1376 | $widthBlocks, | ||
| 1377 | $heightBlocks, | ||
| 1378 | $xPosPixels, | ||
| 1379 | $yPosPixels, | ||
| 1380 | $widthPixels, | ||
| 1381 | $heightPixels, | ||
| 1382 | $winObj->session, | ||
| 1383 | ); | ||
| 1384 | |||
| 1385 | if (! $areaObj) { | ||
| 1386 | |||
| 1387 | return $axmud::CLIENT->writeError( | ||
| 1388 | 'Can\'t move the window - attempt to move it to its new zone failed', | ||
| 1389 | $self->_objClass . '->changeWinzone', | ||
| 1390 | ); | ||
| 1391 | } | ||
| 1392 | |||
| 1393 | # Update the window object's own IVs | ||
| 1394 | $winObj->set_workspaceGridObj($self); | ||
| 1395 | $winObj->set_workspaceObj($self->workspaceObj); | ||
| 1396 | $winObj->set_areaObj($areaObj); | ||
| 1397 | |||
| 1398 | # If the new zone is different from the old one, update the workspace grid object's IVs too | ||
| 1399 | if ($oldZoneObj && $oldZoneObj->workspaceGridObj ne $zoneObj->workspaceGridObj) { | ||
| 1400 | |||
| 1401 | $oldZoneObj->workspaceGridObj->ivDelete('gridWinHash', $winObj->number); | ||
| 1402 | $zoneObj->workspaceGridObj->add_gridWin($winObj); | ||
| 1403 | } | ||
| 1404 | |||
| 1405 | # Resize the window and move it to the correct location | ||
| 1406 | $self->workspaceObj->moveResizeWin( | ||
| 1407 | $winObj, | ||
| 1408 | $xPosPixels, | ||
| 1409 | $yPosPixels, | ||
| 1410 | $widthPixels, | ||
| 1411 | $heightPixels, | ||
| 1412 | ); | ||
| 1413 | |||
| 1414 | # Reshuffle the positions of all windows in the zone, if necessary, in order to fill smaller | ||
| 1415 | # gaps to fill up the zone, or expand larger ones to make room for another window | ||
| 1416 | # If the global flag isn't set allowing these adjustments, or if the zone has a maximum of | ||
| 1417 | # 1 window, don't make any adjustments | ||
| 1418 | if ( | ||
| 1419 | $axmud::CLIENT->gridAdjustmentFlag | ||
| 1420 | && $zoneObj->areaMax != 1 | ||
| 1421 | && ( | ||
| 1422 | # Windows are stacked horizontally, and there's only room for one (default size) | ||
| 1423 | # window in each row | ||
| 1424 | ( | ||
| 1425 | $zoneObj->orientation eq 'horizontal' | ||
| 1426 | && $zoneObj->heightBlocks >= $zoneObj->defaultAreaHeight | ||
| 1427 | && $zoneObj->heightBlocks < ($zoneObj->defaultAreaHeight * 2) | ||
| 1428 | # Windows are stacked vertically, and there's only room for one (default size) | ||
| 1429 | # window in each column | ||
| 1430 | ) || ( | ||
| 1431 | $zoneObj->orientation eq 'vertical' | ||
| 1432 | && $zoneObj->widthBlocks >= $zoneObj->defaultAreaWidth | ||
| 1433 | && $zoneObj->widthBlocks < ($zoneObj->defaultAreaWidth * 2) | ||
| 1434 | ) | ||
| 1435 | ) | ||
| 1436 | ) { | ||
| 1437 | $zoneObj->adjustMultipleWin($layer); | ||
| 1438 | } | ||
| 1439 | |||
| 1440 | # Let the calling function display a success message | ||
| 1441 | return 1; | ||
| 1442 | } | ||
| 1443 | |||
| 1444 | ################## | ||
| 1445 | # Accessors - set | ||
| 1446 | |||
| 1447 | sub set_currentLayer { | ||
| 1448 | |||
| 1449 | my ($self, $layer, $check) = @_; | ||
| 1450 | |||
| 1451 | # Check for improper arguments | ||
| 1452 | if (! defined $layer || defined $check) { | ||
| 1453 | |||
| 1454 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_currentLayer', @_); | ||
| 1455 | } | ||
| 1456 | |||
| 1457 | $self->ivPoke('currentLayer', $layer); | ||
| 1458 | |||
| 1459 | return 1; | ||
| 1460 | } | ||
| 1461 | |||
| 1462 | sub inc_currentLayer { | ||
| 1463 | |||
| 1464 | my ($self, $check) = @_; | ||
| 1465 | |||
| 1466 | # Check for improper arguments | ||
| 1467 | if (defined $check) { | ||
| 1468 | |||
| 1469 | return $axmud::CLIENT->writeImproper($self->_objClass . '->inc_currentLayer', @_); | ||
| 1470 | } | ||
| 1471 | |||
| 1472 | # Update IVs | ||
| 1473 | $self->ivIncrement('currentLayer'); | ||
| 1474 | |||
| 1475 | return 1; | ||
| 1476 | } | ||
| 1477 | |||
| 1478 | sub dec_currentLayer { | ||
| 1479 | |||
| 1480 | my ($self, $check) = @_; | ||
| 1481 | |||
| 1482 | # Check for improper arguments | ||
| 1483 | if (defined $check) { | ||
| 1484 | |||
| 1485 | return $axmud::CLIENT->writeImproper($self->_objClass . '->dec_currentLayer', @_); | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | # Update IVs | ||
| 1489 | $self->ivDecrement('currentLayer'); | ||
| 1490 | |||
| 1491 | return 1; | ||
| 1492 | } | ||
| 1493 | |||
| 1494 | sub add_gridWin { | ||
| 1495 | |||
| 1496 | # Called by GA::Obj::Workspace->createGridWin, ->createSimpleGridWin and | ||
| 1497 | # ->enableWorkspaceGrids, as well as $self->changeWinzone | ||
| 1498 | |||
| 1499 | my ($self, $winObj, $check) = @_; | ||
| 1500 | |||
| 1501 | # Check for improper arguments | ||
| 1502 | if (! defined $winObj || defined $check) { | ||
| 1503 | |||
| 1504 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_gridWin', @_); | ||
| 1505 | } | ||
| 1506 | |||
| 1507 | $self->ivAdd('gridWinHash', $winObj->number, $winObj); | ||
| 1508 | |||
| 1509 | return 1; | ||
| 1510 | } | ||
| 1511 | |||
| 1512 | sub del_gridWin { | ||
| 1513 | |||
| 1514 | # Called by GA::Win::Internal->winDestroy, etc | ||
| 1515 | |||
| 1516 | my ($self, $obj, $check) = @_; | ||
| 1517 | |||
| 1518 | # Check for improper arguments | ||
| 1519 | if (! defined $obj || defined $check) { | ||
| 1520 | |||
| 1521 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_gridWin', @_); | ||
| 1522 | } | ||
| 1523 | |||
| 1524 | if (! $self->ivExists('gridWinHash', $obj->number)) { | ||
| 1525 | |||
| 1526 | return undef; | ||
| 1527 | |||
| 1528 | } else { | ||
| 1529 | |||
| 1530 | $self->ivDelete('gridWinHash', $obj->number); | ||
| 1531 | # Also remove the area object from its zone | ||
| 1532 | if ($obj->areaObj && $obj->areaObj->zoneObj) { | ||
| 1533 | |||
| 1534 | $obj->areaObj->zoneObj->removeArea($obj->areaObj); | ||
| 1535 | } | ||
| 1536 | |||
| 1537 | return 1; | ||
| 1538 | } | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | sub reset_gridWinHash { | ||
| 1542 | |||
| 1543 | # Called by GA::Obj::Workspace->disableWorkspaceGrids | ||
| 1544 | |||
| 1545 | my ($self, $check) = @_; | ||
| 1546 | |||
| 1547 | # Check for improper arguments | ||
| 1548 | if (defined $check) { | ||
| 1549 | |||
| 1550 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_gridWinHash', @_); | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | $self->ivEmpty('gridWinHash'); | ||
| 1554 | |||
| 1555 | return undef; | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | ################## | ||
| 1559 | # Accessors - get | ||
| 1560 | |||
| 1561 | sub number | ||
| 1562 | { $_[0]->{number} } | ||
| 1563 | sub workspaceObj | ||
| 1564 | { $_[0]->{workspaceObj} } | ||
| 1565 | sub owner | ||
| 1566 | { $_[0]->{owner} } | ||
| 1567 | |||
| 1568 | sub zonemap | ||
| 1569 | { $_[0]->{zonemap} } | ||
| 1570 | |||
| 1571 | sub maxLayers | ||
| 1572 | { $_[0]->{maxLayers} } | ||
| 1573 | sub defaultLayer | ||
| 1574 | { $_[0]->{defaultLayer} } | ||
| 1575 | sub currentLayer | ||
| 1576 | { $_[0]->{currentLayer} } | ||
| 1577 | |||
| 1578 | sub widthBlocks | ||
| 1579 | { $_[0]->{widthBlocks} } | ||
| 1580 | sub heightBlocks | ||
| 1581 | { $_[0]->{heightBlocks} } | ||
| 1582 | sub xPosPixels | ||
| 1583 | { $_[0]->{xPosPixels} } | ||
| 1584 | sub yPosPixels | ||
| 1585 | { $_[0]->{yPosPixels} } | ||
| 1586 | |||
| 1587 | sub zoneHash | ||
| 1588 | { my $self = shift; return %{$self->{zoneHash}}; } | ||
| 1589 | sub zoneCount | ||
| 1590 | { $_[0]->{zoneCount} } | ||
| 1591 | sub zonemapXCoordHash | ||
| 1592 | { my $self = shift; return %{$self->{zonemapXCoordHash}}; } | ||
| 1593 | sub zonemapYCoordHash | ||
| 1594 | { my $self = shift; return %{$self->{zonemapYCoordHash}}; } | ||
| 1595 | |||
| 1596 | sub gridWinHash | ||
| 1597 | { my $self = shift; return %{$self->{gridWinHash}}; } | ||
| 1598 | } | ||
| 1599 | |||
| 1600 | # Package must return a true value | ||
| 1601 | 1 |