private void Refresh()
    {
        if (items == null)
        {
            items = new PooledList<ShipStatsEntry, KeyValuePair<string, string>>(content, statsEntryPrefab);
        }

        if (!PlayerShip.LocalPlayer)
        {
            items.Clear();
            return;
        }

        var ship = PlayerShip.LocalPlayer.Ship;
        var stats = ship.CurrentStats;
        var hp = ship.GetComponent<Hitpoints>();
      
        var entries = new Dictionary<string, string>();
        entries.Add("DPS", ship.EstimateDps().ToString("F2"));
        entries.Add("Max speed", stats.MaxSpeed.ToString("F2") +"m/s");
        entries.Add("Agility", stats.MaxTurnSpeed.ToString("F2") + "deg/s");
        entries.Add("Armor", hp.GetMaxArmor().ToString());
        entries.Add("Shield", hp.GetMaxShields().ToString());
        entries.Add("Mass", (stats.Mass * 0.001f).ToString("F2") + "t");

        if (items == null)
        {
            items = new PooledList<ShipStatsEntry, KeyValuePair<string, string>>(content, statsEntryPrefab);
        }

        items.Refresh(entries, (i, item, entry) => item.SetText(entry.Key, entry.Value));
    }
Example #2
0
        void CollectPreviewProperties(PooledList <PreviewProperty> perMaterialPreviewProperties)
        {
            using (CollectPreviewPropertiesMarker.Auto())
                using (var tempCollectNodes = PooledHashSet <AbstractMaterialNode> .Get())
                    using (var tempPreviewProps = PooledList <PreviewProperty> .Get())
                    {
                        // we only collect properties from nodes upstream of something we want to draw
                        // TODO: we could go a step farther and only collect properties from nodes we know have changed their value
                        // but that's not something we currently track...
                        PropagateNodes(m_NodesToDraw, PropagationDirection.Upstream, tempCollectNodes);

                        foreach (var propNode in tempCollectNodes)
                        {
                            propNode.CollectPreviewMaterialProperties(tempPreviewProps);
                        }

                        foreach (var prop in m_Graph.properties)
                        {
                            tempPreviewProps.Add(prop.GetPreviewMaterialProperty());
                        }

                        foreach (var previewProperty in tempPreviewProps)
                        {
                            previewProperty.SetValueOnMaterialPropertyBlock(m_SharedPreviewPropertyBlock);

                            // virtual texture assignments must be pushed to the materials themselves (MaterialPropertyBlocks not supported)
                            if ((previewProperty.propType == PropertyType.VirtualTexture) &&
                                (previewProperty.vtProperty?.value?.layers != null))
                            {
                                perMaterialPreviewProperties.Add(previewProperty);
                            }
                        }
                    }
        }
Example #3
0
        private IEnumerator SortRoutine()
        {
            while (true)
            {
                using (PooledList <Transform> children = PooledList <Transform> .Create())
                {
                    if (children.Capacity < SortGroup.childCount)
                    {
                        children.Capacity = SortGroup.childCount;
                    }
                    for (int i = 0; i < SortGroup.childCount; ++i)
                    {
                        children.Add(SortGroup.GetChild(i));
                    }

                    children.Sort(s_HeightSorter);

                    for (int i = 0; i < children.Count; ++i)
                    {
                        children[i].SetSiblingIndex(i);
                    }

                    if (Controller.DraggingObject != null && Controller.DraggingObject.transform.parent == SortGroup)
                    {
                        Controller.DraggingObject.transform.SetAsLastSibling();
                    }
                }

                yield return(0.05f);
            }
        }
 public void GlobalSetup()
 {
     list            = CreateList(N);
     pooled          = CreatePooled(N);
     containedList   = list[list.Count / 2];
     containedPooled = pooled[pooled.Count / 2];
 }
            public void BasicInsert(T[] items, T item, int index, int repeat)
            {
                using (var list = new PooledList <T>(items))
                {
                    for (int i = 0; i < repeat; i++)
                    {
                        list.Insert(index, item);
                    }

                    Assert.True(list.Contains(item));                //"Expect it to contain the item."
                    Assert.Equal(list.Count, items.Length + repeat); //"Expect to be the same."

                    for (int i = 0; i < index; i++)
                    {
                        Assert.Equal(list[i], items[i]); //"Expect to be the same."
                    }

                    for (int i = index; i < index + repeat; i++)
                    {
                        Assert.Equal(list[i], item); //"Expect to be the same."
                    }


                    for (int i = index + repeat; i < list.Count; i++)
                    {
                        Assert.Equal(list[i], items[i - repeat]); //"Expect to be the same."
                    }
                }
            }
        void CollectPreviewProperties()
        {
            using (CollectPreviewPropertiesMarker.Auto())
                using (var tempCollectNodes = PooledHashSet <AbstractMaterialNode> .Get())
                    using (var tempPreviewProps = PooledList <PreviewProperty> .Get())
                    {
                        // we only collect properties from nodes upstream of something we want to draw
                        // TODO: we could go a step farther and only collect properties from nodes we know have changed their value
                        // but that's not something we currently track...
                        PropagateNodes(m_NodesToDraw, PropagationDirection.Upstream, tempCollectNodes);

                        foreach (var propNode in tempCollectNodes)
                        {
                            propNode.CollectPreviewMaterialProperties(tempPreviewProps);
                        }

                        foreach (var prop in m_Graph.properties)
                        {
                            tempPreviewProps.Add(prop.GetPreviewMaterialProperty());
                        }

                        foreach (var previewProperty in tempPreviewProps)
                        {
                            previewProperty.SetValueOnMaterialPropertyBlock(m_SharedPreviewPropertyBlock);
                        }
                    }
        }
Example #7
0
        public void Reverse_int_int(int listLength, int index, int count)
        {
            PooledList <T> list       = GenericListFactory(listLength);
            PooledList <T> listBefore = list.ToPooledList();

            list.Reverse(index, count);

            for (int i = 0; i < index; i++)
            {
                Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same."
            }

            int j = 0;

            for (int i = index; i < index + count; i++)
            {
                Assert.Equal(list[i], listBefore[index + count - (j + 1)]); //"Expect them to be the same."
                j++;
            }

            for (int i = index + count; i < listBefore.Count; i++)
            {
                Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same."
            }

            list.Dispose();
            listBefore.Dispose();
        }
 public static void ToStream(Voxel[] voxels, Stream stream)
 {
     using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
     {
         var    encoded       = new PooledList <long>();
         var    currentVoxel  = voxels[0];
         ushort currentLength = 1;
         for (int i = 1; i < voxels.Length; i++)
         {
             if (voxels[i] == currentVoxel)
             {
                 currentLength++;
             }
             else
             {
                 writer.Write(currentLength);
                 writer.Write(currentVoxel.Data);
                 currentVoxel  = voxels[i];
                 currentLength = 1;
             }
         }
         writer.Write(currentLength);
         writer.Write(currentVoxel.Data);
     }
 }
Example #9
0
        public EmbedMenu(ref EmbedMenuAct ExecutedEMAct, ref EmbedMenu <UserT, ChannelT> PrevEM, string title, string desc)
        {
            InitAct = ExecutedEMAct.Act;

            EMHistory = PrevEM.EMHistory;

            Title = title;

            Desc = desc;

            Acts = PrevEM.Acts;

            CurrentEMIndex = unchecked (++PrevEM.CurrentEMIndex);

            //Page defaults

            CurrentPageNumber = 0;

            MaxElemsPerPage = 5;

            Pages = EMHelpers.DivideAndRoundUpFast(Acts.Count, MaxElemsPerPage);

            //User creds

            User = PrevEM.User;

            Channel = PrevEM.Channel;

            Unsafe.SkipInit(out CurrentMsg);
        }
        private static bool ProcessTags(ref AttributeEnumerationState state, KeyValuePair <string, string> attribute)
        {
            string key    = attribute.Key;
            string strVal = attribute.Value;

            if (strVal != null)
            {
                if (RemoteEndpointServiceNameKeyResolutionDictionary.TryGetValue(key, out int priority) &&
                    (state.RemoteEndpointServiceName == null || priority < state.RemoteEndpointServiceNamePriority))
                {
                    state.RemoteEndpointServiceName         = strVal;
                    state.RemoteEndpointServiceNamePriority = priority;
                }
                else if (key == Resource.ServiceNameKey)
                {
                    state.ServiceName = strVal;
                }
                else if (key == Resource.ServiceNamespaceKey)
                {
                    state.ServiceNamespace = strVal;
                }
                else
                {
                    PooledList <KeyValuePair <string, string> > .Add(ref state.Tags, new KeyValuePair <string, string>(key, strVal));
                }
            }
            else
            {
                PooledList <KeyValuePair <string, string> > .Add(ref state.Tags, new KeyValuePair <string, string>(key, strVal));
            }

            return(true);
        }
Example #11
0
        void ForeachConnectedNode(AbstractMaterialNode node, PropagationDirection dir, Action <AbstractMaterialNode> action)
        {
            using (var tempEdges = PooledList <IEdge> .Get())
                using (var tempSlots = PooledList <MaterialSlot> .Get())
                {
                    // Loop through all nodes that the node feeds into.
                    if (dir == PropagationDirection.Downstream)
                    {
                        node.GetOutputSlots(tempSlots);
                    }
                    else
                    {
                        node.GetInputSlots(tempSlots);
                    }

                    foreach (var slot in tempSlots)
                    {
                        // get the edges out of each slot
                        tempEdges.Clear();                        // and here we serialize another list, ouch!
                        m_Graph.GetEdges(slot.slotReference, tempEdges);
                        foreach (var edge in tempEdges)
                        {
                            // We look at each node we feed into.
                            var connectedSlot = (dir == PropagationDirection.Downstream) ? edge.inputSlot : edge.outputSlot;
                            var connectedNode = connectedSlot.node;

                            action(connectedNode);
                        }
                    }
                }
        }
        private HashSet <ushort> DnaToUsedNodes(BitArray dna)
        {
            using (var mstNodes = new PooledList <int>(dna.Length + TargetNodes.Count))
                using (var mst = new MinimalSpanningTree(mstNodes, Distances))
                {
                    for (var i = 0; i < dna.Length; i++)
                    {
                        if (dna[i])
                        {
                            mstNodes.Add(i);
                        }
                    }
                    var searchSpaceNodeCount = mstNodes.Count;
                    for (var i = 0; i < TargetNodes.Count; i++)
                    {
                        mstNodes.Add(TargetNodes[i].DistancesIndex);
                    }

                    var spanningEdges = _orderedEdges is null
                    ? mst.Span(StartNode.DistancesIndex)
                    : mst.Span(_orderedEdges);

                    return(GetSkillNodeIds(mstNodes, searchSpaceNodeCount, spanningEdges));
                }
        }
Example #13
0
        internal EmbedMenu(EmbedMenuDel initAct, UserT user, ChannelT channel, ref PooledList <EmbedMenu <UserT, ChannelT> > emHistory, ref PooledList <EmbedMenuAct> acts)
        {
            InitAct = initAct;

            User = user;

            Channel = channel;

            EMHistory = emHistory;

            Acts = acts;

            CurrentEMIndex = 0;

            //Page defaults

            CurrentPageNumber = 0;

            MaxElemsPerPage = 5;

            Pages = EMHelpers.DivideAndRoundUpFast(Acts.Count, MaxElemsPerPage);

            Unsafe.SkipInit(out Title);

            Unsafe.SkipInit(out Desc);

            Unsafe.SkipInit(out CurrentMsg);
        }
            public bool ForEach(KeyValuePair <string, object> activityTag)
            {
                if (activityTag.Value == null)
                {
                    return(true);
                }

                string key = activityTag.Key;

                if (activityTag.Value is string strVal)
                {
                    PeerServiceResolver.InspectTag(ref this, key, strVal);

                    if (key == SpanAttributeConstants.StatusCodeKey)
                    {
                        if (strVal == "Error")
                        {
                            PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, new KeyValuePair <string, object>("error", "true"));
                        }
                        else if (strVal == "Unset")
                        {
                            // Unset Status is not sent: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md#status
                            return(true);
                        }
                    }
                }
                else if (activityTag.Value is int intVal && activityTag.Key == SemanticConventions.AttributeNetPeerPort)
                {
                    PeerServiceResolver.InspectTag(ref this, key, intVal);
                }

                PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, activityTag);

                return(true);
            }
Example #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RoutedEvent"/> class.
        /// </summary>
        /// <param name="e">The routed event to be raised.</param>
        public EventRoute(RoutedEvent e)
        {
            e = e ?? throw new ArgumentNullException(nameof(e));

            _event = e;
            _route = null;
        }
        internal SectionMeshData(PooledList <int> simpleVertexData,
                                 PooledList <float> complexVertexPositions, PooledList <int> complexVertexData,
                                 PooledList <uint> complexIndices,
                                 PooledList <int> varyingHeightVertexData, PooledList <uint> varyingHeightIndices,
                                 PooledList <int> crossPlantVertexData,
                                 PooledList <int> cropPlantVertexData,
                                 PooledList <int> opaqueLiquidVertexData, PooledList <uint> opaqueLiquidIndices,
                                 PooledList <int> transparentLiquidVertexData, PooledList <uint> transparentLiquidIndices)
        {
            this.simpleVertexData = simpleVertexData;

            this.complexVertexPositions = complexVertexPositions;
            this.complexVertexData      = complexVertexData;
            this.complexIndices         = complexIndices;

            this.varyingHeightVertexData = varyingHeightVertexData;
            this.varyingHeightIndices    = varyingHeightIndices;

            this.crossPlantVertexData = crossPlantVertexData;

            this.cropPlantVertexData = cropPlantVertexData;

            this.opaqueLiquidVertexData = opaqueLiquidVertexData;
            this.opaqueLiquidIndices    = opaqueLiquidIndices;

            this.transparentLiquidVertexData = transparentLiquidVertexData;
            this.transparentLiquidIndices    = transparentLiquidIndices;
        }
Example #17
0
        public void PooledAddRange_String_CapacityIncrease_Array()
        {
            var pooled = new PooledList <string>();

            for (int j = 0; j < addLoops; j++)
            {
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
            }

            pooled.Dispose();
        }
Example #18
0
 public void GlobalSetup()
 {
     listInt      = CreateList(N);
     listString   = listInt.ConvertAll(i => i.ToString());
     pooledInt    = new PooledList <int>(listInt);
     pooledString = pooledInt.ConvertAll(i => i.ToString());
 }
Example #19
0
        public void PooledAddRange_Int_CapacityIncrease_Enumerable()
        {
            var pooled = new PooledList <string>();

            var enumerable = (IEnumerable <string>)sampleSet;

            for (int j = 0; j < addLoops; j++)
            {
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
                pooled.AddRange(enumerable);
            }

            pooled.Dispose();
        }
    private void Refresh()
    {
        if (statsLines == null)
        {
            statsLines = new PooledList<ShipStatsEntry, KeyValuePair<string, string>>(statsRoot.transform, statsPrefab);
        }

        if (itemType)
        {
            nameLabel.text = itemType.DisplayName;
            icon.sprite = itemType.Icon;
            icon.gameObject.SetActive(true);

            descriptionLabel.text = itemType.Description;

            var stats = new List<KeyValuePair<string, string>>();

            var player = SpaceTraderConfig.LocalPlayer;
            var station = player.Ship.Moorable.DockedAtStation;
            var market = SpaceTraderConfig.Market;

            var baseVal = Market.FormatCurrency(itemType.BaseValue);
            stats.Add(new KeyValuePair<string, string>("Base Value", baseVal));

            if (station)
            {
                int price;
                string priceType;

                if (itemOwnedByPlayer)
                {
                    price = market.GetSellingItemPrice(itemType, station);
                    priceType= "Sells For";
                }
                else
                {
                    price = market.GetBuyingItemPrice(itemType, station);
                    priceType = "Price";
                }

                stats.Add(new KeyValuePair<string, string>(priceType, Market.FormatCurrency(price)));
            }

            stats.AddRange(itemType.GetDisplayedStats(itemOwnedByPlayer? player.Ship : null));

            statsLines.Refresh(stats, (i, statsLine, statsEntry) =>
                statsLine.SetText(statsEntry.Key, statsEntry.Value));
        }
        else
        {
            nameLabel.text = "No item selected";
            icon.gameObject.SetActive(false);
            descriptionLabel.text = null;

            statsLines.Clear();
        }

        statsRoot.Elements = statsLines.Select(l => (RectTransform) l.transform);
    }
        protected virtual PooledList <T> GenericListFactory(int count)
        {
            IEnumerable <T> toCreateFrom = CreateEnumerable(EnumerableType.List, null, count, 0, 0);
            var             list         = new PooledList <T>(toCreateFrom);

            RegisterForDispose(list);
            return(list);
        }
Example #22
0
        public void Constructor_Default()
        {
            PooledList <T> list = new PooledList <T>();

            Assert.Equal(0, list.Capacity);             //"Expected capacity of list to be the same as given."
            Assert.Empty(list);                         //"Do not expect anything to be in the list."
            Assert.False(((IList <T>)list).IsReadOnly); //"List should not be readonly"
        }
Example #23
0
        public void TerribleBugWhenAppendingString()
        {
            var expected = "longer than the capacity";
            var builder  = new PooledList <char>(1);

            builder.AddRange(expected.AsSpan());
            Assert.Equal(expected, builder.AsEnumerable());
        }
Example #24
0
        public void NoSizeToCapacityItemsSet()
        {
            var list  = new PooledList <T>(13, false);
            var value = CreateT(42);

            Assert.Throws <ArgumentOutOfRangeException>(() => list[12] = value);
            list.Dispose();
        }
 public void PooledIterSetup()
 {
     pooledLists = new PooledList <int> [5000];
     for (int i = 0; i < 5000; i++)
     {
         pooledLists[i] = new PooledList <int>(list);
     }
 }
Example #26
0
        public void SizeToCapacityCapacityCount()
        {
            var list = new PooledList <T>(13, true);

            Assert.InRange(list.Capacity, 13, list.Capacity);
            Assert.Equal(13, list.Count);
            list.Dispose();
        }
            public void InsertRangeIEnumerable(T[] itemsX, T[] itemsY, int index, int repeat, Func <T[], IEnumerable <T> > constructIEnumerable)
            {
                PooledList <T> list = new PooledList <T>(constructIEnumerable(itemsX));

                for (int i = 0; i < repeat; i++)
                {
                    list.InsertRange(index, constructIEnumerable(itemsY));
                }

                foreach (T item in itemsY)
                {
                    Assert.True(list.Contains(item));                               //"Should contain the item."
                }
                Assert.Equal(list.Count, itemsX.Length + (itemsY.Length * repeat)); //"Should have the same result."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], itemsX[i]); //"Should have the same result."
                }

                for (int i = index; i < index + (itemsY.Length * repeat); i++)
                {
                    Assert.Equal(list[i], itemsY[(i - index) % itemsY.Length]); //"Should have the same result."
                }

                for (int i = index + (itemsY.Length * repeat); i < list.Count; i++)
                {
                    Assert.Equal(list[i], itemsX[i - (itemsY.Length * repeat)]); //"Should have the same result."
                }

                //InsertRange into itself
                list.Dispose();
                list = new PooledList <T>(constructIEnumerable(itemsX));
                list.InsertRange(index, list);

                foreach (T item in itemsX)
                {
                    Assert.True(list.Contains(item));                    //"Should contain the item."
                }
                Assert.Equal(list.Count, itemsX.Length + itemsX.Length); //"Should have the same result."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], itemsX[i]); //"Should have the same result."
                }

                for (int i = index; i < index + itemsX.Length; i++)
                {
                    Assert.Equal(list[i], itemsX[(i - index) % itemsX.Length]); //"Should have the same result."
                }

                for (int i = index + (itemsX.Length); i < list.Count; i++)
                {
                    Assert.Equal(list[i], itemsX[i - (itemsX.Length)]); //"Should have the same result."
                }

                list.Dispose();
            }
 public void PooledAddRangeIEnumerable()
 {
     for (int i = 0; i < 5000; i++)
     {
         var emptyList = new PooledList <int>();
         emptyList.AddRange(IntEnumerable());
         emptyList.Dispose();
     }
 }
 public void PooledAddRangeICollection()
 {
     for (int i = 0; i < 5000; i++)
     {
         var emptyList = new PooledList <int>();
         emptyList.AddRange(list);
         emptyList.Dispose();
     }
 }
 public void CopyTo_ArgumentValidity(int count)
 {
     if (count > 0)
     {
         PooledList <T> list = GenericListFactory(count);
         AssertExtensions.Throws <ArgumentException>(null, () => list.CopyTo(new T[0]));
         list.Dispose();
     }
 }
        public void GlobalSetup()
        {
            int samples = GetSampleLength();

            sampleSet = new int[samples];

            for (int i = 0; i < samples; i++)
            {
                sampleSet[i] = i;
            }

            addLoops = LARGE_SAMPLE_LENGTH / samples;

            // create lists big enough to hold 17 copies of the sample set
            startingCapacity = 17 * samples * addLoops;
            list             = new List <int>(startingCapacity);
            pooled           = new PooledList <int>(startingCapacity);

            for (int j = 0; j < addLoops; j++)
            {
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);
                list.AddRange(sampleSet);

                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
                pooled.AddRange(sampleSet);
            }
        }
Example #32
0
        public void Reverse_InvalidParameters(int listLength)
        {
            if (listLength % 2 != 0)
            {
                listLength++;
            }
            PooledList <T> list = GenericListFactory(listLength);

            (int, int)[] InvalidParameters = new[]
Example #33
0
        public void Refresh(PooledList<QuestListItem, Quest> itemsList)
        {
            EmptyMessage.gameObject.SetActive(itemsList.Count == 0);

            //status of quests can change independent of which quests are displayed
            foreach (var item in itemsList)
            {
                item.UpdateStatus();
            }
        }
    private void Update()
    {
        if (notifications == null)
        {
            notifications = new PooledList<MessagePanelItem, IPlayerNotification>(messageContent, messagePrefab);
        }

        var items = PlayerNotifications.GetNotifications(notificationCount, notificationCategory)
            .Where(n => n.Created > Time.time - maxAge);

        notifications.Refresh(items, (i, item, data) => 
            item.Assign(data.Text));
    }
    private void Update()
    {
        var player = PlayerShip.LocalPlayer;

        if (modules == null)
        {
            modules = new PooledList<ShipModuleController, HardpointModule>(modulesRoot, moduleTemplate);
        }

        if (!player)
        {
            modules.Clear();
            return;
        }

        modules.Refresh(player.Ship.ModuleLoadout, (i, module, slot) =>
            module.Assign(player.Ship, i, i == highlightedIndex));
    }
Example #36
0
    public void Refresh()
    {
        if (questList == null)
        {
            questList = new PooledList<QuestListItem, Quest>(availableQuests.ItemsRoot, itemPrefab);
        }

        if (acceptedQuestList == null)
        {
            acceptedQuestList = new PooledList<QuestListItem, Quest>(acceptedQuests.ItemsRoot, itemPrefab);
        }

        var player = SpaceTraderConfig.LocalPlayer;

        if (player)
        {
            var station = player.Moorable.DockedAtStation;
            var myQuests = SpaceTraderConfig.QuestBoard.QuestsForPlayer(player);
            var questsNotAccepted = SpaceTraderConfig.QuestBoard.QuestsAtStation(station)
                .Except(myQuests);

            availableQuests.SetActive(station);
            if (station)
            {
                questList.Refresh(questsNotAccepted, (index, listItem, quest) =>
                    listItem.Assign(quest));
            }
            else
            {
                questList.Clear();
            }

            acceptedQuestList.Refresh(myQuests, (index, listItem, quest) =>
                listItem.Assign(quest));
        }
        else
        {
            questList.Clear();
            acceptedQuestList.Clear();
        }

        availableQuests.Refresh(questList);
        acceptedQuests.Refresh(acceptedQuestList);
    }
Example #37
0
    public void Update()
    {
        var player = PlayerShip.LocalPlayer;

        if (items == null)
        {
            items = new PooledList<FleetListItem, Ship>(content, itemPrefab);
        }

        Fleet playerFleet;
        if (!player 
            || !player.Ship 
            || !(playerFleet = SpaceTraderConfig.FleetManager.GetFleetOf(player.Ship)))
        {
            items.Clear();
        }
        else
        {
            var ships = playerFleet.Members.ToList();
            ships.Remove(player.Ship);

            items.Refresh(ships, (i, item, ship) => item.Assign(ship, bracketManager.FleetMemberColor));
        }
    }
    void LateUpdate()
    {
        if (brackets == null)
        {
            brackets = new PooledList<Bracket, Targetable>(transform, bracket);
        }

        UpdateShipBrackets();

        var spaceCam = FollowCamera.Current;
        if (spaceCam && spaceCam.isActiveAndEnabled)
        {
            CheckSpaceClicks(spaceCam);
        }
    }
    private void Update()
    {
        IEnumerable<CrewMember> crew = null;

        Ship playerShip = PlayerShip.LocalPlayer ? PlayerShip.LocalPlayer.Ship : null;

        if (playerShip)
        {
            if (targetCrew == TargetCrew.Station)
            {
                var station = PlayerShip.LocalPlayer.Moorable.DockedAtStation;
                if (station)
                {
                    crew = station.AvailableCrew;
                }
            }
            else
            {
                switch (forAssignment)
                {
                    case CrewAssignment.Captain:
                        crew = playerShip.GetCaptain().AsOptionalObject();
                        break;
                    default:
                        crew = playerShip.GetPassengers();
                        break;
                }
            }
        }

        if (crewItems == null)
        {
            crewItems = new PooledList<CrewListItem, CrewMember>(contentArea, itemPrefab);
        }

        if (crew != null && crew.Any())
        {
            CrewListItem.BuySellMode buySellMode;

            if (playerShip.Moorable.DockedAtStation)
            {
                if (targetCrew == TargetCrew.Player)
                {
                    buySellMode = CrewListItem.BuySellMode.Sellable;
                }
                else
                {
                    buySellMode = CrewListItem.BuySellMode.Buyable;
                }
            }
            else
            {
                buySellMode = CrewListItem.BuySellMode.ReadOnly;
            }

            crewItems.Refresh(crew, (i, existingItem, newCrewMember) => 
                existingItem.Assign(newCrewMember, buySellMode));

            emptyLabel.gameObject.SetActive(false);
        }
        else
        {
            crewItems.Clear();

            emptyLabel.gameObject.SetActive(true);
        }
    }
Example #40
0
    void LateUpdate()
    {
        if (markers == null)
        {
            markers = new PooledList<PredictorMarker, Vector3>(transform, markerPrefab);
        }

        var player = PlayerShip.LocalPlayer;
        var camera = FollowCamera.Current.Camera;
        Ship playerShip;

        if (!player 
            || !(playerShip = player.Ship) 
            || !player.Ship.Target 
            || player.Ship.Target.TargetSpace != TargetSpace.Local
            || !camera)
        {
            markers.Clear();
            return;
        }
        
        var loadout = playerShip.ModuleLoadout;
        var modCount = loadout.SlotCount;

        var newMarkerPositions = new List<Vector3>(modCount);
        //var markerItems = new List<HardpointModule>();

        var playerTargetable = playerShip.Targetable;
        
        /* one marker per active hardpoint module which returns true for
        IsPredictable. we get the prediction points from the module's 
        behaviour here too */
        for (int moduleIndex = 0; moduleIndex < modCount; ++moduleIndex)
        {
            var module = loadout.GetSlot(moduleIndex);
            if (!module.ModuleType)
            {
                //empty slot
                continue;
            }
            
            var behavior = module.ModuleType.Behaviour;
            var predictPoint = behavior.PredictTarget(playerShip, moduleIndex, playerShip.Target);

            if (predictPoint.HasValue)
            {
                if (predictPoint.HasValue && predictPoint.Value.z >= 0)
                {
                    newMarkerPositions.Add(predictPoint.Value);
                }
            }
        }

        var targetOrigin = player.Ship.Target.transform.position;
        float maxDistSqr = 0;
        for (int pos = 0; pos < newMarkerPositions.Count; ++pos)
        {
            float distSqr = (targetOrigin - newMarkerPositions[pos]).sqrMagnitude;
            maxDistSqr = Mathf.Max(maxDistSqr, distSqr);
        }

        if (maxDistSqr < MIN_SPEED)
        {
            markers.Clear();
        }
        else
        {
            var predictorColor = brackets.GetBracketColor(playerTargetable, playerShip.Target);
            markers.Refresh(newMarkerPositions, (i, marker, position) =>
            {
                //PredictTarget returns world pos
                var screenPos = camera.WorldToScreenPoint(position);

                marker.transform.position = screenPos;
                marker.Color = predictorColor;
            });
        }
    }