Ejemplo n.º 1
0
        void AddIconable(EntityState entityState)
        {
            var entityItem = entityState.Entity;

            if (entityItem.HasDataBlob <NameDB>())
            {
                _nameIcons.TryAdd(entityItem.Guid, new NameIcon(entityState, _state));
            }


            if (entityItem.HasDataBlob <OrbitDB>())
            {
                var orbitDB = entityItem.GetDataBlob <OrbitDB>();
                if (!orbitDB.IsStationary)
                {
                    OrbitIconBase orbit;
                    if (orbitDB.Eccentricity < 1)
                    {
                        orbit = new OrbitEllipseIcon(entityState, _state.UserOrbitSettingsMtx);
                        _orbitRings.TryAdd(entityItem.Guid, orbit);
                    }
                }
            }

            if (entityItem.HasDataBlob <NewtonMoveDB>())
            {
                var hyp = entityItem.GetDataBlob <NewtonMoveDB>();
                OrbitHypobolicIcon orb;
                orb = new OrbitHypobolicIcon(entityState, _state.UserOrbitSettingsMtx);
                _orbitRings.TryAdd(entityItem.Guid, orb);
            }

            if (entityItem.HasDataBlob <StarInfoDB>())
            {
                _entityIcons.TryAdd(entityItem.Guid, new StarIcon(entityItem));
            }
            if (entityItem.HasDataBlob <SystemBodyInfoDB>())
            {
                _entityIcons.TryAdd(entityItem.Guid, new SysBodyIcon(entityItem));
                if (entityItem.GetDataBlob <SystemBodyInfoDB>().Colonies.Count > 0)
                {
                    foreach (var colony in entityItem.GetDataBlob <SystemBodyInfoDB>().Colonies)
                    {
                        _nameIcons[entityItem.Guid].AddSubName(colony);
                        _sysState.EntityStatesWithPosition[entityItem.Guid].NameIcon = _nameIcons[entityItem.Guid];

                        /*
                         * IconEntityStates.Add(colony.Guid, new EntityState(colony)
                         * {
                         *
                         *  Name = _nameIcons[entityItem.Guid].SubNames[colony.Guid],
                         *  NameIcon = _nameIcons[entityItem.Guid]
                         * });*/
                    }
                }
            }
            if (entityItem.HasDataBlob <ShipInfoDB>())
            {
                _entityIcons.TryAdd(entityItem.Guid, new ShipIcon(entityItem));
            }
        }
Ejemplo n.º 2
0
        void HandleChanges(EntityState entityState)
        {
            foreach (var changeData in entityState.Changes)
            {
                if (changeData.ChangeType == EntityChangeData.EntityChangeType.DBAdded)
                {
                    if (changeData.Datablob is OrbitDB && changeData.Entity.GetDataBlob <OrbitDB>().Parent != null)
                    {
                        if (!((OrbitDB)changeData.Datablob).IsStationary)
                        {
                            if (_sysState.EntityStatesWithPosition.ContainsKey(changeData.Entity.Guid))
                            {
                                entityState = _sysState.EntityStatesWithPosition[changeData.Entity.Guid];
                            }
                            else
                            {
                                entityState = new EntityState(changeData.Entity)
                                {
                                    Name = "Unknown"
                                }
                            };

                            _orbitRings[changeData.Entity.Guid] = new OrbitEllipseIcon(entityState, _state.UserOrbitSettingsMtx);
                        }
                    }
                    if (changeData.Datablob is WarpMovingDB)
                    {
                        var widget = new ShipMoveWidget(changeData.Entity);
                        widget.OnPhysicsUpdate();
                        //Matrix matrix = new Matrix();
                        //matrix.Scale(_camera.ZoomLevel);
                        //widget.OnFrameUpdate(matrix, _camera);
                        _moveIcons[changeData.Entity.Guid] = widget;
                        //_moveIcons.Add(changeData.Entity.ID, widget);
                    }

                    if (changeData.Datablob is NewtonMoveDB)
                    {
                        OrbitHypobolicIcon orb;
                        orb = new OrbitHypobolicIcon(entityState, _state.UserOrbitSettingsMtx);
                        _orbitRings.AddOrUpdate(changeData.Entity.Guid, orb, ((guid, data) => data = orb));
                    }
                    //if (changeData.Datablob is NameDB)
                    //TextIconList[changeData.Entity.ID] = new TextIcon(changeData.Entity, _camera);

                    //_entityIcons[changeData.Entity.ID] = new EntityIcon(changeData.Entity, _camera);
                }
                if (changeData.ChangeType == EntityChangeData.EntityChangeType.DBRemoved)
                {
                    if (changeData.Datablob is OrbitDB)
                    {
                        _orbitRings.TryRemove(changeData.Entity.Guid, out IDrawData foo);
                    }
                    if (changeData.Datablob is WarpMovingDB)
                    {
                        _moveIcons.TryRemove(changeData.Entity.Guid, out IDrawData foo);
                    }

                    if (changeData.Datablob is NewtonMoveDB)
                    {
                        _orbitRings.TryRemove(changeData.Entity.Guid, out IDrawData foo);
                    }

                    //if (changeData.Datablob is NameDB)
                    //TextIconList.Remove(changeData.Entity.ID);
                }
            }
        }

        void TextIconsDistribute()
        {
            if (_nameIcons.Count == 0)
            {
                return;
            }
            var occupiedPosition             = new List <IRectangle>();
            IComparer <IRectangle> byViewPos = new ByViewPosition();
            var textIconList = new List <NameIcon>(_nameIcons.Values);


            //Consolidate TextIcons that share the same position and name
            textIconList.Sort();
            int listLength       = textIconList.Count;
            int textIconQuantity = 1;

            for (int i = 1; i < listLength; i++)
            {
                if (textIconList[i - 1].CompareTo(textIconList[i]) == 0)
                {
                    textIconQuantity++;
                    textIconList.RemoveAt(i);
                    i--;
                    listLength--;
                }
                else if (textIconQuantity > 1)
                {
                    textIconList[i - 1].NameString += " x" + textIconQuantity;
                    textIconQuantity = 1;
                }
            }

            //Placement happens bottom to top, left to right
            //Each newly placed Texticon is compared to only the Texticons that are placed above its position
            //Therefore a sorted list of the occupied Positions is maintained
            occupiedPosition.Add(textIconList[0]);



            List <NameIcon> texiconsCopy = new List <NameIcon>();

            texiconsCopy.AddRange(_nameIcons.Values);

            int numTextIcons = texiconsCopy.Count;

            for (int i = 1; i < numTextIcons; i++)
            {
                var     item   = texiconsCopy[i - 1];
                Vector2 height = new Vector2()
                {
                    X = 0, Y = item.Height
                };
                int lowestPosIndex = occupiedPosition.BinarySearch(item.ViewDisplayRect + height, byViewPos);
                int lpi            = lowestPosIndex;
                if (lowestPosIndex < 0)
                {
                    lpi = ~lowestPosIndex;
                }

                for (int j = lpi; j < occupiedPosition.Count; j++)
                {
                    if (item.ViewDisplayRect.Intersects(occupiedPosition[j]))
                    {
                        var newpoint = new Vector2()
                        {
                            X = item.ViewOffset.X,
                            Y = item.ViewOffset.Y - occupiedPosition[j].Height
                        };
                        item.ViewOffset = newpoint;
                    }
                }
                //Inserts the new label sorted
                int insertIndex = occupiedPosition.BinarySearch(item, byViewPos);
                if (insertIndex < 0)
                {
                    insertIndex = ~insertIndex;
                }
                occupiedPosition.Insert(insertIndex, item);
            }
        }