Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Win/Internal.pm view on Meta::CPAN
$spacing = $self->stripSpacingPixels;
}
# Add the strip object to the packing box
if ($stripObj->visibleFlag) {
if (
$winmapObj->orientation eq 'top'
|| $winmapObj->orientation eq 'left'
) {
$packingBox->pack_start(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
} else {
$packingBox->pack_end(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
}
}
# Inform all existing strip objects of this strip object's birth
foreach my $otherStripObj ($self->stripList) {
if ($stripObj ne $otherStripObj) {
$stripObj->notify_addStripObj($otherStripObj);
}
}
}
}
}
} until (! @initList);
# Now draw table objects on the GA::Strip::Table, using the layout specified by the winmap's
# winzones. We assume that the winmap has already checked that its winzones have valid
# sizes and don't overlap each other
@winzoneList = sort {$a->number <=> $b->number} ($winmapObj->ivValues('zoneHash'));
foreach my $winzoneObj (@winzoneList) {
$self->tableStripObj->addTableObj(
$winzoneObj->packageName,
$winzoneObj->left,
$winzoneObj->right,
$winzoneObj->top,
$winzoneObj->bottom,
$winzoneObj->objName,
$winzoneObj->initHash,
);
}
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
return 1;
}
sub redrawWidgets {
# Can be called by anything
# Resets the Gtk3::Window by re-packing the strip objects in $self->stripList
# When called by $self->addStripObj, the new strip object will be packed for the first time.
# When called by $self->removeStripObj, the removed strip object won't be packed at all
#
# NB This is a legacy function that probably should not be called at all. Due to Gtk
# performance issues, it's nearly always better to call $self->hideStripObj,
# ->revealStripObj or ->replaceStripObj instead
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 on success
my ($self, $check) = @_;
# Local variables
my (
$winmapObj, $gaugeStripObj,
@modList,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->redrawWidgets', @_);
}
# Get the winmap object specified by $self->winmap, or a default winmap, if $self->winmap
# is 'undef'
$winmapObj = $self->getWinmap();
# Empty the packing box of existing strips
foreach my $child ($self->packingBox->get_children()) {
$self->packingBox->remove($child);
}
# Get a list of existing strips that are actually visible
foreach my $stripObj ($self->stripList) {
if ($stripObj->visibleFlag) {
push (@modList, $stripObj);
}
}
# Re-pack all visible strips, leaving a gap between strips that aren't at the beginning or
# end of the list
if (@modList) {
for (my $count = 0; $count < (scalar @modList); $count++) {
my ($stripObj, $spacing);
$stripObj = $modList[$count];
if (! $stripObj->spacingFlag || $count == 0 || $count == (scalar @modList - 1)) {
$spacing = 0;
} else {
$spacing = $self->stripSpacingPixels;
}
if (
$winmapObj->orientation eq 'top'
|| $winmapObj->orientation eq 'left'
) {
$self->packingBox->pack_start(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
} else {
$self->packingBox->pack_end(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
}
}
}
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
# Any Gtk3::TextViews will now be using the colours of the most recently-created
# Gtk3::TextView, not the colours that we want them to use. Update colours for all pane
# objects (GA::Table::Pane) before the forthcoming call to ->winShowAll
$self->updateColourScheme(undef, TRUE);
# Make everything visible
$self->winShowAll($self->_objClass . '->redrawWidgets');
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->redrawWidgets');
# Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
# Make sure all the textviews are scrolled to the bottom
$self->rescrollTextViews();
# Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
# themselves will have disappeared
$gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
$gaugeStripObj->updateGauges();
# (Need to call this a second time, or the re-draw doesn't work...)
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->redrawWidgets');
}
return 1;
}
# ->signal_connects
sub setDeleteEvent {
# Called by $self->winSetup
# Set up a ->signal_connect to watch out for the user manually closing the 'internal' window
# If it's a 'main' window and there are no 'main' windows left, halt the client
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
}
if ($self->winType eq 'main' && $axmud::CLIENT->shareMainWinFlag) {
$self->winBox->signal_connect('delete-event' => sub {
# Prompt the user for confirmation, if required
if (! $self->checkConnectedSessions()) {
# Don't close the 'main' window
return 1;
lib/Games/Axmud/Win/Internal.pm view on Meta::CPAN
$self->ivPoke('workspaceGridObj', $gridObj);
last OUTER;
}
}
}
# In case the change of visible session isn't the result of the user clicking a
# session's default tab, make the new visible session's default tab the visible one.
# If that default tab is a simple tab, then there's nothing to do
# ($session->defaultTabObj won't be set yet, if $session->start is still executing)
if ($session->defaultTabObj) {
$paneObj = $session->defaultTabObj->paneObj;
$tabObj = $paneObj->findSession($session);
$visibleTabObj = $paneObj->getVisibleTab();
if ($paneObj->notebook && $tabObj && $visibleTabObj && $tabObj ne $visibleTabObj) {
$paneObj->setVisibleTab($tabObj);
}
}
# If the session's tab label is in a different colour, meaning that text had been
# received from the world but hadn't been viewed by the user yet, reset the flag to
# show that the text is now visible to the user
$session->reset_showNewTextFlag();
# Update information stored in the 'main' window's connection info strip, if visible
$self->setHostLabel($session->getHostLabelText());
$self->setTimeLabel($session->getTimeLabelText());
# Update certain strip objects in any 'internal' window used by the new visible session
# (if any; the TRUE flag means 'return 'internal' windows only)
foreach my $winObj ($axmud::CLIENT->desktopObj->listSessionGridWins($session, TRUE)) {
# Reset the 'internal' window's entry box and blinkers, if any
$winObj->resetEntry();
$winObj->resetBlinkers();
}
# Fire any hooks that are using the 'visible_session' hook event
$session->checkHooks('visible_session', undef);
# Fire any hooks that are using the 'change_visible' hook event
foreach my $otherSession ($axmud::CLIENT->listSessions()) {
if ($otherSession ne $session) {
$otherSession->checkHooks('change_visible', $session->number);
}
}
}
# Update all 'internal' windows
foreach my $winObj ($axmud::CLIENT->desktopObj->listGridWins()) {
if (
$winObj->winType eq 'main'
|| $winObj->winType eq 'protocol'
|| $winObj->winType eq 'custom'
) {
# Sensitise/desensitise menu items in 'internal' windows, as appropriate
$winObj->restrictMenuBars();
$winObj->restrictToolbars();
# Update the gauge box, if visible
$winObj->updateGauges();
# Sensitise or desensitise widgets, as appropriate
$winObj->setWidgetsIfSession();
# Update widgets, as appropriate
$winObj->setWidgetsChangeSession();
# Make any changes visible
$winObj->winShowAll($self->_objClass . '->setVisibleSession');
}
}
return 1;
}
sub checkConnectedSessions {
# Called by $self->setDeleteEvent
# If the user tries to manually close a 'main' window, counts the number of connected
# sessions (not including disconencted or 'connect offline' mode sessions) using this
# window as their 'main' window
# If any are found, prompts the user for confirmation (if the GA::Client flag requires us
# to do that)
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if the window should not be closed
# 1 if the window can be closed
my ($self, $check) = @_;
# Local variables
my ($count, $choice, $msg);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->checkConnectedSessions',
@_,
);
}
if (! $axmud::CLIENT->confirmCloseMainWinFlag) {
# The window can be closed - no confirmation required
return 1;
}
# Otherwise, count connected sessions
$count = 0;
foreach my $session ($axmud::CLIENT->ivValues('sessionHash')) {
if (
$session->mainWin
&& $session->mainWin eq $self
lib/Games/Axmud/Win/Internal.pm view on Meta::CPAN
#
# Return values
# 'undef' on improper arguments or if this window isn't a 'main' window
# 1 otherwise
my ($self, $flag, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->setMainWinTitle', @_);
}
# Ignore this function call for other types of 'grid' window
if ($self->winType eq 'main') {
return undef;
# Set the window title
} elsif ($flag) {
$self->winWidget->set_title('*' . $axmud::SCRIPT);
} else {
$self->winWidget->set_title($axmud::SCRIPT);
}
return 1;
}
sub setWinTitle {
# Can be called by anything to change the text in the window's title bar
# Does nothing if this window is a 'main' window (code should call $self->setMainWinTitle
# instead)
#
# Expected arguments
# $text - The text to use
#
# Return values
# 'undef' on improper arguments or if this window isn't a 'main' window
# 1 otherwise
my ($self, $text, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->setWinTitle', @_);
}
if ($self->enabledFlag && $self->winType ne 'main' && $self->winWidget eq $self->winBox) {
$self->winWidget->set_title($text);
}
return 1;
}
sub restrictMenuBars {
# Called by GA::Obj::Desktop->restrictWidgets
# Sensitise or desensitise the menu bar in this 'internal' window, depending on current
# conditions. (Don't do anything if this window doesn't use a strip object for a menu bar)
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if this window doesn't use a strip object for a menu
# bar
# 1 otherwise
my ($self, $check) = @_;
# Local variables
my (
$stripObj, $openFlag, $setupFlag,
@list, @sensitiseList, @desensitiseList,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictMenuBars', @_);
}
# Get the strip object
$stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::MenuBar');
if (! $stripObj) {
# Nothing to sensitise/desensitise
return undef;
}
# Test whether this is a 'main' window with a visible session whose status is 'connected' or
# 'offline' (for the sake of efficiency)
if (
$self->visibleSession
&& (
$self->visibleSession->status eq 'connected'
|| $self->visibleSession->status eq 'offline'
)
) {
$openFlag = TRUE;
}
# Test whether the setup wizwin is open (in which case, almost everything is desensitised)
OUTER: foreach my $winObj ($axmud::CLIENT->desktopObj->ivValues('freeWinHash')) {
if ($winObj->isa('Games::Axmud::WizWin::Setup')) {
$setupFlag = TRUE;
# In addition, the following menu items are desensitised
push (@desensitiseList,
# 'World' column
'connect', 'stop_client',
# 'Edit' column
'test_pattern',
# 'Help' column
'help', 'about', 'credits', 'license',
);
last OUTER;
}
}
# Menu bar items that require a 'main' window with a visible session
@list = (
# 'World' column
'reconnect', 'reconnect_offline',
'xconnect', 'xconnect_offline',
'quit_all',
'exit_all',
'stop_session',
# 'File' column
'test_file',
'show_files', 'show_file_meta',
# 'Axbasic' column
'check_script', 'edit_script',
# 'Plugins' column
'load_plugin', 'show_plugin',
);
if (! $setupFlag && $self->visibleSession) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline'
@list = (
# 'World' column
'login',
'quit', 'qquit',
'exit', 'xxit',
# 'File' column
'load_all', 'load_file',
'save_all', 'save', 'save_options',
'import_files',
# 'export_all_files', 'export_file',
'export_file',
'import_data',
'export_data',
'backup_restore_data',
'disable_world_save', 'disable_save_load',
# 'Edit' column
'edit_quick_prefs', 'edit_client_prefs', 'edit_session_prefs',
'edit_current_world',
'run_locator_wiz', 'edit_world_model', 'edit_dictionary',
'simulate',
# 'Interfaces' column
'active_interfaces',
'show_triggers', 'show_aliases', 'show_macros', 'show_timers', 'show_hooks',
'show_cmds', 'show_routes',
# 'Tasks' column
'freeze_tasks', 'start_new_task', 'chat_task', 'chat_task_start',
'run_locator_wiz_2',
'other_task',
# 'Display' column
'open_automapper', 'open_object_viewer',
'activate_grid', 'activate_grid_with', 'reset_grid', 'disactivate_grid',
'win_components', 'current_layer', 'window_storage',
'test_controls', 'test_panels',
# 'Commands' column
'repeat_cmd', 'repeat_second', 'repeat_interval',
'cancel_repeat',
# 'Axbasic' column
'run_script', 'run_script_task',
);
if (! $setupFlag && $openFlag) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and whose ->currentGuild is defined
@list = (
# 'Edit' column
'edit_current_guild',
# 'Interfaces' column
'guild_triggers', 'guild_aliases', 'guild_macros', 'guild_timers', 'guild_hooks',
'guild_cmds', 'guild_routes',
);
if (! $setupFlag && $openFlag && $self->visibleSession->currentGuild) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and whose ->currentRace is defined
@list = (
# 'Edit' column
'edit_current_race',
# 'Interfaces' column
'race_triggers', 'race_aliases', 'race_macros', 'race_timers', 'race_hooks',
'race_cmds', 'race_routes',
);
if (! $setupFlag && $openFlag && $self->visibleSession->currentRace) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and whose ->currentChar is defined
@list = (
# 'Edit' column
'edit_current_char',
# 'Interfaces' column
'char_triggers', 'char_aliases', 'char_macros', 'char_timers', 'char_hooks',
'char_cmds', 'char_routes',
);
if (! $setupFlag && $openFlag && $self->visibleSession->currentChar) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and $stripObj->saveAllSessionsFlag set to FALSE
@list = (
# 'File' column
'save_file',
);
if (! $setupFlag && $openFlag && ! $stripObj->saveAllSessionsFlag) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and whose ->recordingPausedFlag is FALSE
@list = (
# 'Recordings' column
'start_stop_recording',
);
if (! $setupFlag && $openFlag && ! $self->visibleSession->recordingPausedFlag) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and whose ->recordingFlag is TRUE
@list = (
# 'Recordings' column
'pause_recording',
);
if (! $setupFlag && $openFlag && $self->visibleSession->recordingFlag) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Chat task
@list = (
# 'Tasks' column
'edit_chat_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->chatTask) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Channels task
@list = (
# 'Tasks' column
'channels_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->channelsTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'channels_task_start');
} else {
push (@sensitiseList, 'channels_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Compass task
@list = (
# 'Tasks' column
'compass_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->compassTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'compass_task_start');
} else {
push (@sensitiseList, 'compass_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and NO Condition task
@list = (
# 'Tasks' column
'condition_task_start',
);
if (! $setupFlag && $openFlag && ! defined $self->visibleSession->conditionTask) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Divert task
@list = (
# 'Tasks' column
'divert_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->divertTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'divert_task_start');
} else {
push (@sensitiseList, 'divert_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and an Inventory task
@list = (
# 'Tasks' column
'inventory_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->inventoryTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'inventory_task_start');
} else {
push (@sensitiseList, 'inventory_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Locator task
@list = (
# 'Tasks' column
'locator_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->locatorTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'locator_task_start');
} else {
push (@sensitiseList, 'locator_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Status task
@list = (
# 'Tasks' column
'status_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->statusTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'status_task_start');
} else {
push (@sensitiseList, 'status_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a 'main' window with a visible session whose status is
# 'connected' or 'offline' and a Watch task
@list = (
# 'Tasks' column
'watch_task',
);
if (! $setupFlag && $openFlag && $self->visibleSession->watchTask) {
push (@sensitiseList, @list);
push (@desensitiseList, 'watch_task_start');
} else {
push (@sensitiseList, 'watch_task_start');
push (@desensitiseList, @list);
}
# Menu bar items that require a require a 'main' window with a visible session whose status
# is 'connected' or 'offline' and GA::Session->recordingFlag
@list = (
# 'Recordings' column
'pause_resume_recording',
'recording_add_line', 'recording_add_break',
'recording_set_insertion', 'recording_cancel_insertion',
'recording_delete_line', 'recording_delete_multi', 'recording_delete_last',
);
if (! $setupFlag && $openFlag && $self->visibleSession->recordingFlag) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require a require a 'main' window with a visible session whose status
# is 'connected' or 'offline', and either GA::Session->recordingFlag or ->recordingList
@list = (
# 'Recordings' column
'show_recording', 'copy_recording',
);
if (
! $setupFlag
&& $openFlag
&& ($self->visibleSession->recordingFlag || $self->visibleSession->recordingList)
) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Menu bar items that require GA::Client->browserCmd
@list = (
# 'Help' column
'go_website',
);
if (! $setupFlag && $axmud::CLIENT->browserCmd) {
push (@sensitiseList, @list);
} else {
push (@desensitiseList, @list);
}
# Sensitise/desensitise menu bar items
$stripObj->sensitiseWidgets(@sensitiseList);
$stripObj->desensitiseWidgets(@desensitiseList);
# All menu items added by plugins require a 'main' window with a visible session, and the
# plugin itself must be must be enabled
foreach my $plugin ($stripObj->ivKeys('pluginMenuItemHash')) {
my ($widget, $pluginObj);
$widget = $stripObj->ivShow('pluginMenuItemHash', $plugin);
$pluginObj = $axmud::CLIENT->ivShow('pluginHash', $plugin);
if (! $setupFlag && $self->visibleSession && $pluginObj->enabledFlag) {
$widget->set_sensitive(TRUE);
} else {
$widget->set_sensitive(FALSE);
}
}
return 1;
}
sub restrictToolbars {
# Called by GA::Obj::Desktop->restrictWidgets
# Sensitise or desensitise the toolbar in this 'internal' window, depending on current
# conditions. (Don't do anything if this window doesn't use a strip object for a toolbar)
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if this window doesn't use a strip object for a toolbar
# 1 otherwise
my ($self, $check) = @_;
# Local variables
my (
$stripObj,
@list, @sensitiseList, @desensitiseList,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictToolbars', @_);
}
# Get the strip object
$stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Toolbar');
if (! $stripObj) {
# Nothing to sensitise/desensitise
return undef;
}
# Test whether the setup wizwin is open (in which case, everything is desensitised)
OUTER: foreach my $winObj ($axmud::CLIENT->desktopObj->ivValues('freeWinHash')) {
if ($winObj->isa('Games::Axmud::WizWin::Setup')) {
foreach my $widget ($stripObj->toolbarWidgetList) {
$widget->set_sensitive(FALSE);
}
return 1;
}
}
lib/Games/Axmud/Win/Internal.pm view on Meta::CPAN
# Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
# list
# If $index is -1, it means 'pack at the end'
if ($index == 0 || $index == -1) {
$spacing = 0;
} else {
$spacing = $self->stripSpacingPixels;
}
if ($index > -1) {
$self->packingBox->pack_start(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
if ($index > 0) {
$self->packingBox->reorder_child($stripObj->packingBox, $posn);
}
} else {
$self->packingBox->pack_end(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
}
}
# Update IVs
$self->ivAdd('stripHash', $stripObj->number, $stripObj);
if (! $self->ivExists('firstStripHash', $packageName)) {
$self->ivAdd('firstStripHash', $packageName, $stripObj);
}
$self->ivIncrement('stripCount');
$self->ivSplice('stripList', $index, 0, $stripObj);
if ($packageName eq 'Games::Axmud::Strip::Table') {
$self->ivPoke('tableStripObj', $stripObj);
}
# Notify all other strip objects of the new strip object's birth
foreach my $otherStripObj (
sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
) {
if ($otherStripObj ne $stripObj) {
$otherStripObj->notify_addStripObj($stripObj);
}
}
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
# Make everything visible
$self->winShowAll($self->_objClass . '->addStripObj');
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addStripObj');
# Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
# Make sure all the textviews are scrolled to the bottom
$self->rescrollTextViews();
# Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
# themselves will have disappeared
$gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
$gaugeStripObj->updateGauges();
# (Need to call this a second time, or the re-draw doesn't work...)
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addStripObj');
}
return $stripObj;
}
sub removeStripObj {
# Can be called by anything
# Removes a strip object (inheriting from GA::Generic::Strip) from the list of strip objects
# that can be displayed in this window (whether the Gtk widget was actually drawn, or not,
# depends on the value of the strip object's ->visibleFlag)
# Can't be used to remove the compulsory GA::Strip::Table object
#
# Expected arguments
# $stripObj - The strip object to remove
#
# Return values
# 'undef' on improper arguments, if $stripObj is the compulsory GA::Strip::Table object
# or if the object doesn't exist
# 1 otherwise
my ($self, $stripObj, $check) = @_;
# Local variables
my (
$gaugeStripObj,
@stripList, @resetList,
);
# Check for improper arguments
if (! defined $stripObj || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->removeStripObj', @_);
}
# The GA::Strip::Table object is compulsory, also check that the strip object actually
# exists in the window
if (
$stripObj->_objClass eq 'Games::Axmud::Strip::Table'
|| ! $self->ivExists('stripHash', $stripObj->number)
) {
return undef
}
# Tell the strip object it's about to be removed, so it can do any necessary tidying up
$stripObj->objDestroy();
# Remove the Gtk3 widget that's contains the whole strip
$axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
# Remove the object by updating IVs
$self->ivDelete('stripHash', $stripObj->number);
foreach my $otherObj ($self->stripList) {
if ($otherObj ne $stripObj) {
push (@stripList, $otherObj);
}
}
$self->ivPoke('stripList', @stripList);
# $self->firstStripHash contains the earliest-created instance of this type of strip object.
# Update or reset it
$self->ivDelete('firstStripHash', $stripObj->_objClass);
@resetList = sort {$a->number <=> $b->number} ($self->ivValues('stripHash'));
OUTER: foreach my $otherObj (@resetList) {
if ($otherObj->_objClass eq $stripObj->_objClass) {
$self->ivAdd('firstStripHash', $otherObj->_objClass, $otherObj);
last OUTER;
}
}
# Notify all other strip objects of this strip object's demise
foreach my $otherStripObj (
sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
) {
if ($otherStripObj ne $stripObj) {
$otherStripObj->notify_removeStripObj($stripObj);
}
}
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
# Make everything visible
$self->winShowAll($self->_objClass . '->removeStripObj');
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->removeStripObj');
# Hack to resolve a Gtk3 issue, in which a white area appears at the bottom of textviews
# when the gauge strip object is removed (and possibly in similar situations)
foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
if ($tableObj->type eq 'pane') {
foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
$tabObj->textViewObj->insertNewLine();
}
}
}
# Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
# Make sure all the textviews are scrolled to the bottom
$self->rescrollTextViews();
# Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
# themselves will have disappeared
$gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
$gaugeStripObj->updateGauges();
# (Need to call this a second time, or the re-draw doesn't work...)
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->removeStripObj');
}
return 1;
}
sub addStrip {
# Convenient shortcut to $self->addStripObj, which expects a package name like
# GA::Strip::GaugeBox as an argument
#
# This function accepts a string, which can be any of the following (case-insensitive):
# 'menu' / 'menubar' / 'menu_bar' - adds a GA::Strip::MenuBar
# 'tool' / 'toolbar' / 'tool_bar' - adds a GA::Strip::Toolbar
# 'gauge' / 'gaugebox' / 'gauge_box' - adds a GA::Strip::GaugeBox
# 'entry' - adds a GA::Strip::Entry
# 'connect' / 'info' / 'connectinfo' / 'connect_info'
# - adds a GA::Strip::ConnectInfo
#
# The string can also be a part of the package name itself. For example, if you create your
# own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
# the string 'MyObject' (case-sensitive)
# NB This function is not able to check that the package actually exists, although Axmud's
# built-in strip objects always exist
# NB This function can't be used to add the compulsory GA::Strip::Table which already
# exists
#
# Expected arguments
# $string - The string described above
#
# Optional arguments
# $index - The new strip object's position in the window. Strip objects are stored in
# $self->stripList, in the order in which they're drawn (which could be
# top to bottom, bottom to top, left to right or right to left). $index
# specifies the position in that list at which the new strip object is
# inserted. If $index is 0, the strip object is inserted at the beginning
# of the list. If $index is 1, it's inserted second, if $index is 2, it's
# inserted third, and so on. If $index is 'undef', or if its index is
# outside the list, the strip object is inserted at the beginning of the
# list
#
# Return values
# 'undef' on improper arguments or if the strip object can't be added
# Otherwise returns the strip object added
my ($self, $string, $index, $check) = @_;
# Local variables
my $packageName;
# Check for improper arguments
if (! defined $string || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->addStrip', @_);
}
# Convert $string into a package name
$packageName = $self->convertPackageName($string);
if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
return undef;
} else {
return $self->addStripObj($packageName, $index);
}
}
sub removeStrip {
# Convenient shortcut to $self->removeStripObj, which expects a package name like
# GA::Strip::GaugeBox as an argument
#
# This function accepts a string, which can be any of the following (case-insensitive):
# 'menu' / 'menubar' / 'menu_bar' - adds a GA::Strip::MenuBar
# 'tool' / 'toolbar' / 'tool_bar' - adds a GA::Strip::Toolbar
# 'gauge' / 'gaugebox' / 'gauge_box' - adds a GA::Strip::GaugeBox
# 'entry' - adds a GA::Strip::Entry
# 'connect' / 'info' / 'connectinfo' / 'connect_info'
# - adds a GA::Strip::ConnectInfo
#
# The string can also be a part of the package name itself. For example, if you create your
# own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
# the string 'MyObject' (case-sensitive)
#
# After converting the string into a package name, this function calls $self->removeStripObj
# to remove the earliest-created instance of that strip object, if any exists
# NB This function is not able to check that the package actually exists, although Axmud's
# built-in strip objects always exist
# NB This function can't be used to remove the compulsory GA::Strip::Table
#
# Expected arguments
# $string - The string described above
#
# Return values
# 'undef' on improper arguments or if no strip object is removed
# 1 if a strip object is removed
my ($self, $string, $check) = @_;
# Local variables
my ($packageName, $stripObj);
# Check for improper arguments
if (! defined $string || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->removeStrip', @_);
}
# Convert $string into a package name
$packageName = $self->convertPackageName($string);
if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
return undef;
}
# Find the earliest-created instance of that strip object
$stripObj = $self->ivShow('firstStripHash', $packageName);
if (! $stripObj) {
return undef;
} else {
return $self->removeStripObj($stripObj);
}
}
sub hideStripObj {
# Can be called by anything
# Hides a visible strip object; the strip object remains in the list of strip objects this
# window can display, but the Gtk widget itself is no longer drawn
# Can't be used to hide the compulsory GA::Strip::Table object
#
# Expected arguments
# $stripObj - The strip object to hide
#
# Return values
# 'undef' on improper arguments, if $stripObj is the compulsory GA::Strip::Table object,
# if the object doesn't exist or if it is already hidden
# 1 otherwise
my ($self, $stripObj, $check) = @_;
# Local variables
my $gaugeStripObj;
# Check for improper arguments
if (! defined $stripObj || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->hideStripObj', @_);
}
# The GA::Strip::Table object is compulsory, also check that the strip object actually
# exists in the window object's list of strip objects and is actually visible
if (
$stripObj->_objClass eq 'Games::Axmud::Strip::Table'
|| ! $self->ivExists('stripHash', $stripObj->number)
|| ! $stripObj->visibleFlag
) {
return undef
}
# Remove the Gtk3 widget that contains the whole strip
$axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
# Update IVs
$stripObj->set_visibleFlag(FALSE);
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
# Make everything visible
$self->winShowAll($self->_objClass . '->hideStripObj');
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->hideStripObj');
# Hack to resolve a Gtk3 issue, in which a white area appears at the bottom of textviews
# when the gauge strip object is removed (and possibly in similar situations)
foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
if ($tableObj->type eq 'pane') {
foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
$tabObj->textViewObj->insertNewLine();
}
}
}
# Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
# Make sure all the textviews are scrolled to the bottom
$self->rescrollTextViews();
# Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
# themselves will have disappeared
$gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
$gaugeStripObj->updateGauges();
# (Need to call this a second time, or the re-draw doesn't work...)
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->hideStripObj');
}
return 1;
}
sub revealStripObj {
# Can be called by anything
# Reveals a hidden strip object; the strip object was still in the list of strip objects
# this window can display, but the Gtk widget itself was not drawn, so draw it and add it
# to the window
#
# Expected arguments
# $stripObj - The strip object to reveal
#
# Return values
# 'undef' on improper arguments, if the object doesn't exist, if it is already visible or
# if there's an error in revealing it
# 1 otherwise
my ($self, $stripObj, $check) = @_;
# Local variables
my ($winmapObj, $count, $posn, $spacing, $gaugeStripObj);
# Check for improper arguments
if (! defined $stripObj || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->revealStripObj', @_);
lib/Games/Axmud/Win/Internal.pm view on Meta::CPAN
$winmapObj = $self->getWinmap();
# Check that the strip object actually exists in the window object's list of strip objects
# and is actually hidden
if (! $self->ivExists('stripHash', $stripObj->number) || $stripObj->visibleFlag) {
return undef
}
# Find the strip object's position in the list of visible strip objects
$count = 0;
OUTER: foreach my $otherObj ($self->stripList) {
if ($otherObj eq $stripObj) {
$posn = $count;
last OUTER;
} elsif ($otherObj->visibleFlag) {
$count++;
}
}
if (! defined $posn) {
# Strip object is missing (for some unlikely reason)
return undef;
}
# Draw the strip object's widgets
if (! $stripObj->objEnable($winmapObj)) {
return undef;
}
# Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
# list
if (! $count || $posn == ($count - 1)) {
$spacing = 0;
} else {
$spacing = $self->stripSpacingPixels;
}
$self->packingBox->pack_start(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
if ($posn != 0) {
$self->packingBox->reorder_child($stripObj->packingBox, $posn);
}
# Update IVs
$stripObj->set_visibleFlag(TRUE);
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
# Make everything visible
$self->winShowAll($self->_objClass . '->revealStripObj');
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->revealStripObj');
# Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
# Make sure all the textviews are scrolled to the bottom
$self->rescrollTextViews();
# Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
# themselves will have disappeared
$gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
$gaugeStripObj->updateGauges();
# (Need to call this a second time, or the re-draw doesn't work...)
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->revealStripObj');
}
return 1;
}
sub replaceStripObj {
# Can be called by anything
# If a strip object has been redrawn for any reason, replace the old Gtk widget with the
# new one. The strip object's ->packingBox IV must already have been set to the new Gtk
# widget before calling this function
#
# Expected arguments
# $stripObj - The strip object to replace
#
# Return values
# 'undef' on improper arguments, if the object doesn't exist or if it hidden
# 1 otherwise
my ($self, $stripObj, $check) = @_;
# Local variables
my ($count, $posn, $spacing, $gaugeStripObj);
# Check for improper arguments
if (! defined $stripObj || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceStripObj', @_);
}
# Check that the strip object actually exists in the window object's list of strip objects
# and is actually visible
if (! $self->ivExists('stripHash', $stripObj->number) || ! $stripObj->visibleFlag) {
return undef
}
# Find the strip object's position in the list of visible strip objects
$count = 0;
OUTER: foreach my $otherObj ($self->stripList) {
if ($otherObj eq $stripObj) {
$posn = $count;
last OUTER;
} elsif ($otherObj->visibleFlag) {
$count++;
}
}
if (! defined $posn) {
# Strip object is missing (for some unlikely reason)
return undef;
}
# Remove the old Gtk3 widget that contains the whole strip
$axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
# Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
# list
if (! $count || $posn == ($count - 1)) {
$spacing = 0;
} else {
$spacing = $self->stripSpacingPixels;
}
$self->packingBox->pack_start(
$stripObj->packingBox,
$stripObj->expandFlag,
$stripObj->fillFlag,
$spacing,
);
if ($posn != 0) {
$self->packingBox->reorder_child($stripObj->packingBox, $posn);
}
# Sensitise/desensitise widgets according to current conditions
$self->restrictMenuBars();
$self->restrictToolbars();
# Make everything visible
$self->winShowAll($self->_objClass . '->replaceStripObj');
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->replaceStripObj');
# Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
# themselves will have disappeared
$gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
$gaugeStripObj->updateGauges();
# (Need to call this a second time, or the re-draw doesn't work...)
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->replaceStripObj');
}
return 1;
}
sub getStrip {
# Convenient method for getting the blessed reference of the earliest-created instance of a
# type of strip object
#
# This function accepts a string, which can be any of the following (case-insensitive):
# 'menu' / 'menubar' / 'menu_bar' - converts to GA::Strip::MenuBar
# 'tool' / 'toolbar' / 'tool_bar' - converts to GA::Strip::Toolbar
# 'table' - converts to GA::Strip::Table
# 'gauge' / 'gaugebox' / 'gauge_box' - converts to GA::Strip::GaugeBox
# 'search' / 'searchbox' / 'search_box' - converts to GA::Strip::SearchBox
# 'entry' - converts to GA::Strip::Entry
# 'connect' / 'info' / 'connectinfo' / 'connect_info'
# - converts to GA::Strip::ConnectInfo
#
# The string can also be a part of the package name itself. For example, if you create your
# own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
# the string 'MyObject' (case-sensitive)
#
# Expected arguments
# $string - The string described above
#
# Return values
# 'undef' on improper arguments or if a strip object of that type doesn't exist in the
# window
# Otherwise returns the blessed reference to the earliest-created instance of the
# specified type of strip object
my ($self, $string, $check) = @_;
# Local variables
my $packageName;
# Check for improper arguments
if (! defined $string || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->getStrip', @_);
}
# Convert $string into a package name
$packageName = $self->convertPackageName($string);
if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
return undef;
}
# Return the earliest-created instance of that strip object (return 'undef' if none exists)
return $self->ivShow('firstStripHash', $packageName);
}
sub convertPackageName {
# Called by $self->addStrip, ->getStrip and $self->removeStrip
# Converts a simple string (e.g. 'menu' into the package name of a strip object (e.g.
# 'Games::Axmud::Strip::MenuBar'
#
# This function accepts a string, which can be any of the following (case-insensitive):
# 'menu' / 'menubar' / 'menu_bar' - converts to GA::Strip::MenuBar
# 'tool' / 'toolbar' / 'tool_bar' - converts to GA::Strip::Toolbar
# 'table' - converts to GA::Strip::Table
# 'gauge' / 'gaugebox' / 'gauge_box' - converts to GA::Strip::GaugeBox
# 'search' / 'searchbox' / 'search_box' - converts to GA::Strip::SearchBox
# 'entry' - converts to GA::Strip::Entry
# 'connect' / 'info' / 'connectinfo' / 'connect_info'
# - converts to GA::Strip::ConnectInfo
#
# The string can also be a part of the package name itself. For example, if you create your
# own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
# the string 'MyObject' (case-sensitive)
#
# Expected arguments
# $string - The string to convert
#
# Return values
# 'undef' on improper arguments
# Otherwise returns a strip object's package name
my ($self, $string, $check) = @_;
# Local variables
my $packageName;
# Check for improper arguments
if (! defined $string || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->convertPackageName', @_);
}
if (
lc($string) eq 'menu' || lc($string) eq 'menubar' || lc($string) eq 'menu_bar'
) {
$packageName = 'Games::Axmud::Strip::MenuBar';
} elsif (
lc($string) eq 'tool' || lc($string) eq 'toolbar' || lc($string) eq 'tool_bar'
) {
$packageName = 'Games::Axmud::Strip::Toolbar';
} elsif (
lc($string) eq 'gauge' || lc($string) eq 'gaugebox' || lc($string) eq 'gauge_box'
) {
$packageName = 'Games::Axmud::Strip::GaugeBox';
} elsif (
lc($string) eq 'search' || lc($string) eq 'searchbox' || lc($string) eq 'search_box'
) {
$packageName = 'Games::Axmud::Strip::SearchBox';
} elsif (lc($string) eq 'entry') {
$packageName = 'Games::Axmud::Strip::Entry';
} elsif (
lc($string) eq 'connect' || lc($string) eq 'info' || lc($string) eq 'connectinfo'
|| lc($string) eq 'connect_info'
) {
$packageName = 'Games::Axmud::Strip::ConnectInfo';
} else {
$packageName = 'Games::Axmud::Strip::' . $string;
}
return $packageName;
}
##################
# Accessors - set
##################
# Accessors - get
sub stripHash
{ my $self = shift; return %{$self->{stripHash}}; }
sub firstStripHash
{ my $self = shift; return %{$self->{firstStripHash}}; }
sub stripCount
{ $_[0]->{stripCount} }
sub stripList
{ my $self = shift; return @{$self->{stripList}}; }
sub tableStripObj
{ $_[0]->{tableStripObj} }
sub stripSpacingPixels
{ $_[0]->{stripSpacingPixels} }
sub visibleSession
{ $_[0]->{visibleSession} }
sub hostLabelText
{ $_[0]->{hostLabelText} }
sub timeLabelText
{ $_[0]->{timeLabelText} }
( run in 0.544 second using v1.01-cache-2.11-cpan-39bf76dae61 )