示例#1
0
        /// <summary>
        /// This method is called when the map display connected successfully.
        /// </summary>
        private void OnDisplaysConnected(IGameConnector sender)
        {
            this.displaysConnector.ConnectorOperationFinished -= this.OnDisplaysConnected;

            /// Subscribe to the events of the appropriate mouse sensors & create the mouse handler.
            this.mouseHandler = new MapEditorMouseHandler(this, this.mapDisplay);
            this.mapDisplay.MouseSensor.Move       += this.OnMouseMoveOverDisplay;
            this.mapDisplay.MouseSensor.ButtonDown += this.OnMouseDown;
            this.mapDisplay.MouseSensor.ButtonUp   += this.OnMouseUp;
            this.mapDisplay.MouseSensor.Wheel      += this.OnMouseWheel;

            /// Subscribe to the events of the map editor panel.
            this.mapEditorPanel.EditModeChanged     += this.OnEditModeChanged;
            this.mapEditorPanel.SelectedItemChanged += this.OnSelectedItemChanged;
            this.mapEditorPanel.SaveButton.Pressed  += this.OnSaveMapPressed;
            this.mapEditorPanel.ExitButton.Pressed  += this.OnExitPressed;
            this.isotileDisplayEx.HighlightIsoTile   = this.mapEditorPanel.SelectedMode == RCMapEditorPanel.EditMode.DrawTerrain;

            /// Attach the map display control to this page.
            this.Attach(this.mapDisplay);
            this.AttachSensitive(this.mapDisplay);

            /// Show the map editor panel.
            this.mapEditorPanel.Show();
            this.mapEditorPanel.ResetControls();
        }
示例#2
0
        /// <summary>
        /// This method is called when the map display disconnected successfully.
        /// </summary>
        private void OnDisplaysDisconnected(IGameConnector sender)
        {
            this.displaysConnector.ConnectorOperationFinished -= this.OnDisplaysDisconnected;

            this.mapEditorService.CloseMap();
            UIRoot.Instance.GraphicsPlatform.RenderLoop.Stop();
        }
示例#3
0
        /// <summary>
        /// This method is called when the map display stopped successfully.
        /// </summary>
        private void OnDisconnected(IGameConnector sender)
        {
            this.gameConnection.ConnectorOperationFinished -= this.OnDisconnected;
            if (this.ConnectorOperationFinished != null)
            {
                this.ConnectorOperationFinished(this);
            }

            /// TODO: later we don't need to stop the render loop here!
            UIRoot.Instance.GraphicsPlatform.RenderLoop.Stop();
        }
        /// <summary>
        /// This event handler is called when the extended control has been disconnected successfully.
        /// </summary>
        private void OnExtendedControlDisconnected(IGameConnector sender)
        {
            if (sender != this.extendedControl)
            {
                throw new InvalidOperationException("Unexpected connector!");
            }
            if (sender.ConnectionStatus != ConnectionStatusEnum.Offline)
            {
                throw new InvalidOperationException("Extended control is not offline!");
            }

            this.extendedControl.ConnectorOperationFinished -= this.OnExtendedControlDisconnected;
            this.extendedCtrlOpFinished.Set();
        }
示例#5
0
        private void Connector_Disconnected(object sender, EventArgs e)
        {
            if (_activeConnector != sender)
            {
                return;
            }

            Logger.Info("Connector Disconnected: " + _activeConnector.GetType());
            _activeConnector.DataLoaded     -= OnDataLoaded;
            _activeConnector.SessionStarted -= OnSessionStarted;
            _activeConnector.Disconnected   -= Connector_Disconnected;
            _activeConnector.DisplayMessage -= ActiveConnectorOnDisplayMessage;
            _activeConnector = null;
            RaiseSessionStartedEvent(new SimulatorDataSet("Not Connected"));
        }
示例#6
0
        /// <summary>
        /// Internal event handler.
        /// </summary>
        private void OnMinimapConnectorOperationFinished(IGameConnector sender)
        {
            if (sender != this.minimapDisplay)
            {
                throw new ArgumentException("Unexpected sender of event!");
            }

            if (sender.ConnectionStatus == ConnectionStatusEnum.Online)
            {
                this.AddControl(this.minimapDisplay);
            }

            if (this.ConnectorOperationFinished != null)
            {
                this.ConnectorOperationFinished(this);
            }
        }
示例#7
0
        /// <summary>
        /// This method is called when the map display started successfully.
        /// </summary>
        private void OnConnected(IGameConnector sender)
        {
            this.commandView            = ComponentManager.GetInterface <IViewService>().CreateView <ICommandView>();
            this.selectionIndicatorView = ComponentManager.GetInterface <IViewService>().CreateView <ISelectionIndicatorView>();
            this.gameConnection.ConnectorOperationFinished -= this.OnConnected;

            /// Attach the map display control to this page.
            this.Attach(this.mapDisplay);
            this.AttachSensitive(this.mapDisplay);
            this.mapDisplay.SendToBottom();

            /// Create the mouse handler for the map display.
            this.CreateMouseHandler();

            this.menuButtonPanel.MouseSensor.ButtonDown += this.OnMenuButtonPressed;

            if (this.ConnectorOperationFinished != null)
            {
                this.ConnectorOperationFinished(this);
            }
        }
示例#8
0
 private void ConnectLoop()
 {
     while (true)
     {
         Thread.Sleep(100);
         foreach (var connector in Connectors)
         {
             connector.DisplayMessage += ActiveConnectorOnDisplayMessage;
             if (connector.TryConnect())
             {
                 Logger.Info("Connector Connected: " + connector.GetType());
                 _activeConnector                 = connector;
                 _activeConnector.DataLoaded     += OnDataLoaded;
                 _activeConnector.SessionStarted += OnSessionStarted;
                 _activeConnector.Disconnected   += Connector_Disconnected;
                 return;
             }
             connector.DisplayMessage -= ActiveConnectorOnDisplayMessage;
         }
     }
 }
示例#9
0
        /// <summary>
        /// Constructs ConcurrentGameConnector instance.
        /// </summary>
        /// <param name="firstConnector">
        /// The first connector to connect concurrently.
        /// </param>
        /// <param name="furtherConnectors">The further connectors to connect concurrently.</param>
        public ConcurrentGameConnector(IGameConnector firstConnector, params IGameConnector[] furtherConnectors)
        {
            if (firstConnector == null)
            {
                throw new ArgumentNullException("firstConnector");
            }
            if (furtherConnectors == null)
            {
                throw new ArgumentNullException("furtherConnectors");
            }

            this.connectedConnectors    = new RCSet <IGameConnector>();
            this.disconnectedConnectors = new RCSet <IGameConnector>();

            /// Handle the first connector.
            if (firstConnector.ConnectionStatus != ConnectionStatusEnum.Offline)
            {
                throw new ArgumentException("All aggregated connectors shall be in the state ConnectionStatusEnum.Offline!", "firstConnector");
            }
            this.disconnectedConnectors.Add(firstConnector);
            firstConnector.ConnectorOperationFinished += this.OnOperationFinished;

            /// Handle the further connectors.
            foreach (IGameConnector connector in furtherConnectors)
            {
                if (connector == null)
                {
                    throw new ArgumentException("None of the elements of furtherConnectors can be null!", "furtherConnectors");
                }
                if (connector.ConnectionStatus != ConnectionStatusEnum.Offline)
                {
                    throw new ArgumentException("All aggregated connectors shall be in the state ConnectionStatusEnum.Offline!", "furtherConnectors");
                }
                this.disconnectedConnectors.Add(connector);
                connector.ConnectorOperationFinished += this.OnOperationFinished;
            }

            this.isDisposed    = false;
            this.currentStatus = ConnectionStatusEnum.Offline;
        }
        /// <summary>
        /// Constructs SequentialGameConnector instance.
        /// </summary>
        /// <param name="firstConnector">
        /// The first connector to connect sequentially.
        /// </param>
        /// <param name="furtherConnectors">The further connectors to connect sequentially.</param>
        public SequentialGameConnector(IGameConnector firstConnector, params IGameConnector[] furtherConnectors)
        {
            if (firstConnector == null)
            {
                throw new ArgumentNullException("firstConnector");
            }
            if (furtherConnectors == null)
            {
                throw new ArgumentNullException("furtherConnectors");
            }

            this.connectors = new List <IGameConnector>();
            this.currentlyHandledConnectorIdx = -1;

            /// Handle the first connector.
            if (firstConnector.ConnectionStatus != ConnectionStatusEnum.Offline)
            {
                throw new ArgumentException("All aggregated connectors shall be in the state ConnectionStatusEnum.Offline!", "firstConnector");
            }
            this.connectors.Add(firstConnector);

            /// Handle the further connectors.
            foreach (IGameConnector connector in furtherConnectors)
            {
                if (connector == null)
                {
                    throw new ArgumentException("None of the elements of furtherConnectors can be null!", "furtherConnectors");
                }
                if (connector.ConnectionStatus != ConnectionStatusEnum.Offline)
                {
                    throw new ArgumentException("All aggregated connectors shall be in the state ConnectionStatusEnum.Offline!", "furtherConnectors");
                }
                this.connectors.Add(connector);
            }

            this.isDisposed    = false;
            this.currentStatus = ConnectionStatusEnum.Offline;
        }
示例#11
0
        private async Task ConnectLoop()
        {
            while (true)
            {
                await Task.Delay(5000).ConfigureAwait(false);

                foreach (var connector in Connectors)
                {
                    connector.DisplayMessage += ActiveConnectorOnDisplayMessage;
                    if (connector.TryConnect())
                    {
                        Logger.Info("Connector Connected: " + connector.GetType());
                        _activeConnector                 = connector;
                        _activeConnector.DataLoaded     += OnDataLoaded;
                        _activeConnector.SessionStarted += OnSessionStarted;
                        _activeConnector.Disconnected   += Connector_Disconnected;
                        _activeConnector.StartConnectorLoop();
                        return;
                    }

                    connector.DisplayMessage -= ActiveConnectorOnDisplayMessage;
                }
            }
        }
示例#12
0
 public ClientHub(IPlayerConnector playerConnector, IGameConnector gameConnector)
 {
     _playerConnector = playerConnector;
     _gameConnector   = gameConnector;
 }
示例#13
0
 /// <summary>
 ///     Registers a connector
 /// </summary>
 /// <param name="connector">Game connector</param>
 public void RegisterConnector(IGameConnector connector)
 {
     this._registeredConnectors.Add(connector);
 }
        /// <summary>
        /// This event handler is called when the connection/disconnection operation of an aggregated connector has been finished.
        /// </summary>
        /// <param name="connector">The aggregated connector whose operation has been finished.</param>
        private void OnOperationFinished(IGameConnector connector)
        {
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("SequentialGameConnector");
            }
            if (connector == null)
            {
                throw new ArgumentNullException("connector");
            }
            if (this.connectors[this.currentlyHandledConnectorIdx] != connector)
            {
                throw new InvalidOperationException("Unknown connector!");
            }

            this.connectors[this.currentlyHandledConnectorIdx].ConnectorOperationFinished -= this.OnOperationFinished;

            if (this.currentStatus == ConnectionStatusEnum.Connecting)
            {
                if (connector.ConnectionStatus != ConnectionStatusEnum.Online)
                {
                    throw new InvalidOperationException("Aggregated connector is not online!");
                }

                this.currentlyHandledConnectorIdx++;

                if (this.currentlyHandledConnectorIdx == this.connectors.Count)
                {
                    /// Last connector has been connected.
                    this.currentStatus = ConnectionStatusEnum.Online;
                    this.currentlyHandledConnectorIdx = -1;
                    if (this.ConnectorOperationFinished != null)
                    {
                        this.ConnectorOperationFinished(this);
                    }
                }
                else
                {
                    /// To avoid recursive call on the UITaskManager.
                    UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnContinueWithNextConnector;
                }
            }
            else if (this.currentStatus == ConnectionStatusEnum.Disconnecting)
            {
                if (connector.ConnectionStatus != ConnectionStatusEnum.Offline)
                {
                    throw new InvalidOperationException("Aggregated connector is not offline!");
                }

                this.currentlyHandledConnectorIdx--;

                if (this.currentlyHandledConnectorIdx < 0)
                {
                    /// Last connector has been disconnected.
                    this.currentStatus = ConnectionStatusEnum.Offline;
                    this.currentlyHandledConnectorIdx = -1;
                    if (this.ConnectorOperationFinished != null)
                    {
                        this.ConnectorOperationFinished(this);
                    }
                }
                else
                {
                    /// To avoid recursive call on the UITaskManager.
                    UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnContinueWithNextConnector;
                }
            }
            else
            {
                throw new InvalidOperationException("IGameConnector.ConnectorOperationFinished event raised unexpectedly!");
            }
        }
示例#15
0
 public Game(IGameConnector gameConnector, IDecisionMaker decisionMaker)
 {
     this.gameConnector = gameConnector;
     this.decisionMaker = decisionMaker;
 }
示例#16
0
        /// <summary>
        /// This event handler is called when the connection/disconnection operation of an aggregated connector has been finished.
        /// </summary>
        /// <param name="connector">The aggregated connector whose operation has been finished.</param>
        private void OnOperationFinished(IGameConnector connector)
        {
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("ConcurrentGameConnector");
            }
            if (connector == null)
            {
                throw new ArgumentNullException("connector");
            }

            if (this.currentStatus == ConnectionStatusEnum.Connecting)
            {
                if (!this.disconnectedConnectors.Contains(connector))
                {
                    throw new InvalidOperationException("Unknown connector!");
                }
                if (connector.ConnectionStatus != ConnectionStatusEnum.Online)
                {
                    throw new InvalidOperationException("Aggregated connector is not online!");
                }

                this.disconnectedConnectors.Remove(connector);
                this.connectedConnectors.Add(connector);

                if (this.disconnectedConnectors.Count == 0)
                {
                    this.currentStatus = ConnectionStatusEnum.Online;
                    if (this.ConnectorOperationFinished != null)
                    {
                        this.ConnectorOperationFinished(this);
                    }
                }
            }
            else if (this.currentStatus == ConnectionStatusEnum.Disconnecting)
            {
                if (!this.connectedConnectors.Contains(connector))
                {
                    throw new InvalidOperationException("Unknown connector!");
                }
                if (connector.ConnectionStatus != ConnectionStatusEnum.Offline)
                {
                    throw new InvalidOperationException("Aggregated connector is not offline!");
                }

                this.connectedConnectors.Remove(connector);
                this.disconnectedConnectors.Add(connector);

                if (this.connectedConnectors.Count == 0)
                {
                    this.currentStatus = ConnectionStatusEnum.Offline;
                    if (this.ConnectorOperationFinished != null)
                    {
                        this.ConnectorOperationFinished(this);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("IGameConnector.ConnectorOperationFinished event raised unexpectedly!");
            }
        }