C#:
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using Oxide.Core;
using System;
using Newtonsoft.Json;
using System.Linq;
namespace Oxide.Plugins
{
[Info("MBCraft", "Barry_Allenn", "1.0.0")]
[Description("Простой календарь с пустым интерфейсом")]
public class MBCraft : RustPlugin
{
[PluginReference] private Plugin ImageLibrary, MBMainMenu;
private ImageUI imageUI = new ImageUI();
private readonly HashSet<ulong> openedPlayers = new();
private readonly Dictionary<ulong, int> craftAmounts = new();
private ConfigData configData;
#region Config
private class ConfigData
{
[JsonProperty("Предмети для крафту")]
public List<ItemEntry> Items = new();
}
public class ItemEntry
{
public string DisplayName;
public string Description;
public string ShortName;
public int WorkbenchLevel = 0; // 0 — не потрібен верстак, 1-3 — відповідні рівні
public Dictionary<string, int> Materials = new();
}
protected override void LoadConfig()
{
base.LoadConfig();
configData = Config.ReadObject<ConfigData>();
SaveConfig();
}
protected override void SaveConfig()
{
Config.WriteObject(configData, true);
}
protected override void LoadDefaultConfig()
{
configData = new ConfigData
{
Items = new List<ItemEntry>
{
new ItemEntry
{
DisplayName = "Бамбукова бочка",
Description = "Зберігайте свої речі в цій бамбуковій бочці.Вміщує до 48 предметів.Не можна замикати.",
ShortName = "bamboo.barrel",
WorkbenchLevel = 0,
Materials = new Dictionary<string, int>
{
{ "wood", 300 },
{ "metal.fragments", 75 }
}
},
new ItemEntry
{
DisplayName = "Різдвяні вогні",
Description = "Низка кольорових вогників для прикраси вашого дому",
ShortName = "xmas.lightstring",
WorkbenchLevel = 0,
Materials = new Dictionary<string, int>
{
{ "lowgradefuel", 20 },
{ "metal.fragments", 25 },
}
}
}
};
SaveConfig();
}
#endregion
[ChatCommand("craft")]
private void CmdCraft(BasePlayer player, string command, string[] args)
{
ShowCraftUI(player);
}
void Init()
{
LoadConfig();
// imageUI = new ImageUI();
// imageUI.DownloadImages();
}
private void OnServerInitialized()
{
imageUI = new ImageUI();
imageUI.DownloadImages();
}
void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, "MBCraft_UI");
}
openedPlayers.Clear();
imageUI?.UnloadImages();
}
#region CraftUI
[HookMethod("OpenCraftForPlayer")]
private void ShowCraftUI(BasePlayer player)
{
CuiHelper.DestroyUi(player, "MBCraft_UI");
var container = new CuiElementContainer();
string root = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
CursorEnabled = true
}, "Overlay", "MBCraft_UI");
string backgroundPanel = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.7", Material = "assets/content/ui/uibackgroundblur.mat" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
CursorEnabled = true
}, root);
string imageId = imageUI?.GetImage("MBWelcome_Five_Os");
if (!string.IsNullOrEmpty(imageId))
{
container.Add(new CuiElement
{
Name = CuiHelper.GetGuid(),
Parent = root,
Components =
{
new CuiRawImageComponent { Png = imageId },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-558 -314", OffsetMax = "558 315" }
}
});
}
// // Панель-фон
// container.Add(new CuiPanel
// {
// Image = { Color = "0.67 0.87 0.80 0" }, // Темно-сірий прозорий фон
// RectTransform = { AnchorMin = "0.68 0.44", AnchorMax = "0.8 0.465" }
// }, root);
container.Add(new CuiButton
{
Button = { Color = "0 0 0 0", Close = "MBCraft_UI" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
Text = { Text = "", FontSize = 0 }
}, root);
string centerPanel = container.Add(new CuiPanel
{
Image = { Color = "0.1 0.1 0.1 0" },
RectTransform = {
AnchorMin = "0.5 0.5",
AnchorMax = "0.5 0.5",
OffsetMin = "-438 -265", // ширина 800, высота 600
OffsetMax = "440 265"
},
CursorEnabled = true
}, root);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.341 0.86", AnchorMax = "0.75 0.955" },
Text = { Text = Msg("MB_Craft_Player", player.userID.ToString()), Color = "1 1 1 0.9", Align = TextAnchor.MiddleLeft, FontSize = 32 }
}, centerPanel);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.341 0.8", AnchorMax = "0.8 0.868" },
Text = { Text = Msg("MB_Craft_Player_2", player.userID.ToString()), Color = "1 1 1 0.9", Align = TextAnchor.MiddleLeft, FontSize = 23, Font = "permanentmarker.ttf" }
}, centerPanel);
container.Add(new CuiLabel
{
Text = { Text = Msg("MB_Close_Craft", player.userID.ToString()), FontSize = 13, Color = "1 1 1 0.4", Align = TextAnchor.MiddleCenter },
RectTransform = { AnchorMin = "0.2 -0.06", AnchorMax = "0.8 -0.02" }
}, centerPanel);
container.Add(new CuiButton
{
Button = {
Command = "mbcraft.back", // кастомная команда
Color = "0.2 0.5 0.8 0"
},
RectTransform = { AnchorMin = "0.865 0.04", AnchorMax = "0.947 0.12" },
Text = {
Text = Msg("MB_Back", player.UserIDString),
FontSize = 15,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
}
}, centerPanel);
// Прокрутка предметів (одна колонка)
float blockHeight = 54f;
float blockMargin = 5.2f;
float verticalShift = 1f;
int totalItems = configData.Items.Count;
float totalHeight = totalItems * (blockHeight + blockMargin);
float minVisibleHeight = 300f;
float scrollContentHeight = Mathf.Max(totalHeight, minVisibleHeight);
// ScrollView контейнер
container.Add(new CuiElement
{
Name = "MBScrollableCraftArea",
Parent = centerPanel,
Components =
{
new CuiScrollViewComponent
{
Vertical = true,
Horizontal = false,
Inertia = true,
Elasticity = 0.2f,
DecelerationRate = 0.2f,
ScrollSensitivity = 30f,
ContentTransform = new CuiRectTransform
{
AnchorMin = "0 1",
AnchorMax = "1 1",
OffsetMin = $"0 -{scrollContentHeight}",
OffsetMax = "0 0"
},
VerticalScrollbar = new CuiScrollbar
{
Size = 5f,
AutoHide = false,
HandleColor = "0.3 0.6 0.9 0.7",
TrackColor = "0.1 0.1 0.1 0.6"
}
},
new CuiRectTransformComponent
{
AnchorMin = "0.745 0.221",
AnchorMax = "0.965 0.78"
},
new CuiNeedsCursorComponent()
}
});
// Внутрішній вміст
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform =
{
AnchorMin = "0 1",
AnchorMax = "0.94 1",
OffsetMin = $"0 -{scrollContentHeight}",
OffsetMax = "0 0"
}
}, "MBScrollableCraftArea", "MBCraftContent");
int columns = 1;
float columnWidth = 1f / columns;
for (int i = 0; i < configData.Items.Count; i++)
{
int row = i / columns;
int col = i % columns;
float topOffset = -(row * (blockHeight + blockMargin)) - verticalShift;
float bottomOffset = topOffset - blockHeight;
float left = col * columnWidth;
float right = left + columnWidth;
var item = configData.Items[i];
string image = item.ShortName;
if (!string.IsNullOrEmpty(image) && !image.StartsWith("http"))
image = "https://rustlabs.com/img/items180/" + image + ".png";
string background = imageUI.GetImage("item_bg");
string containerName = $"CraftItemContainer_{i}";
// Контейнер блоку
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform =
{
AnchorMin = $"{left} 1",
AnchorMax = $"{right} 1",
OffsetMin = $"0 {bottomOffset}",
OffsetMax = $"0 {topOffset}"
}
}, "MBCraftContent", containerName);
// Фон
if (!string.IsNullOrEmpty(background))
{
container.Add(new CuiElement
{
Name = $"CraftItemBG_{i}",
Parent = containerName,
Components =
{
new CuiRawImageComponent
{
Png = background,
Sprite = "assets/content/textures/generic/fulltransparent.tga",
Color = "1 1 1 1"
},
new CuiRectTransformComponent
{
AnchorMin = "0 0",
AnchorMax = "1 1"
}
}
});
}
var itemDef = ItemManager.FindItemDefinition(item.ShortName);
if (itemDef != null)
{
int itemId = itemDef.itemid;
container.Add(new CuiElement
{
Name = $"CraftItemImage_{i}",
Parent = containerName,
Components =
{
new CuiImageComponent
{
ItemId = itemId
// SkinId = 0 // если нужно
},
new CuiRectTransformComponent
{
AnchorMin = "0.03 0.07",
AnchorMax = "0.32 0.93"
}
}
});
}
// Назва предмета
container.Add(new CuiLabel
{
Text =
{
Text = item.DisplayName,
FontSize = 13,
Align = TextAnchor.MiddleLeft,
Color = "1 1 1 0.6"
},
RectTransform =
{
AnchorMin = "0.35 0.6", AnchorMax = "0.95 0.9"
}
}, containerName);
// Матеріали (якщо є)
if (item.Materials != null && item.Materials.Count > 0)
{
string materialsText = string.Join(", ",
item.Materials.Select(kv =>
{
string translated = GetMaterialDisplayName(kv.Key, player.UserIDString);
return $"{translated} × {kv.Value}";
})
);
container.Add(new CuiLabel
{
Text =
{
Text = materialsText,
FontSize = 9,
Align = TextAnchor.UpperLeft,
Color = "1 1 1 0.6"
},
RectTransform =
{
AnchorMin = "0.35 0.1", AnchorMax = "0.96 0.55"
}
}, containerName);
}
// Кнопка
container.Add(new CuiButton
{
Button =
{
Color = "0 0 0 0",
Command = $"mbcraft.select {i}"
},
RectTransform =
{
AnchorMin = "0 0",
AnchorMax = "1 1"
},
Text =
{
Text = "",
FontSize = 0
}
}, containerName);
}
CuiHelper.AddUi(player, container);
// Показать первый предмет только при первом открытии
if (configData.Items.Count > 0)
{
craftAmounts[player.userID] = 1;
ShowItemDetailUI(player, configData.Items[0], 0);
}
}
#endregion
#region ItemDetailUI
private void ShowItemDetailUI(BasePlayer player, ItemEntry item, int index)
{
int amount = craftAmounts.TryGetValue(player.userID, out int value) ? value : 1;
craftAmounts[player.userID] = amount;
CuiHelper.DestroyUi(player, "MBCraft_ItemDetail");
string image = item.ShortName;
if (!string.IsNullOrEmpty(image) && !image.StartsWith("http"))
image = "https://rustlabs.com/img/items180/" + image + ".png";
var container = new CuiElementContainer();
container.Add(new CuiPanel
{
Image = { Color = "0.67 0.87 0.80 0" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-139 -147", OffsetMax = "206 150" },
CursorEnabled = true
}, "MBCraft_UI", "MBCraft_ItemDetail");
var itemDef = ItemManager.FindItemDefinition(item.ShortName);
if (itemDef != null)
{
container.Add(new CuiElement
{
Parent = "MBCraft_ItemDetail",
Components =
{
new CuiImageComponent
{
ItemId = itemDef.itemid
},
new CuiRectTransformComponent
{
AnchorMin = "0.755 0.71",
AnchorMax = "0.9496 0.943"
}
}
});
}
// // Панель-фон
// container.Add(new CuiPanel
// {
// Image = { Color = "0.67 0.87 0.80 0.2" }, // Темно-сірий прозорий фон
// RectTransform = { AnchorMin = "0.045 0.71", AnchorMax = "0.62 0.943" }
// }, "MBCraft_ItemDetail");
// // Название
// container.Add(new CuiLabel
// {
// Text = { Text = item.DisplayName, FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
// RectTransform = { AnchorMin = "0.05 0.25", AnchorMax = "0.95 0.35" }
// }, "MBCraft_ItemDetail");
// Описание
container.Add(new CuiLabel
{
Text = { Text = item.Description, FontSize = 11, Align = TextAnchor.UpperLeft, Color = "1 1 1 0.5" },
RectTransform = { AnchorMin = "0.05 0.71", AnchorMax = "0.62 0.943" }
}, "MBCraft_ItemDetail");
// Кнопка "Крафт"
container.Add(new CuiButton
{
Button = {
Command = $"mbcraft.craft {index}",
Color = "0.25 0.7 0.25 0"
},
RectTransform = { AnchorMin = "0.803 0.026", AnchorMax = "0.965 0.115" },
Text = {
Text = Msg("MB_Craft", player.userID.ToString()),
FontSize = 12,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.6"
}
}, "MBCraft_ItemDetail");
int row = 0;
float rowHeight = 0.098f;
float startY = 0.535f;
foreach (var kv in item.Materials)
{
if (row >= 5) break;
float anchorMinY = startY - row * rowHeight;
float anchorMaxY = anchorMinY + rowHeight;
string translatedName = GetMaterialDisplayName(kv.Key, player.UserIDString);
string rowContainer = $"MaterialLine_{row}";
// Контейнер строки
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform = {
AnchorMin = $"0 {anchorMinY}",
AnchorMax = $"1 {anchorMaxY}"
}
}, "MBCraft_ItemDetail", rowContainer);
// Количество
container.Add(new CuiLabel
{
Text = {
Text = kv.Value.ToString(),
FontSize = 11,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.5"
},
RectTransform = {
AnchorMin = "0.03 0", AnchorMax = "0.191 1"
}
}, rowContainer);
// Название
container.Add(new CuiLabel
{
Text = {
Text = translatedName,
FontSize = 11,
Align = TextAnchor.MiddleLeft,
Color = "1 1 1 0.5"
},
RectTransform = {
AnchorMin = "0.22 0",
AnchorMax = "0.95 1"
}
}, rowContainer);
// Загальна сума (кількість × amount)
if (amount > 0)
{
container.Add(new CuiLabel
{
Text = {
Text = $"{kv.Value * amount}",
FontSize = 11,
Align = TextAnchor.MiddleCenter,
Color = "1 1 0 0.8" // Жовтий
},
RectTransform = {
AnchorMin = "0.81 0", AnchorMax = "0.955 1"
}
}, rowContainer);
}
row++;
// Кількість для крафту
container.Add(new CuiLabel
{
Text = {
Text = amount.ToString(),
FontSize = 14,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.5"
},
RectTransform = { AnchorMin = "0.51 0.027", AnchorMax = "0.671 0.115" }
}, "MBCraft_ItemDetail");
// "+" кнопка
container.Add(new CuiButton
{
Button = {
Command = $"mbcraft.amount {index} add",
Color = "0.2 0.8 0.2 0"
},
RectTransform = { AnchorMin = "0.684 0.026", AnchorMax = "0.771 0.115" },
Text = {
Text = "+",
FontSize = 16,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.6"
}
}, "MBCraft_ItemDetail");
// "-" кнопка
container.Add(new CuiButton
{
Button = {
Command = $"mbcraft.amount {index} sub",
Color = "0.8 0.2 0.2 0"
},
RectTransform = { AnchorMin = "0.41 0.026", AnchorMax = "0.495 0.115" },
Text = {
Text = "-",
FontSize = 16,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 0.6"
}
}, "MBCraft_ItemDetail");
// Необхідний верстак
if (item.WorkbenchLevel > 0)
{
container.Add(new CuiLabel
{
Text = {
Text = Msg("workbench_required", player.UserIDString, item.WorkbenchLevel),
FontSize = 10,
Align = TextAnchor.MiddleCenter,
Color = "1 0.5 0 0.8"
},
RectTransform = { AnchorMin = "0.03 0.03", AnchorMax = "0.335 0.115" }
}, "MBCraft_ItemDetail");
}
else
{
container.Add(new CuiLabel
{
Text = {
Text = Msg("workbench_not_required", player.UserIDString),
FontSize = 10,
Align = TextAnchor.MiddleCenter,
Color = "0.5 1 0.5 0.3"
},
RectTransform = { AnchorMin = "0.03 0.03", AnchorMax = "0.335 0.115" }
}, "MBCraft_ItemDetail");
}
// // Панель-фон
// container.Add(new CuiPanel
// {
// Image = { Color = "0.67 0.87 0.80 0.2" }, // Темно-сірий прозорий фон
// RectTransform = { AnchorMin = "0.03 0.026", AnchorMax = "0.335 0.115" }
// }, "MBCraft_ItemDetail");
}
CuiHelper.AddUi(player, container);
}
private string GetMaterialDisplayName(string shortName, string userId = null)
{
var dict = new Dictionary<string, string>
{
{ "wood", Msg("material_wood", userId) },
{ "metal.fragments", Msg("material_metal_fragments", userId) },
{ "stones", Msg("material_stones", userId) },
{ "cloth", Msg("material_cloth", userId) },
{ "sulfur", Msg("material_sulfur", userId) },
{ "charcoal", Msg("material_charcoal", userId) },
{ "gunpowder", Msg("material_gunpowder", userId) },
{ "lowgradefuel", Msg("material_lowgradefuel", userId) },
{ "bone.fragments", Msg("material_bone_fragments", userId) },
{ "tarp", Msg("material_tarp", userId) },
{ "skull.human", Msg("material_skull_human", userId) },
{ "leather", Msg("material_leather", userId) },
{ "pumpkin", Msg("material_pumpkin", userId) },
{ "sewingkit", Msg("material_sewingkit", userId) },
{ "metal.refined", Msg("material_metal_refined", userId) },
// добавь по необходимости
};
return dict.TryGetValue(shortName, out var translated) ? translated : shortName;
}
[ConsoleCommand("mbcraft.select")]
private void CmdSelectItem(ConsoleSystem.Arg arg)
{
var player = arg?.Player();
if (player == null || arg.Args == null || arg.Args.Length < 1) return;
if (!int.TryParse(arg.Args[0], out int index)) return;
if (index < 0 || index >= configData.Items.Count) return;
var item = configData.Items[index];
// Скидаємо кількість крафту до 1 при виборі нового предмета
craftAmounts[player.userID] = 1;
ShowItemDetailUI(player, item, index);
}
[ConsoleCommand("mbcraft.amount")]
private void CmdCraftAmount(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || arg.Args == null || arg.Args.Length < 2) return;
if (!int.TryParse(arg.Args[0], out int index)) return;
if (index < 0 || index >= configData.Items.Count) return;
string action = arg.Args[1];
int current = craftAmounts.TryGetValue(player.userID, out int val) ? val : 1;
if (action == "add")
current++;
else if (action == "sub")
current = Mathf.Max(1, current - 1);
craftAmounts[player.userID] = current;
ShowItemDetailUI(player, configData.Items[index], index);
}
[ConsoleCommand("mbcraft.craft")]
private void CmdCraft(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null || arg.Args == null || arg.Args.Length < 1) return;
if (!int.TryParse(arg.Args[0], out int index)) return;
if (index < 0 || index >= configData.Items.Count) return;
var item = configData.Items[index];
// Отримати кількість для крафту
int count = craftAmounts.TryGetValue(player.userID, out int selectedAmount) ? selectedAmount : 1;
// Перевірка верстака
if (!HasRequiredWorkbench(player, item.WorkbenchLevel))
{
player.ChatMessage($"❌ Потрібен верстак {item.WorkbenchLevel} рівня для крафту \"{item.DisplayName}\".");
return;
}
// Перевірка ресурсів
foreach (var kv in item.Materials)
{
int required = kv.Value * count;
int available = player.inventory.GetAmount(ItemManager.FindItemDefinition(kv.Key).itemid);
if (available < required)
{
player.ChatMessage($"❌ Не вистачає ресурсу: {kv.Key} × {required}");
return;
}
}
// Списання ресурсів
foreach (var kv in item.Materials)
{
int required = kv.Value * count;
player.inventory.Take(null, ItemManager.FindItemDefinition(kv.Key).itemid, required);
}
// Видача предметів
for (int i = 0; i < count; i++)
{
var createdItem = ItemManager.CreateByName(item.ShortName, 1);
if (createdItem != null)
{
player.GiveItem(createdItem);
}
}
player.ChatMessage($"✅ Ви скрафтили: <color=#00FF00>{item.DisplayName}</color> × {count}");
}
[ConsoleCommand("mbcraft.back")]
private void CmdBack(ConsoleSystem.Arg arg)
{
var player = arg.Connection?.player as BasePlayer;
if (player == null) return;
CuiHelper.DestroyUi(player, "MBCraft_UI");
MBMainMenu?.Call("ShowMainMenu", player);
}
#endregion
private bool HasRequiredWorkbench(BasePlayer player, int requiredLevel)
{
if (requiredLevel <= 0) return true;
var entities = new List<BaseEntity>();
Vis.Entities(player.transform.position, 8f, entities, Rust.Layers.Solid); // Радіус 8 м
int highestFound = 0;
foreach (var entity in entities)
{
if (entity?.ShortPrefabName == null) continue;
if (entity.ShortPrefabName.Contains("workbench1.deployed"))
highestFound = Math.Max(highestFound, 1);
else if (entity.ShortPrefabName.Contains("workbench2.deployed"))
highestFound = Math.Max(highestFound, 2);
else if (entity.ShortPrefabName.Contains("workbench3.deployed"))
highestFound = Math.Max(highestFound, 3);
}
return highestFound >= requiredLevel;
}
#region ImageUI
private class ImageUI
{
private const string PathFolder = "MBSystem/MBCraft/Images/";
private readonly Dictionary<string, ImageData> _images = new()
{
{ "MBWelcome_Five_Os", new ImageData() },
{ "item_bg", new ImageData() },
};
private enum ImageStatus { NotLoaded, Loaded, Failed }
private class ImageData
{
public ImageStatus Status = ImageStatus.NotLoaded;
public string Id { get; set; }
}
public string GetImage(string name)
{
if (_images.TryGetValue(name, out var image) && image.Status == ImageStatus.Loaded)
return image.Id;
return null;
}
public void DownloadImages()
{
string fullPath = Interface.Oxide.DataDirectory + System.IO.Path.DirectorySeparatorChar + PathFolder;
if (!System.IO.Directory.Exists(fullPath))
{
System.IO.Directory.CreateDirectory(fullPath);
Interface.Oxide.LogInfo($"[MBCraft] Создана папка: {fullPath}");
}
var nextImage = _images.FirstOrDefault(img => img.Value.Status == ImageStatus.NotLoaded);
if (!string.IsNullOrEmpty(nextImage.Key))
ServerMgr.Instance.StartCoroutine(LoadImage(nextImage));
else
Interface.Oxide.LogInfo("[MBCraft] Все изображения загружены!");
}
private IEnumerator LoadImage(KeyValuePair<string, ImageData> image)
{
string filePath = "file://" + Interface.Oxide.DataDirectory + System.IO.Path.DirectorySeparatorChar + PathFolder + image.Key + ".png";
using (var www = UnityEngine.Networking.UnityWebRequestTexture.GetTexture(filePath))
{
yield return www.SendWebRequest();
if (www.result != UnityEngine.Networking.UnityWebRequest.Result.Success)
{
image.Value.Status = ImageStatus.Failed;
Interface.Oxide.LogWarning($"[MBCraft] Ошибка загрузки {image.Key}");
}
else
{
Texture2D texture = UnityEngine.Networking.DownloadHandlerTexture.GetContent(www);
image.Value.Id = FileStorage.server.Store(texture.EncodeToPNG(), FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID).ToString();
image.Value.Status = ImageStatus.Loaded;
UnityEngine.Object.DestroyImmediate(texture);
}
DownloadImages(); // Попытка загрузить следующую
}
}
public void UnloadImages()
{
foreach (var img in _images)
{
if (img.Value.Status == ImageStatus.Loaded && img.Value.Id != null)
FileStorage.server.Remove(uint.Parse(img.Value.Id), FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID);
}
_images.Clear();
}
}
#endregion
#region lang
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["MB_Close_Craft"] = "Click on an empty space to close the menu",
["MB_Craft_Player"] = "CRAFT",
["MB_Craft_Player_2"] = "<color=#FFD700>Craft</color> DLC gear!",
["MB_Back"] = "Back",
["material_wood"] = "Wood",
["material_metal_fragments"] = "Metal Fragments",
["material_stones"] = "Stones",
["material_cloth"] = "Cloth",
["material_sulfur"] = "Sulfur",
["material_bone_fragments"] = "Bone Fragments",
["material_charcoal"] = "Charcoal",
["material_gunpowder"] = "Gunpowder",
["material_lowgradefuel"] = "Low Grade Fuel",
["material_tarp"] = "Tarp",
["material_skull_human"] = "Human Skull",
["material_leather"] = "Leather",
["material_pumpkin"] = "Pumpkin",
["material_sewingkit"] = "Sewing Kit",
["material_metal_refined"] = "High Quality Metal",
["MB_Craft"] = "Craft",
["workbench_required"] = "Workbench level {0}",
["workbench_not_required"] = "No workbench required",
}, this);
lang.RegisterMessages(new Dictionary<string, string>
{
["MB_Close_Craft"] = "Натисніть на порожнє місце, щоб закрити меню",
["MB_Craft_Player"] = "КРАФТ",
["MB_Craft_Player_2"] = "<color=#FFD700>Скрафти</color> принадлежності з DLC!",
["MB_Back"] = "Назад",
["material_wood"] = "Дерево",
["material_metal_fragments"] = "Металеві фрагменти",
["material_stones"] = "Каміння",
["material_cloth"] = "Тканина",
["material_sulfur"] = "Сірка",
["material_bone_fragments"] = "Кісткові уламки",
["material_charcoal"] = "Вугілля",
["material_gunpowder"] = "Порох",
["material_lowgradefuel"] = "Низькосортне паливо",
["material_tarp"] = "Брезент",
["material_skull_human"] = "Людський череп",
["material_leather"] = "Шкіра",
["material_pumpkin"] = "Гарбуз",
["material_sewingkit"] = "Швейний набір",
["material_metal_refined"] = "Високоякісний метал",
["MB_Craft"] = "Створити",
["workbench_required"] = "Потрібен верстак {0}",
["workbench_not_required"] = "Верстак не потрібен",
}, this, "uk");
lang.RegisterMessages(new Dictionary<string, string>
{
["MB_Close_Craft"] = "Нажмите на пустое место, чтобы закрыть меню",
["MB_Craft_Player"] = "КРАФТ",
["MB_Craft_Player_2"] = "<color=#FFD700>Скрафтить</color> предметы из DLC!",
["MB_Back"] = "Назад",
["material_wood"] = "Дерево",
["material_metal_fragments"] = "Металлические фрагменты",
["material_stones"] = "Камень",
["material_cloth"] = "Ткань",
["material_sulfur"] = "Сера",
["material_bone_fragments"] = "Костные осколки",
["material_charcoal"] = "Уголь",
["material_gunpowder"] = "Порох",
["material_lowgradefuel"] = "Низкокачественное топливо",
["material_tarp"] = "Брезент",
["material_skull_human"] = "Череп человека",
["material_leather"] = "Кожа",
["material_pumpkin"] = "Тыква",
["material_sewingkit"] = "Швейный набор",
["material_metal_refined"] = "Высококачественный металл",
["MB_Craft"] = "Создать",
["workbench_required"] = "Требуется верстак {0}",
["workbench_not_required"] = "Верстак не требуется"
}, this, "ru");
}
private string Msg(string key, string userid = null, params object[] obj)
{
return string.Format(lang.GetMessage(key, this, userid), obj);
}
#endregion
}
}