/// <summary>
        /// This method is called on the UI-thread when the minimap background task has been finished.
        /// </summary>
        /// <param name="sender">Reference to the background task.</param>
        /// <param name="nothing">Unused.</param>
        private void OnBackgroundTaskFinished(IUIBackgroundTask sender, object nothing)
        {
            if (sender != this.backgroundTask)
            {
                throw new InvalidOperationException("Unexpected sender!");
            }

            UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate -= this.OnExecuteScan;
            this.showAttackSignalsFlag            = false;
            this.timeSinceAttackSignalFlagChanged = 0;
            this.backgroundTask   = null;
            this.minimapView      = null;
            this.minimapScanner   = null;
            this.spriteBuffer     = null;
            this.connectionStatus = ConnectionStatusEnum.Offline;
            this.stopBackgroundTaskEvent.Close();
            this.newJobEvent.Close();
            this.stopBackgroundTaskEvent = null;
            this.newJobEvent             = null;

            TraceManager.WriteAllTrace("Minimap disconnection completed", PresLogicTraceFilters.INFO);

            if (this.ConnectorOperationFinished != null)
            {
                this.ConnectorOperationFinished(this);
            }
        }
        /// <summary>
        /// This method is called if loading the map has been failed.
        /// </summary>
        private void OnLoadMapFailed(IUIBackgroundTask sender, object message)
        {
            this.loadMapTask.Finished -= this.OnLoadMapFinished;
            this.loadMapTask.Failed   -= this.OnLoadMapFailed;

            throw (Exception)message;
        }
Beispiel #3
0
        /// <see cref="ITaskManager.StartTask"/>
        public ITask StartTask(TaskMethod taskMethod, string name, object parameter)
        {
            IUIBackgroundTask adaptedTask =
                UITaskManager.StartParallelTask(delegate(object param) { taskMethod(parameter); }, name);

            return(new TaskAdapter(adaptedTask));
        }
Beispiel #4
0
 /// <summary>
 /// Adapted handler of IUIBackgoundTask.Failed events.
 /// </summary>
 private void AdaptedFailedHdl(IUIBackgroundTask sender, object message)
 {
     if (sender == this.adaptedTask && this.failedInternal != null)
     {
         this.failedInternal(this, message);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Called if loading the resources has been failed.
        /// </summary>
        private void LoadingFailed(IUIBackgroundTask sender, object args)
        {
            this.loadingTask.Finished -= this.LoadingFinished;
            this.loadingTask.Failed   -= this.LoadingFailed;

            throw (Exception)args;
        }
Beispiel #6
0
        /// <summary>
        /// Called if loading the resources has been finished.
        /// </summary>
        private void LoadingFinished(IUIBackgroundTask sender, object args)
        {
            this.loadingTask.Finished -= this.LoadingFinished;
            this.loadingTask.Failed   -= this.LoadingFailed;

            if (this.LoadFinished != null)
            {
                this.LoadFinished();
            }

            this.loadingTask  = null;
            this.currentPhase = ShowPhase.Normal;
            UIWorkspace.Instance.SetDefaultMousePointer(UIResourceManager.GetResource <UIPointer>("RC.App.Pointers.NormalPointer"));

            UIFont menuFont = UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font9B");

            string[] menuPoints = new string[3] {
                START_GAME_MENUPOINT, CREDITS_MENUPOINT, EXIT_MENUPOINT
            };
            this.menuPanel = new RCMainMenuPanel(new RCIntRectangle((UIWorkspace.Instance.WorkspaceSize.X - MENU_PANEL_WIDTH) / 2,
                                                                    100,
                                                                    MENU_PANEL_WIDTH,
                                                                    (menuFont.CharTopMaximum + menuFont.CharBottomMaximum + 1) * menuPoints.Length),
                                                 menuPoints);
            this.RegisterPanel(this.menuPanel);

            this.menuPanel[START_GAME_MENUPOINT].Pressed += this.OnMenupointPressed;
            this.menuPanel[CREDITS_MENUPOINT].Pressed    += this.OnMenupointPressed;
            this.menuPanel[EXIT_MENUPOINT].Pressed       += this.OnMenupointPressed;

            this.menuPanel.Show();
        }
Beispiel #7
0
 /// <summary>
 /// Constructs a TaskAdapter instance.
 /// </summary>
 /// <param name="adaptedTask">Reference to the adapted background task.</param>
 public TaskAdapter(IUIBackgroundTask adaptedTask)
 {
     if (adaptedTask == null)
     {
         throw new ArgumentNullException("adaptedTask");
     }
     this.adaptedTask = adaptedTask;
 }
        /// <summary>
        /// This method is called if loading the map has been finished successfully.
        /// </summary>
        private void OnLoadMapFinished(IUIBackgroundTask sender, object message)
        {
            /// Unsubscribe from the events of the background task.
            this.loadMapTask.Finished -= this.OnLoadMapFinished;
            this.loadMapTask.Failed   -= this.OnLoadMapFailed;

            /// To avoid recursive call on the UITaskManager.
            UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnUpdateAfterMapLoaded;
        }
        /// <summary>
        /// This method is called if saving the map has been finished successfully.
        /// </summary>
        private void OnSaveMapFinished(IUIBackgroundTask sender, object message)
        {
            /// Unsubscribe from the events of the background task.
            this.saveMapTask.Finished -= this.OnSaveMapFinished;
            this.saveMapTask.Failed   -= this.OnSaveMapFailed;

            // TODO: display a "Please wait..." dialog instead!!!
            this.workspaceTmp.AttachSensitive(this);
            this.workspaceTmp = null;
        }
        /// <summary>
        /// This method is called if saving the map has been failed.
        /// </summary>
        private void OnSaveMapFailed(IUIBackgroundTask sender, object message)
        {
            this.saveMapTask.Finished -= this.OnSaveMapFinished;
            this.saveMapTask.Failed   -= this.OnSaveMapFailed;

            // TODO: display a "Please wait..." dialog instead!!!
            this.workspaceTmp.AttachSensitive(this);
            this.workspaceTmp = null;

            throw (Exception)message;
        }
        /// <summary>
        /// This method is called on the UI-thread when the minimap background task sent a message.
        /// </summary>
        /// <param name="sender">Reference to the background task.</param>
        /// <param name="finishedJob">The job that has been executed by the background task.</param>
        private void OnBackgroundTaskMessage(IUIBackgroundTask sender, object finishedJob)
        {
            if (sender != this.backgroundTask)
            {
                throw new InvalidOperationException("Unexpected sender!");
            }

            if (finishedJob == this.spriteBuffer)
            {
                if (this.scannerStatus == ScannerStatusEnum.Inactive)
                {
                    /// Connection completed, start the first scan operation.
                    TraceManager.WriteAllTrace("Minimap connection completed", PresLogicTraceFilters.INFO);
                    this.minimapScanner = new MinimapScanner(this.minimapView);
                    this.minimapScanner.InitScan(this.spriteBuffer.CheckoutFOWSprite(),
                                                 this.spriteBuffer.CheckoutEntitiesSprite(),
                                                 this.spriteBuffer.CheckoutAttackSignalsSprite());
                    this.scannerStatus                    = ScannerStatusEnum.Scanning;
                    this.mouseHandler                     = new MinimapMouseHandler(this);
                    this.showAttackSignalsFlag            = false;
                    this.timeSinceAttackSignalFlagChanged = 0;
                    UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnExecuteScan;

                    this.connectionStatus = ConnectionStatusEnum.Online;
                    if (this.ConnectorOperationFinished != null)
                    {
                        this.ConnectorOperationFinished(this);
                    }
                }
            }
            else if (finishedJob is MinimapTerrainRenderJob)
            {
                /// Terrain rendering completed.
                TraceManager.WriteAllTrace("Minimap terrain refresh completed", PresLogicTraceFilters.INFO);
                this.spriteBuffer.CheckinTerrainSprite((finishedJob as MinimapTerrainRenderJob).Result);
            }
            else if (finishedJob == this.minimapScanner)
            {
                if (this.scannerStatus == ScannerStatusEnum.Rendering)
                {
                    /// Rendering completed, start the next scan operation.
                    //TraceManager.WriteAllTrace("Minimap refresh completed", PresLogicTraceFilters.INFO);
                    this.spriteBuffer.CheckinFOWSprite(this.minimapScanner.FOWBuffer);
                    this.spriteBuffer.CheckinEntitiesSprite(this.minimapScanner.EntitiesBuffer);
                    this.spriteBuffer.CheckinAttackSignalsSprite(this.minimapScanner.AttackSignalsBuffer);
                    this.minimapScanner.InitScan(this.spriteBuffer.CheckoutFOWSprite(),
                                                 this.spriteBuffer.CheckoutEntitiesSprite(),
                                                 this.spriteBuffer.CheckoutAttackSignalsSprite());
                    this.scannerStatus = ScannerStatusEnum.Scanning;
                }
            }
        }
        /// <summary>
        /// Unloads every loaded resources in the given resource group. The unloading will be performed as a background task.
        /// </summary>
        /// <param name="group">The name of the resource group to unload.</param>
        /// <returns>
        /// Calling this method will return immediately with an interface to the background task. This interface can be used
        /// to subscribe the events of the task. The resource group unloader task doesn't send messages during it's execution.
        /// </returns>
        /// <remarks>
        /// This method throws an InvalidOperationException if there is another resource group loader or unloader task in progress.
        /// </remarks>
        public static IUIBackgroundTask UnloadResourceGroupAsync(string group)
        {
            if (string.IsNullOrEmpty(group))
            {
                throw new ArgumentNullException("group");
            }
            if (!resourceGroups.ContainsKey(group))
            {
                throw new UIException(string.Format("Resource group '{0}' doesn't exist!", group));
            }

            string[]          resourcesToUnload = new string[resourceGroups[group].Count];
            IUIBackgroundTask unloaderTask      = UITaskManager.StartParallelTask(UnloadResourceGroupAsync_i, "ResourceUnloadingTask", resourcesToUnload);

            return(unloaderTask);
        }
Beispiel #13
0
 /// <summary>
 /// Called when the currently running background task has been finished.
 /// </summary>
 private void OnBackgroundTaskFinished(IUIBackgroundTask sender, object message)
 {
     this.backgroundTask = null;
     if (!this.isConnected)
     {
         this.isConnected = true;
         if (this.ConnectorOperationFinished != null)
         {
             this.ConnectorOperationFinished(this);
         }
     }
     else
     {
         this.isConnected = false;
         if (this.ConnectorOperationFinished != null)
         {
             this.ConnectorOperationFinished(this);
         }
     }
 }
Beispiel #14
0
        /// <summary>
        /// Called when the currently running background task has been finished.
        /// </summary>
        private void OnBackgroundTaskFinished(IUIBackgroundTask sender, object message)
        {
            this.backgroundTask.Finished -= this.OnBackgroundTaskFinished;
            this.backgroundTask           = null;
            if (!this.isConnected)
            {
                /// Create the selection buttons.
                for (int i = 0; i < MAX_SELECTION_SIZE; i++)
                {
                    this.buttonArray[i] = new RCSelectionButton(i, this.hpIndicatorSprites);
                }

                /// Create the controls that display the custom content.
                this.productionLineDisplay       = new RCProductionLineDisplay(this.productIconSprites, CUSTOM_CONTENT_RECT.Location, CUSTOM_CONTENT_RECT.Size);
                this.constructionProgressDisplay = new RCConstructionProgressDisplay(CUSTOM_CONTENT_RECT.Location, CUSTOM_CONTENT_RECT.Size);
                this.supplyDetailsDisplay        = new RCSupplyDetailsDisplay(CUSTOM_CONTENT_RECT.Location, CUSTOM_CONTENT_RECT.Size);
                this.resourceAmountDisplay       = new RCResourceAmountDisplay(CUSTOM_CONTENT_RECT.Location, CUSTOM_CONTENT_RECT.Size);
                this.weaponDetailsDisplay        = new RCWeaponDetailsDisplay(CUSTOM_CONTENT_RECT.Location, CUSTOM_CONTENT_RECT.Size);

                /// Subscribe to the FrameUpdate event.
                UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnFrameUpdate;

                this.isConnected = true;
                if (this.ConnectorOperationFinished != null)
                {
                    this.ConnectorOperationFinished(this);
                }
            }
            else
            {
                this.multiplayerService    = null;
                this.selectionDetailsView  = null;
                this.mapObjectDetailsView  = null;
                this.productionDetailsView = null;
                this.isConnected           = false;
                if (this.ConnectorOperationFinished != null)
                {
                    this.ConnectorOperationFinished(this);
                }
            }
        }