コード例 #1
0
        private string GetKitForUI(BasePlayer player, string name)
        {
            var kit = FindKitByName(name);

            if (kit == null)
            {
                return(null);
            }

            var data = GetDataKitInfo(player, name);

            var obj = new KitUI {
                block       = kit.block,
                cooldown    = kit.cooldown,
                uses        = kit.uses - data.uses,
                displayName = kit.displayName,
                description = kit.description,
                items       = new Dictionary <string, int>(),
            };

            foreach (var item in kit.items)
            {
                if (obj.items.ContainsKey(item.shortname))
                {
                    obj.items[item.shortname] += item.amount;
                }
                else
                {
                    obj.items.Add(item.shortname, item.amount);
                }
            }

            return(JsonConvert.SerializeObject(obj));
        }
コード例 #2
0
        private string GetPlayerKitsForUI(BasePlayer player)
        {
            var kits = config.kits.Where(x => !x.forAPI);
            var list = new List <KitUI>();
            var data = Data.Get(player.UserIDString);

            foreach (var kit in kits)
            {
                var kitInfo = GetDataKitInfo(player, kit.name, data);
                var message = GetUIMessage(player, kit, kitInfo);
                if (message == null)
                {
                    continue;
                }

                var obj = new KitUI {
                    block           = kit.block,
                    cooldown        = kit.cooldown,
                    description     = kit.description,
                    name            = kit.name,
                    items           = new Dictionary <string, int>(),
                    url             = kit.url,
                    uses            = kit.uses,
                    displayName     = kit.displayName,
                    messageOnButton = message
                };

                foreach (var item in kit.items)
                {
                    if (!obj.items.TryAdd(item.shortname, item.amount))
                    {
                        obj.items[item.shortname] += item.amount;
                    }
                }

                list.Add(obj);
            }

            var array = list.ToArray();

            return(JsonConvert.SerializeObject(array));
        }
コード例 #3
0
        void GenerateContents(KitUI kit, float colms, float colSize, float sizeX, float sizeY, CuiElementContainer container, string parent, string AnchorMin = "0.1 0.5", string AnchorMax = "0.1 0.5", int fontS = 0)
        {
            var i           = 0;
            var itemsOnLine = (colms * colSize) / sizeX;
            var originalX   = 0f;
            var originalY   = 0f;
            var startX      = originalX;
            var startY      = originalY;

            foreach (var pair in kit.items)
            {
                var url    = $"https://rustlabs.com/img/items180/{pair.Key}.png";
                var amount = pair.Value;

                // Icon
                container.Add(new CuiElement {
                    Name       = elemInfo + pair.Key,
                    Parent     = parent,
                    Components =
                    {
                        new CuiRawImageComponent
                        {
                            Png   = GetImage(url),
                            Color = "1 1 1 1"
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = AnchorMin,
                            AnchorMax = AnchorMax,
                            OffsetMin = $"{startX} {startY - sizeY}",
                            OffsetMax = $"{startX + sizeX} {startY}"
                        }
                    }
                });

                // Amount
                CuiTextComponent cuiTC = new CuiTextComponent {
                    Text  = amount.ToString(),
                    Align = TextAnchor.LowerRight
                };
                CuiTextComponent cuiTCF = new CuiTextComponent {
                    Text     = amount.ToString(),
                    Align    = TextAnchor.LowerRight,
                    FontSize = fontS
                };
                container.Add(new CuiElement {
                    Parent     = elemInfo + pair.Key,
                    Components =
                    {
                        fontS > 0 ? cuiTCF : cuiTC,
                        new CuiOutlineComponent
                        {
                            Color    = config.outlineColor,
                            Distance = config.outlineDistance
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "1 1"
                        }
                    }
                });


                startX += sizeX + config.ContentoffsetX;
                i++;

                if (i > 0 && i % colms == 0)
                {
                    startX  = originalX;
                    startY -= sizeY + config.ContentoffsetY;
                }
            }
        }