Иконка ресурса

FREE AbsolutMarket : 1.8.4 1.8.4

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("AbsolutMarket", "Absolut", "1.8.4", ResourceId = 2118)]
    public class AbsolutMarket : RustPlugin
    {
        [PluginReference]
        private Plugin ServerRewards, Economics, ImageLibrary;

        private MarketData mData;
        private DynamicConfigFile MData;

        private string TitleColor = "<color=orange>";
        private string MsgColor = "<color=#A9A9A9>";
        private Vector3 eyesAdjust;
        private FieldInfo serverinput;

        private bool initialized;

        private List<ulong> MenuState = new List<ulong>();
        private Dictionary<string, Timer> timers = new Dictionary<string, Timer>();
        private Dictionary<ulong, List<AMItem>> PlayerBoxContents = new Dictionary<ulong, List<AMItem>>();
        private Dictionary<ulong, AMItem> SalesItemPrep = new Dictionary<ulong, AMItem>();
        private Dictionary<ulong, List<Item>> PlayerInventory = new Dictionary<ulong, List<Item>>();
        private Dictionary<ulong, List<Item>> ItemsToTransfer = new Dictionary<ulong, List<Item>>();
        private Dictionary<ulong, existence> UIInfo = new Dictionary<ulong, existence>();

        private class existence
        {
            public StorageContainer box = null;
            public int page;
            public Category cat = Category.All;
            public AMItem PurchaseItem = null;
        }

        #region Server Hooks

        private void Loaded()
        {
            MData = Interface.Oxide.DataFileSystem.GetFile("AbsolutMarket_Data");
            lang.RegisterMessages(messages, this);
        }

        private void Unload()
        {
            foreach (var entry in timers)
                entry.Value.Destroy();
            MenuState.Clear();
            timers.Clear();
            PlayerBoxContents.Clear();
            SalesItemPrep.Clear();
            foreach (BasePlayer p in BasePlayer.activePlayerList)
            {
                DestroyMarketPanel(p);
                DestroyPurchaseScreen(p);
            }
            if (initialized)
                SaveData();
        }

        private void OnPlayerDisconnected(BasePlayer player)
        {
            if (MenuState.Contains(player.userID))
                MenuState.Remove(player.userID);
            if (mData.TradeBox.ContainsKey(player.userID))
            {
                StorageContainer box = null;
                if (UIInfo.ContainsKey(player.userID))
                    box = UIInfo[player.userID].box;
                else GetTradeBox(player.userID);
                if (box == null)
                {
                    Dictionary<uint, string> listings = new Dictionary<uint, string>();
                    foreach (var entry in mData.MarketListings.Where(kvp => kvp.Value.seller == player.userID))
                        listings.Add(entry.Key, entry.Value.shortname);
                    foreach (var entry in listings)
                        RemoveListing(player.userID, entry.Value, entry.Key, "TradeBoxInvalid");
                    listings.Clear();
                    mData.TradeBox.Remove(player.userID);
                    GetSendMSG(player, "TradeBoxNoLongerValid");
                }
            }
            if (UIInfo.ContainsKey(player.userID))
                UIInfo.Remove(player.userID);
        }

        private void OnPlayerInit(BasePlayer player)
        {
            if (player != null)
            {
                //player.Command($"bind {configData.MarketMenuKeyBinding} \"UI_ToggleMarketScreen\"");
                GetSendMSG(player, "AMInfo", configData.MarketMenuKeyBinding);
                if (!mData.names.ContainsKey(player.userID))
                    mData.names.Add(player.userID, player.displayName);
                else
                {
                    var length = player.displayName.Count();
                    if (length > 30)
                    {
                        mData.names[player.userID] = player.displayName.Substring(0, 30);
                    }
                    else mData.names[player.userID] = player.displayName;
                }
                SendMessages(player);
                if (!UIInfo.ContainsKey(player.userID))
                    UIInfo.Add(player.userID, new existence());
                if (mData.TradeBox.ContainsKey(player.userID))
                {
                    UIInfo[player.userID].box = GetTradeBox(player.userID);
                    if (UIInfo[player.userID].box == null)
                    {
                        Dictionary<uint, string> listings = new Dictionary<uint, string>();
                        foreach (var entry in mData.MarketListings.Where(kvp => kvp.Value.seller == player.userID))
                            listings.Add(entry.Key, entry.Value.shortname);
                        foreach (var entry in listings)
                            RemoveListing(player.userID, entry.Value, entry.Key, "TradeBoxInvalid");
                        listings.Clear();
                        mData.TradeBox.Remove(player.userID);
                        GetSendMSG(player, "TradeBoxNoLongerValid");
                    }
                }
                SaveData();
            }
        }

        private void OnServerInitialized()
        {
            timer.Once(10, () =>
            {
                initialized = false;
                try
                {
                    ImageLibrary.Call("isLoaded", null);
                }
                catch (Exception)
                {
                    PrintWarning($"ImageLibrary is missing.Unloading {Name} as it will not work without ImageLibrary.");
                    Interface.Oxide.UnloadPlugin(Name);
                    return;
                }
                LoadVariables();
                if (configData.ServerRewards && configData.Economics)
                {
                    PrintWarning($"You can not have Economics and Server Rewards enabled.Disable one and reload.");
                    Interface.Oxide.UnloadPlugin(Name);
                    return;
                }
                if (configData.ServerRewards)
                    try
                    {
                        ServerRewards.Call("isLoaded", null);
                    }
                    catch (Exception)
                    {
                        PrintWarning($"ServerRewards is missing.Unloading {Name} as it will not work without ServerRewards or change the config option to false.");
                        Interface.Oxide.UnloadPlugin(Name);
                        return;
                    }
                if (configData.Economics)
                    try
                    {
                        Economics.Call("isLoaded", null);
                    }
                    catch (Exception)
                    {
                        PrintWarning($"Economics is missing.Unloading {Name} as it will not work without Economics or change the config option to false.");
                        Interface.Oxide.UnloadPlugin(Name);
                        return;
                    }
                permission.RegisterPermission("AbsolutMarket.admin", this);
                LoadData();
                eyesAdjust = new Vector3(0f, 1.5f, 0f);
                timers.Add("info", timer.Once(configData.InfoInterval, () => InfoLoop()));
                timers.Add("save", timer.Once(600, () => SaveLoop()));
                timers.Add("listings", timer.Once(600, () => CheckListings()));
                SaveData();
                AddNeededImages();
                RefreshBackgrounds();
                foreach (BasePlayer p in BasePlayer.activePlayerList)
                    OnPlayerInit(p);
            });
        }

        #endregion Server Hooks

        #region Player Hooks

        private void OnEntityDeath(BaseEntity entity, HitInfo hitInfo)
        {
            if (entity is StorageContainer)
            {
                if (mData.TradeBox.ContainsKey(entity.OwnerID))
                {
                    if (entity.transform.localPosition == GetVector3(mData.TradeBox[entity.OwnerID]))
                    {
                        Dictionary<uint, string> listings = new Dictionary<uint, string>();
                        foreach (var entry in mData.MarketListings.Where(kvp => kvp.Value.seller == entity.OwnerID))
                            listings.Add(entry.Key, entry.Value.shortname);
                        foreach (var entry in listings)
                            RemoveListing(entity.OwnerID, entry.Value, entry.Key, "TradeBoxDestroyed");
                        listings.Clear();
                        mData.TradeBox.Remove(entity.OwnerID);
                        if (UIInfo.ContainsKey(entity.OwnerID))
                            UIInfo[entity.OwnerID].box = null;
                        BasePlayer owner = BasePlayer.FindByID(entity.OwnerID);
                        if (BasePlayer.activePlayerList.Contains(owner))
                            GetSendMSG(owner, "TradeBoxDestroyed");
                    }
                    SaveData();
                }
                return;
            }
        }

        private object OnServerCommand(ConsoleSystem.Arg arg)
        {
            var player = arg.Connection?.player as BasePlayer;
            if (player == null || !SalesItemPrep.ContainsKey(player.userID)) return null;
            if (arg.Args != null && !string.IsNullOrEmpty(string.Join(" ", arg.Args)) && arg.cmd?.FullName == "chat.say")
            {
                AMItem item;
                item = SalesItemPrep[player.userID];
                var args = string.Join(" ", arg.Args);
                if (args.Contains("quit"))
                {
                    CancelListing(player);
                    return false;
                }
                switch (item.stepNum)
                {
                    case 0:
                        var name = string.Join(" ", arg.Args);
                        item.name = name;
                        item.stepNum = 99;
                        SellItems(player, 1);
                        return false;
                }
                return false;
            }
            return null;
        }

        #endregion Player Hooks

        #region Functions

        private StorageContainer GetTradeBox(ulong Buyer)
        {
            List<StorageContainer> Containers = new List<StorageContainer>();
            if (mData.TradeBox.ContainsKey(Buyer))
            {
                Vector3 containerPos = GetVector3(mData.TradeBox[Buyer]);
                foreach (StorageContainer Cont in StorageContainer.FindObjectsOfType<StorageContainer>())
                {
                    Vector3 ContPosition = Cont.transform.position;
                    if (ContPosition == containerPos)
                        return Cont;
                }
            }
            return null;
        }

        private Vector3 GetVector3(XYZ xyz)
        {
            return new Vector3 { x = xyz.x, y = xyz.y, z = xyz.z };
        }

        private bool GetTradeBoxContents(BasePlayer player, StorageContainer box)
        {
            if (player == null) return false;
            ulong seller = player.userID;
            bool EcoAllowed = false;
            if (Economics && configData.Economics && !mData.Blacklist.Contains("ECO")) EcoAllowed = true;
            bool SRAllowed = false;
            if (ServerRewards && configData.ServerRewards && !mData.Blacklist.Contains("SR")) SRAllowed = true;
            if (box != null)
            {
                if (GetItems(box.inventory).Count() == 0)
                {
                    if (!SRAllowed && !EcoAllowed)
                    {
                        GetSendMSG(player, "TradeBoxEmpty");
                        return false;
                    }
                    else
                    {
                        double amount = 0;
                        if (SRAllowed)
                            if (CheckPoints(player.userID) is int)
                                amount += (int)CheckPoints(player.userID);
                        if (EcoAllowed)
                            amount += CheckEco(player.userID);
                        if (amount == 0)
                        {
                            GetSendMSG(player, "TradeBoxEmptyNoSR");
                            return false;
                        }
                    }
                }
                if (PlayerBoxContents.ContainsKey(seller)) PlayerBoxContents.Remove(seller);
                PlayerBoxContents.Add(seller, new List<AMItem>());
                PlayerBoxContents[seller].AddRange(GetItems(box.inventory));
                var bl = 0;
                var c = 0;
                var listed = 0;
                foreach (var entry in PlayerBoxContents[seller])
                {
                    c++;
                    if (mData.Blacklist.Contains(entry.shortname))
                        bl++;
                    if (mData.MarketListings.ContainsKey(entry.ID))
                        listed++;
                    foreach (var cat in configData.Categorization.Where(k => k.Value.Contains(entry.shortname)))
                    {
                        entry.cat = cat.Key;
                        break;
                    }
                }
                if (bl == c)
                {
                    double amount = 0;
                    var msg = "";
                    if (SRAllowed)
                    {
                        msg = msg + GetMSG("SRInclusion", player);
                        if (CheckPoints(player.userID) is int)
                            amount += (int)CheckPoints(player.userID);
                    }
                    if (EcoAllowed)
                    {
                        msg = msg + GetMSG("ECOInclusion", player);
                        amount += CheckEco(player.userID);
                    }
                    if (amount <= 0)
                    {
                        GetSendMSG(player, "AllItemsAreBL", msg);
                        return false;
                    }
                }
                if (c == listed)
                {
                    bool alllisted = true;
                    var msg = "";
                    if (SRAllowed)
                    {
                        msg = msg + GetMSG("SRInclusionListed", player);
                        if (CheckPoints(player.userID) is int)
                        {
                            var total = (int)CheckPoints(player.userID);
                            var totalListed = 0;
                            foreach (var entry in mData.MarketListings.Where(kvp => kvp.Value.seller == player.userID && kvp.Value.shortname == "SR"))
                                totalListed += entry.Value.amount;
                            if (totalListed < total)
                                alllisted = false;
                        }
                    }
                    if (EcoAllowed && alllisted)
                    {
                        msg = msg + GetMSG("ECOInclusionListed", player);
                        var total = CheckEco(player.userID);
                        var totalListed = 0;
                        foreach (var entry in mData.MarketListings.Where(kvp => kvp.Value.seller == player.userID && kvp.Value.shortname == "ECO"))
                            totalListed += entry.Value.amount;
                        if (totalListed < total)
                            alllisted = false;
                    }
                    if (alllisted)
                    {
                        GetSendMSG(player, "AllItemsAreListed", msg);
                        return false;
                    }
                }
                return true;
            }
            else GetSendMSG(player, "NoTradeBox"); return false;
        }

        private bool BoxCheck(BasePlayer player, uint item)
        {
            if (player == null) return false;
            ulong seller = player.userID;
            StorageContainer box = UIInfo[player.userID].box;
            if (box != null)
            {
                if (GetItems(box.inventory).Count() == 0)
                {
                    GetSendMSG(player, "TradeBoxEmpty");
                    return false;
                }
                foreach (var entry in box.inventory.itemList)
                {
                    if (entry.uid == item)
                        return true;
                }
                return false;
            }
            else GetSendMSG(player, "NoTradeBox"); return false;
        }

        private void AddMessages(ulong player, string message, string arg1 = "", string arg2 = "", string arg3 = "", string arg4 = "")
        {
            try
            {
                BasePlayer Online = BasePlayer.FindByID(player);
                if (BasePlayer.activePlayerList.Contains(Online))
                    GetSendMSG(Online, message, arg1, arg2, arg3, arg4);
            }
            catch
            {
                if (!mData.OutstandingMessages.ContainsKey(player))
                    mData.OutstandingMessages.Add(player, new List<Unsent>());
                mData.OutstandingMessages[player].Add(new Unsent { message = message, arg1 = arg1, arg2 = arg2, arg3 = arg3, arg4 = arg4 });
                SaveData();
            }
        }

        private void SendMessages(BasePlayer player)
        {
            if (mData.OutstandingMessages.ContainsKey(player.userID))
            {
                foreach (var entry in mData.OutstandingMessages[player.userID])
                {
                    GetSendMSG(player, entry.message, entry.arg1, entry.arg2, entry.arg3, entry.arg4);
                }
                mData.OutstandingMessages.Remove(player.userID);
            }
        }

        private string TryForImage(string shortname, ulong skin = 99)
        {
            if (shortname.Contains("http")) return shortname;
            if (skin == 99) skin = (ulong)ResourceId;
            return GetImage(shortname, skin, true);
        }

        public string GetImage(string shortname, ulong skin = 0, bool returnUrl = false) => (string)ImageLibrary.Call("GetImage", shortname.ToLower(), skin, returnUrl);
        public bool HasImage(string shortname, ulong skin = 0) => (bool)ImageLibrary.Call("HasImage", shortname.ToLower(), skin);
        public bool AddImage(string url, string shortname, ulong skin = 0) => (bool)ImageLibrary?.Call("AddImage", url, shortname.ToLower(), skin);
        public List<ulong> GetImageList(string shortname) => (List<ulong>)ImageLibrary.Call("GetImageList", shortname.ToLower());
        public bool isReady() => (bool)ImageLibrary?.Call("IsReady");

        private IEnumerable<AMItem> GetItems(ItemContainer container)
        {
            return container.itemList.Select(item => new AMItem
            {
                amount = item.amount,
                skin = item.skin,
                cat = Category.Other,
                pricecat = Category.Other,
                shortname = item.info.shortname,
                condition = item.condition,
                ID = item.uid,
            });
        }

        private IEnumerable<Item> GetItemsOnly(ItemContainer container)
        {
            return container.itemList;
        }

        //private void XferPurchase(ulong buyer, uint ID, ItemContainer from, ItemContainer to)
        //{
        //    foreach (Item item in from.itemList.Where(kvp => kvp.uid == ID))
        //    {
        //        item.MoveToContainer(to);
        //    }
        //}

        private void XferCost(uint item, BasePlayer player, uint Listing, ItemContainer SellerBox)
        {
            List<ItemContainer> containers = new List<ItemContainer> { player.inventory.containerMain, player.inventory.containerBelt, player.inventory.containerWear };
            if (mData.MarketListings[Listing].priceAmount > 0)
            {
                //Puts("TRying");
                foreach (var container in containers)
                    foreach (Item item1 in container.itemList.Where(k => k.uid == item))
                    {
                        //Puts("Item found)");
                        if (mData.MarketListings[Listing].priceAmount == 0) return;
                        if (mData.MarketListings[Listing].priceAmount >= item1.amount)
                        {
                            //Puts("1");
                            item1.MoveToContainer(SellerBox);
                            mData.MarketListings[Listing].priceAmount -= item1.amount;
                            //Puts($"{item1} moved...price amount: {mData.MarketListings[Listing].priceAmount} item amount:{item1.amount}");
                        }
                        else
                        {
                            Item item2 = item1.SplitItem(mData.MarketListings[Listing].priceAmount);
                            item2.MoveToContainer(SellerBox);
                            mData.MarketListings[Listing].priceAmount = 0;
                            return;
                            //Puts($"SPLITTING: {item2} moved...price amount: {mData.MarketListings[Listing].priceAmount} item amount:{item2.amount}");
                        }
                        break;
                    }
            }
        }

        private Item BuildCostItems(string shortname, int amount)
        {
            var definition = ItemManager.FindItemDefinition(shortname);
            if (definition != null)
            {
                var item1 = ItemManager.Create(definition, amount, 0);
                if (item1 != null)
                    return item1;
            }
            Puts("Error making purchase cost item(s)");
            return null;
        }

        private void OnItemRemovedFromContainer(ItemContainer cont, Item item)
        {
            if (mData.MarketListings == null || mData.MarketListings.Count < 1) return;
            if (mData.TradeBox == null || mData.TradeBox.Count < 1) return;
            if (cont.entityOwner != null)
                if (mData.TradeBox.ContainsKey(cont.entityOwner.OwnerID) && cont.entityOwner.transform.localPosition == GetVector3(mData.TradeBox[cont.entityOwner.OwnerID]))
                    if (mData.MarketListings.ContainsKey(item.uid))
                    {
                        var name = "";
                        if (configData.UseUniqueNames && item.name != "")
                            name = mData.MarketListings[item.uid].name;
                        else name = mData.MarketListings[item.uid].shortname;
                        RemoveListing(cont.entityOwner.OwnerID, name, item.uid, "FromBox");
                        mData.MarketListings.Remove(item.uid);
                    }
        }

        private void RemoveListing(ulong seller, string name, uint ID, string reason = "")
        {
            AddMessages(seller, "ItemRemoved", name.ToUpper(), reason);
            mData.MarketListings.Remove(ID);
        }

        private void CancelListing(BasePlayer player)
        {
            DestroyMarketPanel(player);
            if (SalesItemPrep.ContainsKey(player.userID))
                SalesItemPrep.Remove(player.userID);
            if (PlayerBoxContents.ContainsKey(player.userID))
                PlayerBoxContents.Remove(player.userID);
            GetSendMSG(player, "ItemListingCanceled");
        }

        private void SRAction(ulong ID, int amount, string action)
        {
            if (action == "ADD")
                ServerRewards?.Call("AddPoints", new object[] { ID, amount });
            if (action == "REMOVE")
                ServerRewards?.Call("TakePoints", new object[] { ID, amount });
        }

        private object CheckPoints(ulong ID) => ServerRewards?.Call("CheckPoints", ID);

        private void ECOAction(ulong ID, int amount, string action)
        {
            if (action == "ADD")
                Economics.Call("Deposit", ID, amount);
            if (action == "REMOVE")
                Economics.Call("Withdraw", ID, amount);
        }

        private double CheckEco(ulong ID) => (double)Economics.Call("Balance", ID);

        private void NumberPad(BasePlayer player, string cmd)
        {
            CuiHelper.DestroyUi(player, PanelMarket);
            var element = UI.CreateElementContainer(PanelMarket, UIColors["dark"], "0.35 0.3", "0.65 0.7", true);
            UI.CreatePanel(ref element, PanelMarket, UIColors["light"], "0.01 0.02", "0.99 0.98");
            UI.CreateLabel(ref element, PanelMarket, UIColors["white"], GetMSG("Select Amount", player), 20, "0.1 0.85", "0.9.98", TextAnchor.UpperCenter);
            var n = 1;
            var i = 0;
            while (n < 10)
            {
                CreateNumberPadButton(ref element, PanelMarket, i, n, cmd); i++; n++;
            }
            while (n >= 10 && n < 25)
            {
                CreateNumberPadButton(ref element, PanelMarket, i, n, cmd); i++; n += 5;
            }
            while (n >= 25 && n < 200)
            {
                CreateNumberPadButton(ref element, PanelMarket, i, n, cmd); i++; n += 25;
            }
            while (n >= 200 && n <= 950)
            {
                CreateNumberPadButton(ref element, PanelMarket, i, n, cmd); i++; n += 50;
            }
            while (n >= 1000 && n <= 10000)
            {
                CreateNumberPadButton(ref element, PanelMarket, i, n, cmd); i++; n += 500;
            }
            UI.CreateButton(ref element, PanelMarket, UIColors["buttonred"], GetMSG("Quit", player), 10, "0.03 0.02", "0.13 0.075", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), Category.All)}");
            CuiHelper.AddUi(player, element);
        }

        private void CreateNumberPadButton(ref CuiElementContainer container, string panelName, int i, int number, string command)
        {
            var pos = CalcNumButtonPos(i);
            UI.CreateButton(ref container, panelName, UIColors["buttonbg"], number.ToString(), 12, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"{command} {number}");
        }

        private void GetSendMSG(BasePlayer player, string message, string arg1 = "", string arg2 = "", string arg3 = "", string arg4 = "")
        {
            string msg = string.Format(lang.GetMessage(message, this, player.UserIDString), arg1, arg2, arg3, arg4);
            SendReply(player, TitleColor + lang.GetMessage("title", this, player.UserIDString) + "</color>" + MsgColor + msg + "</color>");
        }

        private string GetMSG(string message, BasePlayer player = null, string arg1 = "", string arg2 = "", string arg3 = "", string arg4 = "")
        {
            string p = null;
            if (player != null)
                p = player.UserIDString;
            if (messages.ContainsKey(message))
                return string.Format(lang.GetMessage(message, this, p), arg1, arg2, arg3, arg4);
            else return message;
        }

        public void DestroyMarketPanel(BasePlayer player)
        {
            if (MenuState.Contains(player.userID))
                MenuState.Remove(player.userID);
            CuiHelper.DestroyUi(player, PanelMarket);
        }

        public void DestroyPurchaseScreen(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, PanelPurchase);
        }

        private void ToggleMarketScreen(BasePlayer player)
        {
            if (configData.BanSteamIDs != null && configData.BanSteamIDs.Contains(player.userID))
            {
                OnScreen(player, "BanFromMarket");
                return;
            }
            if (MenuState.Contains(player.userID))
            {
                MenuState.Remove(player.userID);
                DestroyMarketPanel(player);
                DestroyPurchaseScreen(player);
                return;
            }
            MenuState.Add(player.userID);
            MarketMainScreen(player, 0, Category.All);
        }

        private bool isAuth(BasePlayer player)
        {
            if (player.net.connection != null)
                if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.UserIDString, "AbsolutMarket.admin"))
                    return false;
            return true;
        }

        #endregion Functions

        #region UI Creation

        private string PanelMarket = "PanelMarket";
        private string PanelPurchase = "PanelPurchase";
        private string PanelOnScreen = "PanelOnScreen";

        public class UI
        {
            static public CuiElementContainer CreateElementContainer(string panel, string color, string aMin, string aMax, bool cursor = false)
            {
                var NewElement = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        Image = {Color = color},
                        RectTransform = {AnchorMin = aMin, AnchorMax = aMax},
                        CursorEnabled = cursor
                    },
                    new CuiElement().Parent,
                    panel
                }
            };
                return NewElement;
            }
            static public CuiElementContainer CreateOverlayContainer(string panelName, string color, string aMin, string aMax, bool cursor = false)
            {
                var NewElement = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        Image = {Color = color},
                        RectTransform = {AnchorMin = aMin, AnchorMax = aMax},
                        CursorEnabled = cursor
                    },
                    new CuiElement().Parent = "Overlay",
                    panelName
                }
            };
                return NewElement;
            }
            static public void CreatePanel(ref CuiElementContainer element, string panel, string color, string aMin, string aMax, bool cursor = false)
            {
                element.Add(new CuiPanel
                {
                    Image = { Color = color },
                    RectTransform = { AnchorMin = aMin, AnchorMax = aMax },
                    CursorEnabled = cursor
                },
                panel);
            }
            static public void CreateLabel(ref CuiElementContainer element, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter)
            {
                element.Add(new CuiLabel
                {
                    Text = { Color = color, FontSize = size, Align = align, FadeIn = 1.0f, Text = text },
                    RectTransform = { AnchorMin = aMin, AnchorMax = aMax }
                },
                panel);
            }

            static public void CreateButton(ref CuiElementContainer element, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter)
            {
                element.Add(new CuiButton
                {
                    Button = { Color = color, Command = command, FadeIn = 1.0f },
                    RectTransform = { AnchorMin = aMin, AnchorMax = aMax },
                    Text = { Text = text, FontSize = size, Align = align }
                },
                panel);
            }

            static public void LoadImage(ref CuiElementContainer container, string panel, string img, string aMin, string aMax)
            {
                if (img.StartsWith("http") || img.StartsWith("www"))
                {
                    container.Add(new CuiElement
                    {
                        Parent = panel,
                        Components =
                    {
                        new CuiRawImageComponent {Url = img, Sprite = "assets/content/textures/generic/fulltransparent.tga" },
                        new CuiRectTransformComponent {AnchorMin = aMin, AnchorMax = aMax }
                    }
                    });
                }
                else
                    container.Add(new CuiElement
                    {
                        Parent = panel,
                        Components =
                    {
                        new CuiRawImageComponent {Png = img, Sprite = "assets/content/textures/generic/fulltransparent.tga" },
                        new CuiRectTransformComponent {AnchorMin = aMin, AnchorMax = aMax }
                    }
                    });
            }

            static public void CreateTextOverlay(ref CuiElementContainer element, string panel, string text, string color, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
            {
                //if (configdata.DisableUI_FadeIn)
                //    fadein = 0;
                element.Add(new CuiLabel
                {
                    Text = { Color = color, FontSize = size, Align = align, FadeIn = fadein, Text = text },
                    RectTransform = { AnchorMin = aMin, AnchorMax = aMax }
                },
                panel);
            }
            static public void CreateTextOutline(ref CuiElementContainer element, string panel, string colorText, string colorOutline, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter)
            {
                element.Add(new CuiElement
                {
                    Parent = panel,
                    Components =
                    {
                        new CuiTextComponent{Color = colorText, FontSize = size, Align = align, Text = text },
                        new CuiOutlineComponent {Distance = "1 1", Color = colorOutline},
                        new CuiRectTransformComponent {AnchorMax = aMax, AnchorMin = aMin }
                    }
                });
            }
        }

        private Dictionary<string, string> UIColors = new Dictionary<string, string>
        {
            {"black", "0 0 0 1.0" },
            {"dark", "0.1 0.1 0.1 0.98" },
            {"header", "1 1 1 0.3" },
            {"light", ".564.564.564 1.0" },
            {"grey1", "0.6 0.6 0.6 1.0" },
            {"brown", "0.3 0.16 0.0 1.0" },
            {"yellow", "0.9 0.9 0.0 1.0" },
            {"orange", "1.0 0.65 0.0 1.0" },
            {"blue", "0.2 0.6 1.0 1.0" },
            {"red", "1.0 0.1 0.1 1.0" },
            {"white", "1 1 1 1" },
            {"green", "0.28 0.82 0.28 1.0" },
            {"grey", "0.85 0.85 0.85 1.0" },
            {"lightblue", "0.6 0.86 1.0 1.0" },
            {"buttonbg", "0.2 0.2 0.2 0.7" },
            {"buttongreen", "0.133 0.965 0.133 0.9" },
            {"buttonred", "0.964 0.133 0.133 0.9" },
            {"buttongrey", "0.8 0.8 0.8 0.9" },
            {"CSorange", "1.0 0.64 0.10 1.0" }
        };

        #endregion UI Creation

        #region UI Panels

        private void MarketMainScreen(BasePlayer player, int page = 0, Category cat = Category.All)
        {
            CuiHelper.DestroyUi(player, PanelMarket);
            if (!mData.mode.ContainsKey(player.userID))
                mData.mode.Add(player.userID, false);
            var i = 0;
            var c = 0;
            bool seller = false;
            double count = 0;
            string Background = TryForImage("NEVERDELETE");
            if (cat == Category.All)
                count = mData.MarketListings.Count();
            else count = mData.MarketListings.Where(kvp => kvp.Value.cat == cat).Count();
            var element = UI.CreateElementContainer(PanelMarket, "0 0 0 0", "0.2 0.15", "0.8 0.85", true);
            UI.CreatePanel(ref element, PanelMarket, "0 0 0 0", "0 0", "1 1");
            int entriesallowed = 9;
            double remainingentries = count - (page * (entriesallowed - 1));
            double totalpages = (Math.Floor(count / (entriesallowed - 1)));
            if (mData.mode[player.userID] == false && !configData.ForceSimpleUI)
            {
                if (mData.background.ContainsKey(player.userID))
                    Background = TryForImage(mData.background[player.userID]);
                UI.LoadImage(ref element, PanelMarket, Background, "0 0", "1 1");
                if (page <= totalpages - 1)
                {
                    UI.LoadImage(ref element, PanelMarket, TryForImage("LAST"), "0.8 0.02", "0.85 0.06");
                    UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 18, "0.8 0.02", "0.85 0.06", $"UI_MarketMainScreen {totalpages} {Enum.GetName(typeof(Category), cat)}");
                }
                if (remainingentries > entriesallowed)
                {
                    UI.LoadImage(ref element, PanelMarket, TryForImage("NEXT"), "0.8 0.065", "0.85 0.105");
                    UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 18, "0.8 0.065", "0.85 0.105", $"UI_MarketMainScreen {page + 1} {Enum.GetName(typeof(Category), cat)}");
                }
                if (page > 0)
                {
                    UI.LoadImage(ref element, PanelMarket, TryForImage("BACK"), "0.74 0.065", "0.79 0.105");
                    UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 18, "0.74 0.065", "0.79 0.105", $"UI_MarketMainScreen {page - 1} {Enum.GetName(typeof(Category), cat)}");
                }
                if (page > 1)
                {
                    UI.LoadImage(ref element, PanelMarket, TryForImage("FIRST"), "0.74 0.02", "0.79 0.06");
                    UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 18, "0.74 0.02", "0.79 0.06", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), cat)}");
                }

                //UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], GetMSG("Filters"), 22, "0.14 0.08", "0.24 0.14");
                foreach (Category ct in Enum.GetValues(typeof(Category)))
                {
                    var loc = FilterButton(c);
                    if (cat == ct)
                    {
                        UI.LoadImage(ref element, PanelMarket, TryForImage("UFILTER"), $"{loc[0]} {loc[1]}", $"{loc[2]} {loc[3]}");
                        UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], Enum.GetName(typeof(Category), ct), 12, $"{loc[0]} {loc[1]}", $"{loc[2]} {loc[3]}", TextAnchor.MiddleCenter);
                        UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 12, $"{loc[0]} {loc[1]}", $"{loc[2]} {loc[3]}", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), ct)}");
                        c++;
                    }
                    else
                    {
                        UI.LoadImage(ref element, PanelMarket, TryForImage("OFILTER"), $"{loc[0]} {loc[1]}", $"{loc[2]} {loc[3]}");
                        UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], Enum.GetName(typeof(Category), ct), 12, $"{loc[0]} {loc[1]}", $"{loc[2]} {loc[3]}", TextAnchor.MiddleCenter);
                        UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 12, $"{loc[0]} {loc[1]}", $"{loc[2]} {loc[3]}", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), ct)}");
                        c++;
                    }
                }
                UI.LoadImage(ref element, PanelMarket, TryForImage("box.wooden.large", 0), $"0.05 0.9", "0.15 1");
                UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], "", 12, $"0.05 0.9", "0.15 1", TextAnchor.MiddleCenter);

                UI.CreateButton(ref element, PanelMarket, "0 0 0 0", GetMSG("TradeBoxAssignment", player), 12, $"0.05 0.9", "0.15 1", $"UI_SetTradeBox");

                UI.LoadImage(ref element, PanelMarket, TryForImage("SELL"), $"0.35 0.9", "0.65 1.0");
                UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], GetMSG("ListItem", player), 12, $"0.35 0.9", "0.65 1.0", TextAnchor.MiddleCenter);
                UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 12, $"0.35 0.9", "0.65 1.0", $"UI_MarketSellScreen {0}");

                UI.LoadImage(ref element, PanelMarket, TryForImage("OFILTER"), "0.66 0.9", "0.75 1");
                UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], GetMSG("ChangeMode", player), 12, "0.66 0.9", "0.75 1", TextAnchor.MiddleCenter);
                UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 12, "0.66 0.9", "0.75 1", $"UI_Mode {1}");

                UI.LoadImage(ref element, PanelMarket, TryForImage("OFILTER"), "0.76 0.9", "0.86 1");
                UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], GetMSG("ChangeTheme", player), 12, "0.76 0.9", "0.86 1", TextAnchor.MiddleCenter);
                UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 12, "0.76 0.9", "0.86 1", $"UI_MarketBackgroundMenu {0}");

                if (isAuth(player))
                {
                    UI.LoadImage(ref element, PanelMarket, TryForImage("UFILTER"), "0.87 0.9", "0.97 1");
                    UI.CreateLabel(ref element, PanelMarket, UIColors["dark"], GetMSG("AdminPanel", player), 12, "0.87 0.9", "0.97 1", TextAnchor.MiddleCenter);
                    UI.CreateButton(ref element, PanelMarket, "0 0 0 0", "", 12, "0.87 0.9", "0.97 1", $"UI_AdminPanel");
                }
                int shownentries = page * entriesallowed;
                int n = 0;
                if (cat == Category.All)
                {
                    foreach (var item in mData.MarketListings)
                    {
                        seller = false;
                        i++;
                        if (i < shownentries + 1) continue;
                        else if (i <= shownentries + entriesallowed)
                        {
                            if (item.Value.seller == player.userID)
                            {
                                seller = true;
                            }
                            CreateMarketListingButton(ref element, PanelMarket, player, item.Value, seller, n);

                            n++;
                        }
                    }
                }
                else
                    foreach (var item in mData.MarketListings.Where(kvp => kvp.Value.cat == cat))
                    {
                        seller = false;
                        i++;
                        if (i < shownentries + 1) continue;
                        else if (i <= shownentries + entriesallowed)
                        {
                            if (item.Value.seller == player.userID)
                            {
                                seller = true;
                            }
                            CreateMarketListingButton(ref element, PanelMarket, player, item.Value, seller, n);
                            n++;
                        }
                    }
            }
            else
            {
                UI.CreatePanel(ref element, PanelMarket, UIColors["dark"], "0.0", "1 1");
                if (page <= totalpages - 1)
                {
                    UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("Last", player), 12, "0.8 0.02", "0.85 0.06", $"UI_MarketMainScreen {totalpages} {Enum.GetName(typeof(Category), cat)}");
                }
                if (remainingentries > entriesallowed)
                {
                    UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("Next", player), 12, "0.8 0.065", "0.85 0.105", $"UI_MarketMainScreen {page + 1} {Enum.GetName(typeof(Category), cat)}");
                }
                if (page > 0)
                {
                    UI.CreateButton(ref element, PanelMarket, UIColors["red"], GetMSG("Back", player), 12, "0.74 0.065", "0.79 0.105", $"UI_MarketMainScreen {page - 1} {Enum.GetName(typeof(Category), cat)}");
                }
                if (page > 1)
                {
                    UI.CreateButton(ref element, PanelMarket, UIColors["red"], GetMSG("First", player), 12, "0.74 0.02", "0.79 0.06", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), cat)}");
                }

                foreach (Category ct in Enum.GetValues(typeof(Category)))
                {
                    var loc = FilterButton(c);
                    if (cat == ct)
                    {
                        UI.CreateButton(ref element, PanelMarket, UIColors["red"], Enum.GetName(typeof(Category), ct), 12, $"{loc[0]} {loc[1] +.02f}", $"{loc[2]} {loc[3] +.02f}", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), ct)}");
                        c++;
                    }
                    else
                    {
                        UI.CreateButton(ref element, PanelMarket, UIColors["header"], Enum.GetName(typeof(Category), ct), 12, $"{loc[0]} {loc[1] +.02f}", $"{loc[2]} {loc[3] +.02f}", $"UI_MarketMainScreen {0} {Enum.GetName(typeof(Category), ct)}");
                        c++;
                    }
                }
                UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("TradeBoxAssignment", player), 12, $"0.05 0.92", "0.15.98", $"UI_SetTradeBox");

                UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("ListItem", player), 12, $"0.35 0.92", "0.65.98", $"UI_MarketSellScreen {0}");

                if (!configData.ForceSimpleUI)
                {
                    UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("ChangeMode", player), 12, "0.66 0.92", "0.75.98", $"UI_Mode {0}");
                    UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("ChangeTheme", player), 12, "0.76 0.92", "0.86.98", $"UI_MarketBackgroundMenu {0}");
                }
                if (isAuth(player))
                {
                    UI.CreateButton(ref element, PanelMarket, UIColors["header"], GetMSG("AdminPanel", player), 12, "0.87 0.92", "0.97.98", $"UI_AdminPanel");
                }
                int shownentries = page * entriesallowed;
                int n = 0;
                if (cat == Category.All)
                {
                    foreach (var item in mData.MarketListings)
                    {
                        seller = false;
                        i++;
                        if (i < shownentries + 1) continue;
                        else if (i <= shownentries + entriesallowed)
                        {
                            if (item.Value.seller == player.userID)
                            {
                                seller = true;
                            }
                            CreateMarketListingButtonSimple(ref element, PanelMarket, player, item.Value, seller, n);
                            n++;
                        }
                    }
                }
                else
                    foreach (var item in mData.MarketListings.Where(kvp => kvp.Value.cat == cat))
                    {
                        seller = false;
                        i++;
                        if (i < shownentries + 1) continue;
                        else if (i <= shownentries + entriesallowed)
                        {
                            if (item.Value.seller == player.userID)
                            {
                                seller = true;
                            }
                            CreateMarketListingButtonSimple(ref element, PanelMarket, player, item.Value, seller, n);
                            n++;
                        }
                    }
            }
            UI.CreateButton(ref element, PanelMarket, UIColors["buttonred"], GetMSG("Close", player), 16, "0.87 0.02", "0.97 0.075", $
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху