/// <summary> /// Handles reading from the eventArgs to determine what action to take. /// </summary> private void HandleEventArgResults() { // clear the Device reference storageDevice = null; // determine the next action... switch (eventArgs.Response) { // will have the manager prompt the user with the option of reselecting the storage device case StorageDeviceEventResponse.Prompt: state = deviceWasConnected ? StorageDevicePromptState.PromptForDisconnected : StorageDevicePromptState.PromptForCanceled; break; // will have the manager prompt the user that the device must be selected case StorageDeviceEventResponse.Force: state = deviceWasConnected ? StorageDevicePromptState.ForceDisconnectedReselection : StorageDevicePromptState.ForceCanceledReselection; break; // will have the manager do nothing default: state = StorageDevicePromptState.None; break; } }
/// <summary> /// Flags the SaveDevice to prompt for a storage device on the next Update. /// </summary> public void PromptForDevice() { // we only let the programmer show the selector if the // SaveDevice isn't busy doing something else. if (state == StorageDevicePromptState.None) { state = StorageDevicePromptState.ShowSelector; } }
/// <summary> /// A callback for either of the message boxes asking the user /// to select a new device, either from cancelling the device /// seledctor or disconnecting the device. /// </summary> /// <param name="result">The result of the prompt.</param> private void ReselectPromptCallback(IAsyncResult result) { int?choice = Guide.EndShowMessageBox(result); // get the device if the user chose the first option state = choice.HasValue && choice.Value == 0 ? StorageDevicePromptState.ShowSelector : StorageDevicePromptState.None; // fire an event for the game to know the result of the prompt promptEventArgs.ShowDeviceSelector = state == StorageDevicePromptState.ShowSelector; if (DeviceReselectPromptClosed != null) { DeviceReselectPromptClosed(this, promptEventArgs); } }
/// <summary> /// A callback for either of the message boxes telling users they /// have to choose a storage device, either from cancelling the /// device selector or disconnecting the device. /// </summary> /// <param name="result">The result of the prompt.</param> private void ForcePromptCallback(IAsyncResult result) { // just end the message and instruct the SaveDevice to show the selector Guide.EndShowMessageBox(result); state = StorageDevicePromptState.ShowSelector; }
/// <summary> /// Allows the component to update itself. /// </summary> /// <param name="gameTime">The current game timestamp.</param> public void Update(GameTime gameTime) { #if XBOX // make sure gamer services are available for all of our Guide methods we use if (!GamerServicesDispatcher.IsInitialized) { throw new InvalidOperationException(Strings.NeedGamerService); } #endif Boolean deviceIsConnected = storageDevice != null && storageDevice.IsConnected; if (!deviceIsConnected && deviceWasConnected) { // if the device was disconnected, fire off the event and handle result PrepareEventArgs(eventArgs); if (DeviceDisconnected != null) { DeviceDisconnected(this, eventArgs); } HandleEventArgResults(); } else if (!deviceIsConnected) { // we use the try/catch because of the asynchronous nature of the Guide. // the Guide may not be visible when we do our test, but it may open // up after that point and before we've made a call, causing our Guide // methods to throw exceptions. #if !SILVERLIGHT try { #endif #if XBOX if (!Guide.IsVisible) { #endif switch (state) { // show the normal storage device selector case StorageDevicePromptState.ShowSelector: state = StorageDevicePromptState.None; GetStorageDevice(storageDeviceSelectorCallback); break; // these actions don't apply anywhere but Xbox so we compile them out for Windows to prevent // issues with gamer services in redistributed games. #if XBOX // the user cancelled the device selector, and we've decided to // see if they want another chance to choose a device case SaveDevicePromptState.PromptForCanceled: ShowMessageBox(eventArgs.PlayerToPrompt, deviceOptionalTitle, promptForCancelledMessage, deviceOptionalOptions, reselectPromptCallback); break; // the user cancelled the device selector, and we've decided to // force them to choose again. this message is simply to inform // the user of that. case SaveDevicePromptState.ForceCanceledReselection: ShowMessageBox(eventArgs.PlayerToPrompt, deviceRequiredTitle, forceCancelledReselectionMessage, deviceRequiredOptions, forcePromptCallback); break; // the device has been disconnected, and we've decided to ask // the user if they want to choose a new one case SaveDevicePromptState.PromptForDisconnected: ShowMessageBox(eventArgs.PlayerToPrompt, deviceOptionalTitle, promptForDisconnectedMessage, deviceOptionalOptions, reselectPromptCallback); break; // the device has been disconnected, and we've decided to force // the user to select a new one. this message is simply to inform // the user of that. case SaveDevicePromptState.ForceDisconnectedReselection: ShowMessageBox(eventArgs.PlayerToPrompt, deviceRequiredTitle, forceDisconnectedReselectionMessage, deviceRequiredOptions, forcePromptCallback); break; #endif default: break; } #if XBOX } #endif #if !SILVERLIGHT } // catch this one type of exception just to be safe catch (GuideAlreadyVisibleException) { } #endif } deviceWasConnected = deviceIsConnected; }
/// <summary> /// A callback for either of the message boxes asking the user /// to select a new device, either from cancelling the device /// seledctor or disconnecting the device. /// </summary> /// <param name="result">The result of the prompt.</param> private void ReselectPromptCallback(IAsyncResult result) { int? choice = Guide.EndShowMessageBox(result); // get the device if the user chose the first option state = choice.HasValue && choice.Value == 0 ? StorageDevicePromptState.ShowSelector : StorageDevicePromptState.None; // fire an event for the game to know the result of the prompt promptEventArgs.ShowDeviceSelector = state == StorageDevicePromptState.ShowSelector; if (DeviceReselectPromptClosed != null) DeviceReselectPromptClosed(this, promptEventArgs); }
/// <summary> /// Allows the component to update itself. /// </summary> /// <param name="gameTime">The current game timestamp.</param> public void Update(GameTime gameTime) { #if XBOX // make sure gamer services are available for all of our Guide methods we use if (!GamerServicesDispatcher.IsInitialized) throw new InvalidOperationException(Strings.NeedGamerService); #endif Boolean deviceIsConnected = storageDevice != null && storageDevice.IsConnected; if (!deviceIsConnected && deviceWasConnected) { // if the device was disconnected, fire off the event and handle result PrepareEventArgs(eventArgs); if (DeviceDisconnected != null) DeviceDisconnected(this, eventArgs); HandleEventArgResults(); } else if (!deviceIsConnected) { // we use the try/catch because of the asynchronous nature of the Guide. // the Guide may not be visible when we do our test, but it may open // up after that point and before we've made a call, causing our Guide // methods to throw exceptions. #if !SILVERLIGHT try { #endif #if XBOX if (!Guide.IsVisible) { #endif switch (state) { // show the normal storage device selector case StorageDevicePromptState.ShowSelector: state = StorageDevicePromptState.None; GetStorageDevice(storageDeviceSelectorCallback); break; // these actions don't apply anywhere but Xbox so we compile them out for Windows to prevent // issues with gamer services in redistributed games. #if XBOX // the user cancelled the device selector, and we've decided to // see if they want another chance to choose a device case SaveDevicePromptState.PromptForCanceled: ShowMessageBox(eventArgs.PlayerToPrompt, deviceOptionalTitle, promptForCancelledMessage, deviceOptionalOptions, reselectPromptCallback); break; // the user cancelled the device selector, and we've decided to // force them to choose again. this message is simply to inform // the user of that. case SaveDevicePromptState.ForceCanceledReselection: ShowMessageBox(eventArgs.PlayerToPrompt, deviceRequiredTitle, forceCancelledReselectionMessage, deviceRequiredOptions, forcePromptCallback); break; // the device has been disconnected, and we've decided to ask // the user if they want to choose a new one case SaveDevicePromptState.PromptForDisconnected: ShowMessageBox(eventArgs.PlayerToPrompt, deviceOptionalTitle, promptForDisconnectedMessage, deviceOptionalOptions, reselectPromptCallback); break; // the device has been disconnected, and we've decided to force // the user to select a new one. this message is simply to inform // the user of that. case SaveDevicePromptState.ForceDisconnectedReselection: ShowMessageBox(eventArgs.PlayerToPrompt, deviceRequiredTitle, forceDisconnectedReselectionMessage, deviceRequiredOptions, forcePromptCallback); break; #endif default: break; } #if XBOX } #endif #if !SILVERLIGHT } // catch this one type of exception just to be safe catch (GuideAlreadyVisibleException) { } #endif } deviceWasConnected = deviceIsConnected; }
/// <summary> /// Flags the SaveDevice to prompt for a storage device on the next Update. /// </summary> public void PromptForDevice() { // we only let the programmer show the selector if the // SaveDevice isn't busy doing something else. if (state == StorageDevicePromptState.None) state = StorageDevicePromptState.ShowSelector; }