C#:
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using System.Collections.Generic;
using Oxide.Core.Plugins;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("UI Logotip", "WOLF#4002", "0.0.1")]
public class WLogo : RustPlugin
{
private class Configuration
{
public int TIME;
public string LOGO;
public static Configuration Generate()
{
return new Configuration
{
TIME = 5,
LOGO = "https://cdn.discordapp.com/attachments/1099794069288403014/1111014133807190016/image.png",
};
}
}
private static Configuration Settings;
protected override void LoadConfig()
{
base.LoadConfig();
try
{
Settings = Config.ReadObject<Configuration>();
}
catch
{
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
protected override void SaveConfig() => Config.WriteObject(Settings);
[PluginReference] Plugin ImageLibrary;
private void OnServerInitialized()
{
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/online.png", "line");
ImageLibrary.Call("AddImage", Settings.LOGO, "logo");
BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
timer.Every(Settings.TIME, () =>
{
BasePlayer.activePlayerList.ToList().ForEach(RefreshOnlineData);
});
}
private void OnPlayerConnected(BasePlayer player)
{
LOGO(player);
}
private void OnPlayerDisconnected(BasePlayer player)
{
CuiHelper.DestroyUi(player, Logo);
CuiHelper.DestroyUi(player, "on");
}
private void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, Logo);
CuiHelper.DestroyUi(player, "on");
}
}
private static string Logo = "UI_Logo";
void LOGO(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, Logo);
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0 0.92", AnchorMax = "0.1 1", OffsetMax = "0 0" },
Image = { Color = "0.25 0.50 0.50 0" },
}, "Hud", Logo);
container.Add(new CuiElement
{
Parent = Logo,
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "logo"), Color = "0 0 0 0.3"},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = "1 1" },
}
});
container.Add(new CuiButton
{
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
Button = { Command = "chat.say /menu", Color = "1.00 0.00 0.00 0" },
Text = { Text = "", FontSize = 50, Align = TextAnchor.MiddleCenter }
}, Logo);
CuiHelper.AddUi(player, container);
}
private void RefreshOnlineData(BasePlayer player)
{
var text = GetLang("Online", player.UserIDString, covalence.Server.Time.ToShortTimeString(), BasePlayer.activePlayerList.ToList().Count);
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, "on");
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.838 0", AnchorMax = "0.9875 0.02"},
Image = { Color = "1.00 0.50 0.50 0" },
}, "Overlay", "on");
container.Add(new CuiElement
{
Parent = "on",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "line")},
new CuiRectTransformComponent{ AnchorMin = "0 0", AnchorMax = "1 1" },
}
});
container.Add(new CuiElement
{
Parent = "on",
Components =
{
new CuiTextComponent {Text = text, Align = TextAnchor.MiddleCenter, FontSize = 10},
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
}
});
CuiHelper.AddUi(player, container);
}
private new void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Online"] = "<color=#B0F394FF>Time:</color> {0} || <color=#B0F394FF>Players online:</color> {1}",
}, this, "eu");
lang.RegisterMessages(new Dictionary<string, string>
{
["Online"] = "<color=#B0F394FF>Время:</color> {0} || <color=#B0F394FF>Игроков онлайн:</color> {1}",
}, this, "ru");
lang.RegisterMessages(new Dictionary<string, string>
{
["Online"] = "<color=#B0F394FF>Час:</color> {0} || <color=#B0F394FF>Гравців онлайн:</color> {1}",
}, this, "uk");
PrintWarning("\nМовний файл завантажено успішно\nЯзыковой файл загружен успешно\nLanguage file uploaded successfully");
}
public static StringBuilder sb = new StringBuilder();
public string GetLang(string LangKey, string userID = null, params object[] args)
{
sb.Clear();
if (args != null)
{
sb.AppendFormat(lang.GetMessage(LangKey, this, userID), args);
return sb.ToString();
}
return lang.GetMessage(LangKey, this, userID);
}
}
}