RaidBlock.cs
RaidBlock.cs
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using ConVar;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Rust;
using UnityEngine;
using VLB;
using Oxide.Plugins.RaidBlockExt;
using UnityEngine.Networking;
using Layer = Rust.Layer;
using Pool = Facepunch.Pool;
using Time = UnityEngine.Time;
namespace Oxide.Plugins
{
[Info("RaidBlock", "C новым годом от команды TopPlugin.ru", "1.1.24")]
public class RaidBlock : RustPlugin
{
/// <summary>
/// - Исправлена проблема с блокировкой комманд. Нужно заного заполнить
команды в конфигурации. без слэша в нижнем регистре
/// - Добавлена поддержка плагина RaidableBases - настраивается в
конфигурации.
/// </summary>
#region ReferencePlugins
#region IQChat
if (Clans)
{
if (Clans.Call("GetClanMembers", targetPlayer.UserIDString) is
ulong[] clanMembers)
friendList.AddRange(clanMembers);
}
if(targetPlayer.Team != null)
friendList.AddRange(targetPlayer.Team.members);
return friendList.ToArray();
}
#endregion
#region Var
#endregion
#region Types
#endregion
#region Configuration
private Configuration config;
SaveConfig();
}
catch
{
for (int i = 0; i < 3; i++)
{
PrintError(LanguageEn ? "Configuration file is corrupt! Check
your config file at https://jsonlint.com/" : "Вы допустили ошибку синтаксиса в
конфигурационном файле! Проверьте файл на https://jsonlint.com/");
}
LoadDefaultConfig();
}
ValidateConfig();
SaveConfig();
}
#region Lang
#endregion
#region Hooks
if (_imageUI != null)
{
_imageUI.UnloadImages();
_imageUI = null;
}
_interface = null;
Instance = null;
}
SubscribeHook(true, false);
}
Instance.SendChat("RAIDBLOCK_KILL_PLAYER".GetAdaptedMessage(player.UserIDString),
player);
UnityEngine.Object.DestroyImmediate(raidPlayer);
}
}
#endregion
SendChat("RAIDBLOCK_ENTER_RAID_ZONE".GetAdaptedMessage(player.UserIDString,
time.ToTimeFormat()), player, 3f);
raidPlayer.ActivateBlock(Time.realtimeSinceStartup + time);
Interface.CallHook("OnEnterRaidZone", player);
}
SendChat("RAIDBLOCK_EXIT_RAID_ZONE".GetAdaptedMessage(player.UserIDString),
player);
Interface.CallHook("OnExitRaidZone", player);
}
#endregion
#region HooksBlockedActions
if (config.ActionsBlocked.RbDeployWhiteList.Contains(shortname))
return null;
Deployable deployable = planner.GetDeployable();
if (deployable != null && !config.ActionsBlocked.CanDeployObjects)
return null;
if (prefab.defaultGrade != null && !config.ActionsBlocked.CanBuildTwig)
return null;
return CanActions(player);
}
return
config.ActionsBlocked.RbBlackListCommand.Contains(onlyCommand.ToLower()) ?
CanActions(player) : null;
}
return
config.ActionsBlocked.RbBlackListCommand.Contains(onlyCommand.ToLower()) ?
CanActions(player) : null;
}
#region Api
private object CanBGrade(BasePlayer player, int grade, BuildingBlock
buildingBlock, Planner planner) => CanActions(player);
private object CanTeleport(BasePlayer player) => CanActions(player, true);
private object canTeleport(BasePlayer player) => CanActions(player);
private object CanRedeemKit(BasePlayer player) => CanActions(player);
private object canRemove(BasePlayer player) => CanActions(player);
private object CanRemove(BasePlayer player) => CanActions(player);
private object canTrade(BasePlayer player) => CanTrade(player);
private object CanTrade(BasePlayer player) => CanActions(player, true);
#region Call
#endregion
#region Metods
if(config.RaidBlockMain.RaidableBasesIntegration.BlockOnEnterZone)
Subscribe(nameof(OnPlayerEnteredRaidableBase));
if(config.RaidBlockMain.RaidableBasesIntegration.BlockOnExitZone)
Subscribe(nameof(OnPlayerExitedRaidableBase));
}
}
if (raidActions)
{
Subscribe(nameof(OnPlayerCommand));
Subscribe(nameof(OnServerCommand));
}
if (config.RaidBlockMain.RaidBlockOnPlayerDeath)
{
Subscribe(nameof(OnPlayerDeath));
}
if (config.ActionsBlocked.CanUseKit)
{
Subscribe(nameof(CanRedeemKit));
}
if (config.ActionsBlocked.CanUseTeleport)
{
Subscribe(nameof(canTeleport));
Subscribe(nameof(CanTeleport));
}
if (config.ActionsBlocked.CanUseTrade)
{
Subscribe(nameof(canTrade));
Subscribe(nameof(CanTrade));
}
if (config.ActionsBlocked.CanDemolishObjects)
{
Subscribe(nameof(OnStructureDemolish));
Subscribe(nameof(canRemove));
Subscribe(nameof(CanRemove));
}
if (config.ActionsBlocked.CanRepairObjects)
{
Subscribe(nameof(OnStructureRepair));
}
if (config.ActionsBlocked.CanBuildTwig ||
config.ActionsBlocked.CanDeployObjects ||
config.ActionsBlocked.RbDeployWhiteList.Count > 0)
{
Subscribe(nameof(CanBuild));
}
if (config.ActionsBlocked.CanUpgradeObjects)
{
Subscribe(nameof(OnStructureUpgrade));
Subscribe(nameof(CanBGrade));
Subscribe(nameof(OnStructureRotate));
}
if (config.ActionsBlocked.CanPickUpObjects)
{
Subscribe(nameof(CanPickupEntity));
}
}
}
if (raidActions)
{
Unsubscribe(nameof(OnPlayerDeath));
Unsubscribe(nameof(CanBGrade));
Unsubscribe(nameof(CanBuild));
Unsubscribe(nameof(OnStructureUpgrade));
Unsubscribe(nameof(OnStructureRepair));
Unsubscribe(nameof(OnStructureDemolish));
Unsubscribe(nameof(OnStructureRotate));
Unsubscribe(nameof(canTeleport));
Unsubscribe(nameof(CanTeleport));
Unsubscribe(nameof(OnPlayerCommand));
Unsubscribe(nameof(OnServerCommand));
Unsubscribe(nameof(canRemove));
Unsubscribe(nameof(CanRemove));
Unsubscribe(nameof(canTrade));
Unsubscribe(nameof(CanTrade));
Unsubscribe(nameof(CanRedeemKit));
Unsubscribe(nameof(CanPickupEntity));
}
}
private static void RunEffect(BasePlayer player, string prefab)
{
Effect effect = new Effect();
effect.Init(Effect.Type.Generic, player.transform.position,
Vector3.zero);
effect.pooledString = prefab;
EffectNetwork.Send(effect, player.net.connection);
}
SendChat("RAIDBLOCK_ACTION_BLOCKED".GetAdaptedMessage(player.UserIDString,
playPlayer.UnblockTimeLeft.ToTimeFormat()), player);
return false;
}
else
{
return
"RAIDBLOCK_ACTION_BLOCKED".GetAdaptedMessage(player.UserIDString,
playPlayer.UnblockTimeLeft.ToTimeFormat());
}
}
return null;
}
if(!config.BlockDetect.CanRaidIfNotCupboard &&
entity.GetBuildingPrivilege() == null)
return;
SendChat("RAIDBLOCK_OWNER_NOTIFY".GetAdaptedMessage(ownerPlayer.UserIDString,
GetGridString(entity.transform.position)), ownerPlayer, 3f);
CreateOrRefreshRaidblock(entity.transform.position, raider);
}
}
}
private void CreateOrRefreshRaidblock(Vector3 position, BasePlayer player)
{
if (permission.UserHasPermission(player.UserIDString, Name +
_permIgnoreRaid))
return;
Interface.CallHook("OnRaidBlock", position);
}
[ChatCommand("rbtest")]
void rbtest(BasePlayer player)
{
if(!player.IsAdmin) return;
CreateOrRefreshRaidblock(player.transform.position, player);
}
return true;
}
#endregion
#region ToolGunAdminHelper
if (!activeItem.info.shortname.Equals(RB_WHITE_AND_BLACK_LIST_ITEM) ||
(activeItem.skin is not RB_WHITELIST_ITEM_SKIN and not
RB_BLACKLIST_ITEM_SKIN))
return null;
return false;
}
GameTipsSendPlayer(player,
messageKey.GetAdaptedMessage(player.UserIDString, entity.ShortPrefabName,
prefabId));
SaveConfig();
return;
list.Add(id);
return true;
}
}
[ChatCommand("rb.white")]
private void RaidBlockDetectWhiteList(BasePlayer player)
{
if (!HasPermission(player))
return;
string itemName =
"RAIDBLOCK_TOOLGUN_WHITELIST_ITEM_NAME".GetAdaptedMessage(player.UserIDString);
if (FindItemInInventory(player, RB_WHITELIST_ITEM_SKIN))
{
GameTipsSendPlayer(player,
"RAIDBLOCK_TOOLGUN_ALREADY_IN_INVENTORY".GetAdaptedMessage(player.UserIDString,
itemName), error: true);
return;
}
[ChatCommand("rb.black")]
private void RaidBlockDetectBlackList(BasePlayer player)
{
if (!HasPermission(player))
return;
string itemName =
"RAIDBLOCK_TOOLGUN_BLACKLIST_ITEM_NAME".GetAdaptedMessage(player.UserIDString);
if (FindItemInInventory(player, RB_BLACKLIST_ITEM_SKIN))
{
GameTipsSendPlayer(player,
"RAIDBLOCK_TOOLGUN_ALREADY_IN_INVENTORY".GetAdaptedMessage(player.UserIDString,
itemName), error: true);
return;
}
SendChat("RAIDBLOCK_TOOLGUN_PERMISSION_DENIED".GetAdaptedMessage(player.UserIDStrin
g), player);
return false;
}
return true;
}
DeleteNotification(player, seconds);
}
private readonly Dictionary<BasePlayer, Timer> _playerTimer = new
Dictionary<BasePlayer, Timer>();
if (_playerTimer.ContainsKey(player))
{
if (_playerTimer[player] != null && !
_playerTimer[player].Destroyed) _playerTimer[player].Destroy();
_playerTimer[player] = timers;
}
else _playerTimer.Add(player, timers);
}
#endregion
#region UnityHooks
private void Awake()
{
player = GetComponent<BasePlayer>();
if(!Instance.raidPlayersList.Contains(this))
Instance.raidPlayersList.Add(this);
Interface.CallHook("OnRaidBlockStarted", player);
}
DestroyImmediate(this);
}
private void OnDestroy()
{
CuiHelper.DestroyUi(player, InterfaceBuilder.RB_MAIN);
Interface.CallHook("OnRaidBlockStopped", player);
}
#endregion
#region Metods
#region UI Methods
public void CrateUI() => Instance.DrawUI_RB_Main(player,
UnblockTimeLeft);
private void RefreshUI() => Instance.DrawUI_RB_Updated(player,
UnblockTimeLeft);
#endregion
}
#endregion
#region Metods
#region VisualizationSphere
#endregion
#region MapMarker
if (raidBlockType is MarkerTypes.ExplosionMarkerRadius or
MarkerTypes.MarkerRadius or MarkerTypes.MarkerRadiusTimer)
{
CreateGenericRadiusMapMarker();
}
if (raidBlockType is MarkerTypes.Explosion or
MarkerTypes.ExplosionMarkerRadius)
{
CreateExplosionMapMarker();
}
InvokeRepeating(nameof(UpdateGenericRadiusMapMarker), 10f, 10f);
}
float CalculateRadius()
{
const float a = 100 / 6f;
float b = Mathf.Sqrt(a) / 2f;
float c = World.Size / 1300f;
float d = b / c;
return d;
}
#endregion
#region Core
if (marker.IsValid())
{
marker.transform.position = position;
}
if (vendingMakrer.IsValid())
{
vendingMakrer.markerShopName = "RAID BLOCK: " +
UnblockTimeLeft.ToTimeFormat();
vendingMakrer.transform.position = position;
}
else if (mapMarkerGenericRadius.IsValid())
{
mapMarkerGenericRadius.transform.position = position;
}
UpdateGenericRadiusMapMarker();
triggerZone.radius = raidBlockDistance;
triggerZone.gameObject.layer = (int) Layer.Reserved1;
triggerZone.transform.SetParent(transform, true);
triggerZone.isTrigger = true;
}
transform.position = raidPos;
initiatorRaid = initiator;
InitializeTriggerZone();
AddPlayer(initiatorRaid, true);
if
(Instance.config.RaidBlockMain.mapMarkerSettings.IsRaidBlockMarkerEnabled)
CreateMapMarker();
if
(Instance.config.RaidBlockMain.RaidZoneSphereSettings.IsSphereEnabled)
CreateSphere();
if
(Instance.config.RaidBlockMain.RaidBlockAddedAllPlayersInZoneRaid)
AddAllPlayerInZoneDistance();
if (Instance.config.RaidBlockMain.RaidBlockShareOnFriends)
AddAllPlayerFriendsInitiator(initiator);
if (Instance.config.RaidBlockMain.RaidBlockShareOnFriends)
AddAllPlayerFriendsInitiator(initiatorReply);
}
_playersAndComponentZone.Remove(playerAndComponent.Key);
});
continue;
}
raidPlayer.UpdateTime(timeToUnblock);
}
}
}
Destroy(this);
}
#endregion
Pool.FreeList(ref players);
}
AddPlayer(player, true);
}
}
if (player == initiatorRaid)
{
Instance.SendChat("RAIDBLOCK_ENTER_RAID_INITIATOR".GetAdaptedMessage(player.UserIDS
tring, leftTimeZone.ToTimeFormat()), player);
initiatorRaid = null;
}
else if(!_playersAndComponentZone.ContainsKey(player))
Instance.SendChat("RAIDBLOCK_ENTER_RAID_ZONE".GetAdaptedMessage(player.UserIDString
, leftTimeZone.ToTimeFormat()), player, 3f);
_playersAndComponentZone[player] = raidPlayer;
raidPlayer.ActivateBlock(timeToUnblock);
Interface.CallHook("OnEnterRaidZone", player);
}
if (Instance.config.RaidBlockMain.RaidBlockOnExitRaidZone &&
Instance.config.RaidBlockMain.TimeLeftOnExitZone == 0)
{
Destroy(_playersAndComponentZone[player]);
Instance.SendChat("RAIDBLOCK_EXIT_RAID_ZONE".GetAdaptedMessage(player.UserIDString)
, player);
}
else if(Instance.config.RaidBlockMain.TimeLeftOnExitZone != 0)
{
if (raidPlayer.UnblockTimeLeft >
Instance.config.RaidBlockMain.TimeLeftOnExitZone)
raidPlayer.UpdateTime(Time.realtimeSinceStartup +
Instance.config.RaidBlockMain.TimeLeftOnExitZone, true);
}
_playersAndComponentZone.Remove(player);
Interface.CallHook("OnExitRaidZone", player);
}
#endregion
#endregion
#region Init
#endregion
#region Hooks
if (vendingMakrer.IsValid())
vendingMakrer.Kill();
if (mapMarkerGenericRadius.IsValid())
mapMarkerGenericRadius.Kill();
marker = null;
mapMarkerGenericRadius = null;
_spheres = null;
Destroy(triggerZone);
}
#endregion
}
#region Refference
#region Friends
return teamMembers;
}
#endregion
#endregion
#region UI
switch (InterfaceBuilder.TypeUi)
{
case 0:
Interface = Interface.Replace("%Descriptions%",
"RAIDBLOCK_UI_DESCRIPTIONS_V1".GetAdaptedMessage(player.UserIDString));
break;
case 1:
Interface = Interface.Replace("%Descriptions%",
"RAIDBLOCK_UI_DESCRIPTIONS_V2".GetAdaptedMessage(player.UserIDString));
break;
}
Interface = Interface.Replace("%Title%",
"RAIDBLOCK_UI_TITLE".GetAdaptedMessage(player.UserIDString));
CuiHelper.DestroyUi(player, InterfaceBuilder.RB_MAIN);
CuiHelper.AddUi(player, Interface);
DrawUI_RB_Updated(player, timeLeft == 0 ?
config.RaidBlockMain.RaidBlockDuration : timeLeft, true);
}
private void DrawUI_RB_Updated(BasePlayer player, float timeLeft, bool upd
= false)
{
string Interface =
InterfaceBuilder.GetInterface(InterfaceBuilder.RB_PROGRESS_BAR);
if (Interface == null) return;
double factor = InterfaceBuilder.Factor * timeLeft /
config.RaidBlockMain.RaidBlockDuration;
Interface = Interface.Replace("%left%",
factor.ToString(CultureInfo.InvariantCulture));
Interface = Interface.Replace("%TimeLeft%",
"RAIDBLOCK_UI_TIMER".GetAdaptedMessage(player.UserIDString,
timeLeft.ToTimeFormat()));
if(!upd)
Interface = Interface.Replace("0.22", "0");
CuiHelper.DestroyUi(player, InterfaceBuilder.RB_PROGRESS);
CuiHelper.DestroyUi(player, InterfaceBuilder.RB_PROGRESS_TIMER);
CuiHelper.AddUi(player, Interface);
}
#endregion
#region Main
public InterfaceBuilder()
{
_instance = this;
_interfaces = new Dictionary<string, string>();
TypeUi = Instance.config.RaidBlockInterface.UiType;
Factor = TypeUi switch
{
0 => 142,
1 => 195,
_ => 130
};
_uiSettings = TypeUi switch
{
0 =>
Instance.config.RaidBlockInterface.InterfaceSettingsVariant0,
1 =>
Instance.config.RaidBlockInterface.InterfaceSettingsVariant1,
2 =>
Instance.config.RaidBlockInterface.InterfaceSettingsVariant2,
_ => throw new ArgumentOutOfRangeException()
};
_fade = _uiSettings.SmoothTransition;
switch (TypeUi)
{
case 0:
BuildingRaidBlockMain();
BuildingRaidBlockUpdated();
break;
case 1:
BuildingRaidBlockMainV2();
BuildingRaidBlockUpdatedV2();
break;
case 2:
BuildingRaidBlockMainV3();
BuildingRaidBlockUpdatedV3();
break;
}
}
_instance._interfaces.Add(name, json);
}
return json;
}
#endregion
#region Building UI V-1
container.Add(new CuiPanel
{
FadeOut = _fade,
CursorEnabled = false,
Image = { Color = "0 0 0 0", FadeIn = _fade },
RectTransform ={ AnchorMin = "1 0.5", AnchorMax = "1 0.5",
OffsetMin = $"{-179.00 + Instance.config.RaidBlockInterface.OffsetX} {-34.5 +
Instance.config.RaidBlockInterface.OffsetY}", OffsetMax = $"{-0.00 +
Instance.config.RaidBlockInterface.OffsetX} {34.5 +
Instance.config.RaidBlockInterface.OffsetY}" }
},Instance.config.RaidBlockInterface.Layers ,RB_MAIN);
container.Add(new CuiElement
{
FadeOut = _fade,
Name = "RB_BACKGROUND",
Parent = RB_MAIN,
Components = {
new CuiRawImageComponent { Color =
_uiSettings.BackgroundColor, Png = _imageUI.GetImage("RB_FON0"), FadeIn = _fade },
new CuiRectTransformComponent { AnchorMin = "0 0",
AnchorMax = "1 1"}
}
});
container.Add(new CuiPanel
{
FadeOut = _fade,
CursorEnabled = false,
Image = { Color = _uiSettings.ProgressBarBackgroundColor,
FadeIn = _fade },
RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 0",
OffsetMin = "-71.00 9.36", OffsetMax = "70.99 12.03" }
},RB_MAIN,RB_PROGRESS_BAR);
container.Add(new CuiLabel
{
FadeOut = _fade,
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
OffsetMin = "-71.00 -9.63", OffsetMax = "84.10 14.71" },
Text = { Text = "%Descriptions%", Font = "robotocondensed-
regular.ttf", FontSize = 8, Align = TextAnchor.MiddleLeft, Color =
_uiSettings.SecondaryTextColor, FadeIn = _fade }
}, RB_MAIN);
container.Add(new CuiLabel
{
FadeOut = _fade,
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
OffsetMin = "-71.00 14.71", OffsetMax = "-9.04 29.11"},
Text = { Text = "%Title%", Font = "robotocondensed-bold.ttf",
FontSize = 11, Align = TextAnchor.MiddleLeft, Color = _uiSettings.MainTextColor ,
FadeIn = _fade}
}, RB_MAIN);
container.Add(new CuiElement
{
Name = "RB_ICON",
Parent = RB_MAIN,
Components = {
new CuiRawImageComponent { Color = _uiSettings.IconColor,
Png = _imageUI.GetImage("RB_VARIANT0_ICON") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5",
AnchorMax = "0.5 0.5", OffsetMin = "-7.38 16.91", OffsetMax = "2.62 26.91" }
}
});
AddInterface(RB_MAIN, container.ToJson());
}
container.Add(new CuiLabel
{
FadeOut = _fade,
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
OffsetMin = "-71.00 -21.16", OffsetMax = "35.49 -9.63"},
Text = { Text = "%TimeLeft%", Font = "robotocondensed-
regular.ttf", FontSize = 9, Align = TextAnchor.MiddleLeft, Color =
_uiSettings.MainTextColor }
}, RB_MAIN, RB_PROGRESS_TIMER);
AddInterface(RB_PROGRESS_BAR, container.ToJson());
}
#endregion
},Instance.config.RaidBlockInterface.Layers,RB_MAIN);
container.Add(new CuiElement
{
FadeOut = _fade,
Name = "RB_BACKGROUND",
Parent = RB_MAIN,
Components = {
new CuiRawImageComponent { Color =
_uiSettings.BackgroundColor , Png = _imageUI.GetImage("RB_FON1"), FadeIn = _fade },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5",
AnchorMax = "0.5 0.5", OffsetMin = "-100.00 -17", OffsetMax = "99.99 20" }
}
});
container.Add(new CuiPanel
{
FadeOut = _fade,
CursorEnabled = false,
Image = { Color = _uiSettings.ProgressBarBackgroundColor,
FadeIn = _fade },
RectTransform ={ AnchorMin = "0.5 0", AnchorMax = "0.5 0",
OffsetMin = "-97.5 0", OffsetMax = "97.5 3.33" }
},RB_MAIN,RB_PROGRESS_BAR);
container.Add(new CuiLabel
{
FadeOut = _fade,
RectTransform = {AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
OffsetMin = "-64.62 0", OffsetMax = "-13.36 15.56" },
Text = { Text = "%Title%", Font = "robotocondensed-bold.ttf",
FontSize = 10, Align = TextAnchor.MiddleLeft, Color = _uiSettings.MainTextColor,
FadeIn = _fade }
}, RB_MAIN);
container.Add(new CuiLabel
{
FadeOut = _fade,
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5
0.5", OffsetMin = "-64.62 -12.76", OffsetMax = "68.69 2.76" },
Text = { Text = "%Descriptions%", Font = "robotocondensed-
regular.ttf", FontSize = 8, Align = TextAnchor.MiddleLeft, Color =
_uiSettings.SecondaryTextColor, FadeIn = _fade}
}, RB_MAIN);
container.Add(new CuiElement
{
Name = "RB_ICON_FON",
Parent = RB_MAIN,
Components = {
new CuiRawImageComponent { Color =
_uiSettings.AdditionalElementsColor, Png =
_imageUI.GetImage("RB_VARIANT1_ICON_FON") },
new CuiRectTransformComponent { AnchorMin = "0 0.5",
AnchorMax = "0 0.5", OffsetMin = "8.19 -10", OffsetMax = "32.19 13" }
}
});
container.Add(new CuiElement
{
Name = "RB_ICON",
Parent = "RB_ICON_FON",
Components = {
new CuiRawImageComponent { Color = _uiSettings.IconColor,
Png = _imageUI.GetImage("RB_VARIANT1_ICON") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5",
AnchorMax = "0.5 0.5", OffsetMin = "-9 -8.5", OffsetMax = "9 8.5" }
}
});
AddInterface(RB_MAIN, container.ToJson());
}
container.Add(new CuiPanel
{
FadeOut = _fade,
CursorEnabled = false,
Image = { Color = "1 1 1 0", FadeIn = _fade },
RectTransform ={ AnchorMin = "1 0.5", AnchorMax = "1 0.5",
OffsetMin = $"{-200 + Instance.config.RaidBlockInterface.OffsetX} {-28 +
Instance.config.RaidBlockInterface.OffsetY}", OffsetMax = $"{0 +
Instance.config.RaidBlockInterface.OffsetX} {28 +
Instance.config.RaidBlockInterface.OffsetY}" }
},Instance.config.RaidBlockInterface.Layers,RB_MAIN);
container.Add(new CuiElement
{
FadeOut = _fade,
Name = "RB_BACKGROUND",
Parent = RB_MAIN,
Components = {
new CuiRawImageComponent { Color =
_uiSettings.BackgroundColor, Png = _imageUI.GetImage("RB_FON2"), FadeIn = _fade },
new CuiRectTransformComponent { AnchorMin = "0 0",
AnchorMax = "1 1"}
}
});
container.Add(new CuiPanel
{
FadeOut = _fade,
CursorEnabled = false,
Image = { Color = _uiSettings.ProgressBarBackgroundColor,
FadeIn = _fade },
RectTransform ={ AnchorMin = "0.5 0", AnchorMax = "0.5 0",
OffsetMin = "-46.03 9.42", OffsetMax = "83.97 12.75" }
},RB_MAIN,RB_PROGRESS_BAR);
container.Add(new CuiLabel
{
FadeOut = _fade,
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
OffsetMin = "-2.95 1.54", OffsetMax = "83.97 21.85" },
Text = { Text = "%Title%", Font = "robotocondensed-bold.ttf",
FontSize = 14, Align = TextAnchor.MiddleRight, Color = _uiSettings.MainTextColor,
FadeIn = _fade}
}, RB_MAIN);
container.Add(new CuiPanel
{
CursorEnabled = false,
Image = { Color = _uiSettings.AdditionalElementsColor },
RectTransform ={ AnchorMin = "1 0.5", AnchorMax = "1 0.5",
OffsetMin = "-7.9 -25", OffsetMax = "-1.9 26" }
},RB_MAIN,"RB_RIGHT_PANEL");
container.Add(new CuiElement
{
Name = "RB_ICON",
Parent = RB_MAIN,
Components = {
new CuiRawImageComponent { Color = _uiSettings.IconColor,
Png = _imageUI.GetImage("RB_VARIANT2_ICON") },
new CuiRectTransformComponent { AnchorMin = "0 0.5",
AnchorMax = "0 0.5", OffsetMin = "2.3 -20", OffsetMax = "42.3 20" }
}
});
AddInterface(RB_MAIN, container.ToJson());
}
container.Add(new CuiPanel
{
CursorEnabled = false,
Image = { Color = _uiSettings.ProgressBarMainColor, FadeIn =
_fade },
RectTransform ={ AnchorMin = "0 0.5", AnchorMax = "0 0.5",
OffsetMin = "0 -1.66", OffsetMax = "%left% 1.66" }
},RB_PROGRESS_BAR,RB_PROGRESS);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5",
OffsetMin = "-46.03 -12.24", OffsetMax = "83.97 5.46" },
Text = { Text = "%TimeLeft%", Font = "robotocondensed-
regular.ttf", FontSize = 10, Align = TextAnchor.MiddleRight, Color =
_uiSettings.SecondaryTextColor, FadeIn = _fade}
}, RB_MAIN, RB_PROGRESS_TIMER);
AddInterface(RB_PROGRESS_BAR, container.ToJson());
}
#endregion
}
#endregion
#region ImageLoader
public ImageUI()
{
_paths = Instance.Name + "/Images/";
_printPath = "data/" + _paths;
_images = new Dictionary<string, ImageData>
{
{ "RB_FON0", new ImageData() },
{ "RB_FON1", new ImageData() },
{ "RB_FON2", new ImageData() },
{ "RB_VARIANT0_ICON", new ImageData() },
{ "RB_VARIANT1_ICON_FON", new ImageData() },
{ "RB_VARIANT1_ICON", new ImageData() },
{ "RB_VARIANT2_ICON", new ImageData() },
};
}
if (image != null)
{
ServerMgr.Instance.StartCoroutine(ProcessDownloadImage(image.Value));
}
else
{
List<string> failedImages = new List<string>();
if (failedImages.Count > 0)
{
string images = string.Join(", ",
failedImages);
Instance.PrintError(LanguageEn
? $"Failed to load the following images:
{images}. Perhaps you did not upload them to the '{_printPath}' folder."
: $"Не удалось загрузить следующие
изображения: {images}. Возможно, вы не загрузили их в папку '{_printPath}'.");
Interface.Oxide.UnloadPlugin(Instance.Name);
}
else
{
Instance.Puts(LanguageEn
? $"{_images.Count} images downloaded
successfully!"
: $"{_images.Count} изображений успешно
загружено!");
FileStorage.server.Remove(uint.Parse(item.Value.Id), FileStorage.Type.png,
CommunityEntity.ServerInstance.net.ID);
_images?.Clear();
}
if (www.result is UnityWebRequest.Result.ConnectionError or
UnityWebRequest.Result.ProtocolError)
{
image.Value.Status = ImageStatus.Failed;
}
else
{
Texture2D tex = DownloadHandlerTexture.GetContent(www);
image.Value.Id = FileStorage.server.Store(tex.EncodeToPNG(),
FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID).ToString();
image.Value.Status = ImageStatus.Loaded;
UnityEngine.Object.DestroyImmediate(tex);
}
DownloadImage();
}
}
#endregion
}
}
namespace Oxide.Plugins.RaidBlockExt
{
public static class ExtensionMethods
{
private static readonly Lang Lang = Interface.Oxide.GetLibrary<Lang>();
#region GetLang
#endregion
#region TimeFormat
#endregion
}
}