예제 #1
0
        void DrawUI(BasePlayer player, BuildingGrade.Enum grade, int seconds)
        {
            if (!loaded)
            {
                return;
            }
            string imgString = seconds.ToString("00");
            string image1    = ImageStorage.FetchPng(imgString[0].ToString());
            string image2    = ImageStorage.FetchPng(imgString[1].ToString());

            core.DrawUI(player, "BuildingUpgrade", "menu", gradeImages[$"building.upgrade.{(int) grade}"], image1, image2);
        }
예제 #2
0
        void drawTopMenu(BasePlayer player)
        {
            topList topdata = calcSum();
            string  topTop  = topdata.arr;

            float points = kills * data[player.userID].pvp.kills - deaths * data[player.userID].pvp.deaths + resGather * (data[player.userID].gather.wood + data[player.userID].gather.stone + data[player.userID].gather.metalOre + data[player.userID].gather.sulfurOre + data[player.userID].gather.hqmetalOre) +
                           resQuarry * (data[player.userID].quarry.stone + data[player.userID].quarry.metal + data[player.userID].quarry.metalOre + data[player.userID].quarry.sulfurOre + data[player.userID].quarry.hqmetal + data[player.userID].quarry.hqmetalOre) + level;



            CuiHelper.DestroyUi(player, "TopParent");
            startGui[player.userID] = CuiHelper.GetGuid();

            cui.createparentcurs("TopParent", "0 0 0 0", "0.05 0.1", "0.95 0.95");

            cui.createimg("StatImg2", "TopParent", ImageStorage.FetchPng("stat2"), "0 0", "1 1");

            cui.createtext("TopText", "TopParent", "", 24, "0.3 0.8", "0.9 0.95", TextAnchor.MiddleLeft);

            //cui.createbox("BoxTop", "TopParent","0.3 0.6 0.3 0.5","0.02 0.05", "0.38 0.75");
            cui.createtext("TopText", "TopParent", "<color=#81feff>" + topTop + "</color>", 17, "0.06 0.08", "0.37 0.72", TextAnchor.MiddleLeft);

            //cui.createtext("TopTimeText", "TopParent", "<color=black>"+topTime+"</color>", 18, "0.6 0.1", "0.99 0.74",TextAnchor.MiddleLeft);

            //cui.createbox("MeTop", "TopParent","0.3 0.6 0.3 0.5","0.52 0.6", "0.86 0.75");
            cui.createtext("MeText", "TopParent", "<color=#81feff>" + data[player.userID].name + " - " + points.ToString() + "</color>", 18, "0.53 0.61", "0.85 0.74", TextAnchor.MiddleLeft);

            cui.createtext("TopExitText", "TopParent", "", 20, "0.55 0.05", "0.75 0.15", TextAnchor.MiddleCenter);
            cui.createbutton("TopExitButton", "TopParent", "", "TopParent", "0 0 0 0", "0.55 0.05", "0.75 0.15");

            cui.createtext("TopbackText", "TopParent", "", 20, "0.55 0.2", "0.75 0.3", TextAnchor.MiddleCenter);
            cui.createbutton("TopbackButton", "TopParent", "stat", "TopParent", "0 0 0 0", "0.55 0.2", "0.75 0.3");

            CuiHelper.AddUi(player, cui.elements);
            cui.elements.Clear();
        }
예제 #3
0
 string[] GetImages(string value) => value.Select(p => ImageStorage.FetchPng(p.ToString())).ToArray();
예제 #4
0
        IEnumerator LoadFunctions()
        {
            yield return(ImageStorage.Store(imagesDB.ReadObject <Dictionary <string, string> >() ?? new Dictionary <string, string>()));

            var funcs = uiDB.ReadObject <Dictionary <string, CuiFunction> >();

            functions = new Dictionary <string, Dictionary <string, CuiFunction> >();

            var comparer = new CuiElementComparer();

            foreach (var funcPair in funcs)
            {
                var    func = funcPair.Key;
                string plugin, funcName;
                SplitFunc(func, out plugin, out funcName);

                if (!functions.ContainsKey(plugin))
                {
                    functions[plugin] = new Dictionary <string, CuiFunction>();
                }

                functions[plugin].Add(funcName, funcPair.Value);

                var function = functions[plugin][funcName];
                var argc     = function.argc();
                for (int i = 0; i < 4; i++)
                {
                    function.cacheArgs.Add(new List <List <CuiElement> >());
                    var json = function[i];
                    if (string.IsNullOrEmpty(json))
                    {
                        continue;
                    }
                    var elements = CuiHelper.FromJson(json);

                    foreach (var e in elements)
                    {
                        var component = e.Components.FirstOrDefault(c => c.Type == "UnityEngine.UI.RawImage");
                        var rawImage  = component as CuiRawImageComponent;
                        if (!string.IsNullOrEmpty(rawImage?.Png))
                        {
                            rawImage.Sprite = "assets/content/textures/generic/fulltransparent.tga";

                            if (rawImage.Png.StartsWith("{"))
                            {
                                if (rawImage.Png == "{colon}")
                                {
                                    rawImage.Png = ImageStorage.FetchPng("colon");
                                }
                            }
                            else
                            {
                                var img = ImageStorage.FetchPng(rawImage.Png);
                                if (string.IsNullOrEmpty(img))
                                {
                                    yield return(CommunityEntity.ServerInstance.StartCoroutine(ImageStorage.Store(rawImage.Png, rawImage.Png)));

                                    if (ImageStorage.FetchPng(rawImage.Png) == string.Empty)
                                    {
                                        Puts("NOT LOADED: " + rawImage.Png);
                                    }
                                    rawImage.Png = ImageStorage.FetchPng(rawImage.Png);
                                    //Puts(e.Name + ": " + rawImage.Png);
                                }
                                else
                                {
                                    rawImage.Png = img;
                                }
                            }
                        }
                        else if (rawImage != null && string.IsNullOrEmpty(rawImage.Url) && rawImage.Sprite == "Assets/Icons/rust.png")
                        {
                            rawImage.Sprite = "Assets/Content/UI/UI.Background.Tile.psd";
                        }
                    }

                    function[i] = json = CuiHelper.ToJson(elements);

                    var jsonArgs = json;
                    if (argc == 0)
                    {
                        function.cacheArgs[i].Add(elements);
                        continue;
                    }
                    for (int j = 0; j < argc; j++)
                    {
                        jsonArgs = jsonArgs.Replace("{" + j + "}", "");
                    }
                    var elementsArgs = CuiHelper.FromJson(jsonArgs);

                    var changedElements = elements.Except(elementsArgs, comparer).ToList();

                    var argsElements = changedElements.Select(element => CuiHelper.ToJson(new List <CuiElement>()
                    {
                        element
                    })).ToList();
                    List <int> argNumbers = new List <int>();
                    for (int j = 0; j < argc; j++)
                    {
                        for (int k = 0; k < argsElements.Count; k++)
                        {
                            if (argsElements[k].Contains("{" + j + "}"))
                            {
                                argNumbers.Add(k);
                            }
                        }
                    }
                    for (int j = 0; j < argNumbers.Count; j++)
                    {
                        var e = changedElements[argNumbers[j]];
                        var argsReferences = elements.Where(
                            o => o != e &&
                            o.Parent == e.Parent && Intersect(GetRect(e), GetRect(o)) &&
                            !changedElements.Contains(o)).ToList();
                        argsReferences.Insert(0, e);
                        var newReferences = new List <CuiElement>();
                        for (var index = 0; index < argsReferences.Count; index++)
                        {
                            var element = argsReferences[index];
                            newReferences.AddRange(GetChildsRecursive(elements, element.Name));
                        }
                        argsReferences.AddRange(newReferences);
                        argsReferences = argsReferences.Distinct(comparer).ToList();
                        function.cacheArgs[i].Add(argsReferences);
                    }
                }
            }
            foreach (var pluginFunctions in functions)
            {
                foreach (var func in pluginFunctions.Value)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        var funcAspect = func.Value[i];
                        if (string.IsNullOrEmpty(funcAspect))
                        {
                            continue;
                        }
                        var elements = CuiHelper.FromJson(funcAspect);
                    }
                }
            }
            onCuiGeneratorInitialized();
        }
예제 #5
0
        void AddShopPlayer(ulong userId)
        {
            if (!players.ContainsKey(userId))
            {
                players[userId] = new ShopPlayer()
                {
                    Points = 15, TotalOnlineSeconds = 0
                }
            }
            ;
        }

        #endregion

        #region UI

        void CreateItemsUI()
        {
            float gap       = 0.014f;
            float width     = 0.15f;
            float height    = 0.17f;
            float startxBox = gap;
            float startyBox = 1f - height - 0.05f;

            float xmin = startxBox;
            float ymin = startyBox;

            itemsUI = new CuiElementContainer();
            int i          = 0;
            var mainParent = itemsUI.Add(new CuiPanel()
            {
                Image = { Color = "0 0 0 0" }
            }, "rustyshop.items",
                                         "rustyshop.items.customui");

            foreach (var item in items)
            {
                var min       = $"{xmin} {ymin}";
                var max       = $"{xmin + width} {ymin + height}";
                var panelname = itemsUI.Add(new CuiPanel()
                {
                    Image         = { Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = min, AnchorMax = max }
                }, mainParent);


                itemsUI.Add(new CuiButton()
                {
                    Button        = { Command = $"rustyshop.buy {i}", Color = "0.3 0.5 0.4 1" },
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0.25" },
                    Text          =
                    {
                        Text     =
                            $"<color=orange><color=#00ccff>{item.Amount}</color> за <color=#ffcc00>{item.Cost}</color> р.</color>",
                        FontSize = 16,
                        Align    = TextAnchor.MiddleCenter
                    }
                }, panelname);

                itemsUI.Add(new CuiElement()
                {
                    Name       = CuiHelper.GetGuid(),
                    Parent     = panelname,
                    Components =
                    {
                        new CuiRawImageComponent()
                        {
                            Png    = ImageStorage.FetchPng(item.DisplayName),
                            Sprite = "assets/content/textures/generic/fulltransparent.tga"
                        },
                        new CuiRectTransformComponent()
                        {
                            AnchorMin = "0 0.25", AnchorMax = "1 1"
                        }
                    }
                });

                xmin += width + gap;
                if (xmin + width >= 1)
                {
                    xmin  = startxBox;
                    ymin -= height + gap;
                }
                i++;
            }
        }

        void DrawUI(BasePlayer player)
        {
            var shopPlayer = players[player.userID];

            foreach (var we in itemsUI)
            {
                CuiHelper.DestroyUi(player, we.Name);
            }
            core.DrawUIWithEx(player, "RustyShop", "menu", itemsUI, shopPlayer.Points,
                              core.TimeToString(shopPlayer.TotalOnlineSeconds));
        }

        void DestroyUI(BasePlayer player)
        {
            core.DestroyUI(player, "RustyShop", "menu");
        }

        IEnumerator LoadImages()
        {
            foreach (var item in items)
            {
                yield return(CommunityEntity.ServerInstance.StartCoroutine(ImageStorage.Store(item.DisplayName, item.URL)));
            }
            CreateItemsUI();
        }
예제 #6
0
        void drawWindow(BasePlayer player)
        {
            IOrderedEnumerable <KeyValuePair <ulong, PlayerData> > items = from pair in data orderby pair.Value.pvp.kills descending select pair;
            int    i      = 1;
            string topPvp = "   Убийства:\n\n";

            foreach (KeyValuePair <ulong, PlayerData> pair in items)
            {
                string name = pair.Value.name;
                if (name == null)
                {
                    name = "Неизвестный";
                }
                topPvp = topPvp + i.ToString() + ") " + name + " - " + pair.Value.pvp.kills.ToString() + "\n";
                i++;
                if (i > 5)
                {
                    break;
                }
            }

            items  = from pair in data orderby pair.Value.pvp.deaths descending select pair;
            i      = 1;
            topPvp = topPvp + "\n   Смерти:\n\n";
            foreach (KeyValuePair <ulong, PlayerData> pair in items)
            {
                string name = pair.Value.name;
                if (name == null)
                {
                    name = "Неизвестный";
                }
                topPvp = topPvp + i.ToString() + ") " + name + " - " + pair.Value.pvp.deaths.ToString() + "\n";
                i++;
                if (i > 5)
                {
                    break;
                }
            }

            items = from pair in data orderby pair.Value.pvp.duelWin descending select pair;
            i     = 1;

            /*topPvp = topPvp + "\n   Победы в дуэлях:\n\n";
             * foreach(KeyValuePair<ulong, PlayerData> pair in items)
             * {
             *  string name = pair.Value.name;
             *  if(name == null) name = "Неизвестный";
             *  topPvp = topPvp + i.ToString() + ") " + name + " - " + pair.Value.pvp.duelWin.ToString() + "\n";
             *  i++;
             *  if(i > 5) break;
             * }*/

            items = from pair in data orderby(pair.Value.gather.wood + pair.Value.gather.stone + pair.Value.gather.metalOre + pair.Value.gather.sulfurOre + pair.Value.gather.hqmetalOre) descending select pair;

            i = 1;
            string topPve = "* Добыча\n\n   Руками:\n\n";

            foreach (KeyValuePair <ulong, PlayerData> pair in items)
            {
                string name = pair.Value.name;
                if (name == null)
                {
                    name = "Неизвестный";
                }
                topPve = topPve + i.ToString() + ") " + name + " - " + (pair.Value.gather.wood + pair.Value.gather.stone + pair.Value.gather.metalOre + pair.Value.gather.sulfurOre +
                                                                        pair.Value.gather.hqmetalOre).ToString() + "\n";
                i++;
                if (i > 5)
                {
                    break;
                }
            }

            items = from pair in data
                    orderby(pair.Value.quarry.stone + pair.Value.quarry.metal + pair.Value.quarry.metalOre + pair.Value.quarry.sulfurOre +
                            pair.Value.quarry.hqmetal + pair.Value.quarry.hqmetalOre) descending
                    select pair;

            i      = 1;
            topPve = topPve + "\n   Карьер:\n\n";
            foreach (KeyValuePair <ulong, PlayerData> pair in items)
            {
                string name = pair.Value.name;
                if (name == null)
                {
                    name = "Неизвестный";
                }
                topPve = topPve + i.ToString() + ") " + name + " - " + (pair.Value.quarry.stone + pair.Value.quarry.metal + pair.Value.quarry.metalOre + pair.Value.quarry.sulfurOre +
                                                                        pair.Value.quarry.hqmetal + pair.Value.quarry.hqmetalOre).ToString() + "\n";
                i++;
                if (i > 5)
                {
                    break;
                }
            }

            items = from pair in data orderby pair.Value.minutes descending select pair;
            i     = 1;
            string topTime = "\n\n * Время на сервере:\n\n";

            foreach (KeyValuePair <ulong, PlayerData> pair in items)
            {
                string name = pair.Value.name;
                if (name == null)
                {
                    name = "Неизвестный";
                }
                topTime = topTime + i.ToString() + ") " + name + " - " + prettyTime(pair.Value.minutes) + "\n";
                i++;
                if (i > 5)
                {
                    break;
                }
            }



            string text = data[player.userID].name + "\n\n   * PvP\n   Убийств: " + data[player.userID].pvp.kills.ToString() + "\n   Смертей: " + data[player.userID].pvp.deaths.ToString() + "\n   Побед в дуэли: " + data[player.userID].pvp.duelWin.ToString() +
                          "\n\n   * Добыто руками (" + (data[player.userID].gather.wood + data[player.userID].gather.stone + data[player.userID].gather.sulfurOre +
                                                        data[player.userID].gather.metalOre + data[player.userID].gather.hqmetalOre).ToString() + ")\n   Дерево: " + data[player.userID].gather.wood.ToString() +
                          "\n   Камень: " + data[player.userID].gather.stone.ToString() + "\n   Железная руда: " + data[player.userID].gather.metalOre.ToString() + "\n   Серная руда: " + data[player.userID].gather.sulfurOre.ToString() +
                          "\n   Мет. выс. к-ва: " + data[player.userID].gather.hqmetalOre.ToString() + "\n\n   * Добыто карьером (" + (data[player.userID].quarry.stone + data[player.userID].quarry.metal + data[player.userID].quarry.metalOre +
                                                                                                                                       data[player.userID].quarry.sulfurOre + data[player.userID].quarry.hqmetal + data[player.userID].quarry.hqmetalOre).ToString() + ")\n   Камень: " + data[player.userID].quarry.stone.ToString() +
                          "\n   Железная руда: " + data[player.userID].quarry.metalOre.ToString() + "\n   Железо: " + data[player.userID].quarry.metal.ToString() + "\n   Серная руда: " +
                          data[player.userID].quarry.sulfurOre.ToString() + "\n   Мет. руда высок. к-ва: " + data[player.userID].quarry.hqmetalOre.ToString() +
                          "\n   Мет. высок. к-ва: " + data[player.userID].quarry.hqmetal.ToString() + "\n\n    " /*+"\n\n   * Подобрал с земли\n   Дерево: "+data[player.userID].pickup.wood.ToString()+"\n   Камень: "+
                                                                                                                  * data[player.userID].pickup.stone.ToString()+"\n   Железная руда: "+data[player.userID].pickup.metalOre+"\n   Серная руда: "+data[player.userID].pickup.sulfurOre+
                                                                                                                  * "\n   Ткань: "+data[player.userID].pickup.cloth*/;

            CuiHelper.DestroyUi(player, "StatsParent");
            startGui[player.userID] = CuiHelper.GetGuid();

            cui.createparentcurs("StatsParent", "0 0 0 0", "0.05 0.1", "0.95 0.95");

            cui.createimg("StatImg", "StatsParent", ImageStorage.FetchPng("stat"), "0 0", "1 1");

            cui.createtext("Text", "StatsParent", "", 24, "0.5 0.9", "0.8 0.99", TextAnchor.MiddleLeft);

            //cui.createbox("Box1", "StatsParent","0.3 0.6 0.3 0.5","0.02 0.05", "0.3 0.95");
            cui.createtext("StatsText", "StatsParent", "<color=#81feff>" + text + "</color>", 18, "0.06 0.1", "0.27 0.95", TextAnchor.MiddleLeft);

            //cui.createbox("Box2", "StatsParent","0.6 0.3 0.3 0.5","0.32 0.35", "0.61 0.88");
            cui.createtext("StatsTextTop", "StatsParent", "<color=#d24a43>" + topPvp + "</color>", 12, "0.36 0.36", "0.63 0.87", TextAnchor.MiddleLeft);

            //cui.createbox("Box3", "StatsParent","0.6 0.3 0.3 0.5","0.62 0.35", "0.99 0.88");
            cui.createtext("StatsTextTop", "StatsParent", "<color=#74b65f>" + topPve /*+topExp*/ + topTime + "</color>", 15, "0.6499 0.02", "0.9999 0.87", TextAnchor.MiddleLeft);

            //cui.createbox("Box4", "StatsParent","0.6 0.3 0.3 0.5","0.62 0.05", "0.99 0.34");
            //cui.createtext("StatsTextTop", "StatsParent", topExp, 18, "0.63 0.06", "0.98 0.33",TextAnchor.MiddleLeft);

            cui.createtext("StatsExitText", "StatsParent", "", 20, "0.32 0.18", "0.61 0.32", TextAnchor.MiddleCenter);
            cui.createbutton("StatsExitButton", "StatsParent", "drawTop", "StatsParent", "0 0 0 0", "0.32 0.18", "0.61 0.32");

            cui.createtext("StatsExitText", "StatsParent", "", 20, "0.32 0.05", "0.61 0.15", TextAnchor.MiddleCenter);
            cui.createbutton("StatsExitButton", "StatsParent", "", "StatsParent", "0 0 0 0", "0.32 0.05", "0.61 0.15");

            CuiHelper.AddUi(player, cui.elements);
            cui.elements.Clear();
        }