• File: BuildUPMEnu.cs
  • Full Path: /var/www/FileManager/Files/RUST PLUGINS/BuildUPMEnu.cs
  • Date Modified: 04/29/2025 6:35 PM
  • File size: 8.47 KB
  • MIME-type: text/plain
  • Charset: utf-8
 
Open Back
using System;
using System.Collections;
using System.Collections.Generic;
using Network;
using UnityEngine;
using Oxide.Core.Plugins;
using Facepunch;
using Newtonsoft.Json;
using System.Linq;
using Network;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Data;
using Oxide.Core;
using System.Xml.Linq;
using Rust;
using ConVar;
using Oxide.Game.Rust.Cui;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;

namespace Oxide.Plugins
{
    [Info("BuildUPMEnu", "Sopelka", "1.2.1")]
    class BuildUPMEnu : RustPlugin
    {
        public static string MENU_PARENT = "panelBuilding";
        [PluginReference] private Plugin ImageLibrary;
        private void OnServerInitialized()
        {
            ImageLibrary = plugins.Find("ImageLibrary");

            if (ImageLibrary == null)
            {
                PrintError("[ImageLibrary] not found! Plugin is disabled!");
                Interface.Oxide.UnloadPlugin(Title);
                return;
            }

            ImageLibrary.Call("AddImage", "https://imgur.com/aA8uqf7.png", MENU_PARENT + "aA8uqf7");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/ozzzrcy.png", MENU_PARENT + "ozzzrcy");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/seK0p7H.png", MENU_PARENT + "seK0p7H");
            ImageLibrary.Call("AddImage", "https://imgur.com/t8svBHz.png", MENU_PARENT + "t8svBHz");
            ImageLibrary.Call("AddImage", "https://i.imgur.com/yxnysku.png", MENU_PARENT + "yxnysku");
        }

        void OnActiveItemChanged(BasePlayer player, Item oldItem, Item newItem)
        {
            try
            {
                if (player == null && !player.IsConnected && player.health <= 0 && player.IsSleeping()) return;
                if (player.GetActiveItem() != null)
                {
                    if (player.GetActiveItem().info.shortname.Contains("planner"))
                    {
                        NextTick(delegate { ShowBuild(player, 0); });
                        return;
                    }
                }
                CuiHelper.DestroyUi(player, MENU_PARENT);
            }
            catch { }
        }

        private static void SoundEffect(BasePlayer player, string effect = null)
        {
            EffectNetwork.Send(new Effect(effect, player, 0, new Vector3(), new Vector3()), player.Connection);
        }

        string colotText = "#FFFFFFFF";
        bool isText = true;
        void ShowBuild(BasePlayer player, BuildingGrade.Enum Enum)
        {
            SoundEffect(player, "assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab");
            CuiElementContainer container = new CuiElementContainer();
            CuiHelper.DestroyUi(player, MENU_PARENT);

            container.Add(new CuiPanel
            {
                RectTransform = { AnchorMin = "0.406 0.108", AnchorMax = "0.450 0.108", OffsetMin = "312 -60", OffsetMax = "535 0" },
                Image = { Color = "0 0 0 0.7" }
            }, "Hud.Menu", MENU_PARENT);

            container.Add(new CuiElement
            {
                Parent = MENU_PARENT,
                Components =
                        {
                        new CuiRawImageComponent { Png = (string)ImageLibrary.Call("GetImage", MENU_PARENT +"aA8uqf7") },
                        new CuiRectTransformComponent{  AnchorMin = $"0.02 0.05", AnchorMax = $"0.20 0.95" },
                        }
            });

            if (isText) 
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = $"0.02 0.05", AnchorMax = $"0.20 0.95" },
                    Button = { Command = $"bgrade.up 1", Color = "0 0 0 0" },
                    //Text = { Text = "Wood", Color = HexToRustFormat(colotText), Align = TextAnchor.MiddleCenter }
                }, MENU_PARENT);
            }
            

            container.Add(new CuiElement
            {
                Parent = MENU_PARENT,
                Components =
                        {
                        new CuiRawImageComponent { Png = (string)ImageLibrary.Call("GetImage", MENU_PARENT +"ozzzrcy") },
                        new CuiRectTransformComponent{  AnchorMin = $"0.22 0.05", AnchorMax = $"0.40 0.95" },
                        }
            });

            if (isText) 
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = $"0.22 0.05", AnchorMax = $"0.40 0.95" },
                    Button = { Command = $"bgrade.up 2", Color = "0 0 0 0" },
                   // Text = { Text = "Stone", Color = HexToRustFormat(colotText), Align = TextAnchor.MiddleCenter }
                }, MENU_PARENT);
            }
            

            container.Add(new CuiElement
            {
                Parent = MENU_PARENT,
                Components =
                        {
                        new CuiRawImageComponent { Png = (string)ImageLibrary.Call("GetImage", MENU_PARENT +"seK0p7H") },
                        new CuiRectTransformComponent{  AnchorMin = $"0.42 0.05", AnchorMax = $"0.60 0.95" },
                        }
            });

            if (isText) 
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = $"0.42 0.05", AnchorMax = $"0.60 0.95" },
                    Button = { Command = $"bgrade.up 3", Color = "0 0 0 0" },
                   // Text = { Text = "Metal", Color = HexToRustFormat(colotText), Align = TextAnchor.MiddleCenter }
                }, MENU_PARENT);
            }
            

            container.Add(new CuiElement
            {
                Parent = MENU_PARENT,
                Components =
                        {
                        new CuiRawImageComponent { Png = (string)ImageLibrary.Call("GetImage", MENU_PARENT +"t8svBHz")},
                        new CuiRectTransformComponent{  AnchorMin = $"0.62 0.05", AnchorMax = $"0.77 0.95" },
                        }
            });

            if (isText) 
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = $"0.62 0.05", AnchorMax = $"0.77 0.95" },
                    Button = { Command = $"bgrade.up 4", Color = "0 0 0 0" },
                   // Text = { Text = "MVK", Color = HexToRustFormat(colotText), Align = TextAnchor.MiddleCenter }
                }, MENU_PARENT);
            }
            

            container.Add(new CuiElement
            {
                Parent = MENU_PARENT,
                Components =
                        {
                        new CuiRawImageComponent { Png = (string)ImageLibrary.Call("GetImage", MENU_PARENT +"yxnysku")},
                        new CuiRectTransformComponent{  AnchorMin = $"0.79 0.05", AnchorMax = $"0.97 0.95" },
                        }
            });

            if (isText) 
            {
                container.Add(new CuiButton
                {
                    RectTransform = { AnchorMin = $"0.79 0.05", AnchorMax = $"0.97 0.95" },
                    Button = { Command = $"UI_BuildingController open", Color = "0 0 0 0" },
                   // Text = { Text = "SKIN", Color = HexToRustFormat(colotText), Align = TextAnchor.MiddleCenter }
                }, MENU_PARENT);
            }
            

            CuiHelper.AddUi(player, container);
        }

        private static string HexToRustFormat(string hex)
        {
            if (string.IsNullOrEmpty(hex))
            {
                hex = "#FFFFFFFF";
            }

            var str = hex.Trim('#');

            if (str.Length == 6)
                str += "FF";

            if (str.Length != 8)
            {
                throw new Exception(hex);
                throw new InvalidOperationException("Cannot convert a wrong format.");
            }

            var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
            var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
            var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
            var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);

            UnityEngine.Color color = new Color32(r, g, b, a);

            return string.Format("{0:F2} {1:F2} {2:F2} {3:F2}", color.r, color.g, color.b, color.a);
        }
    }
}