Upload from upload_mods.ps1
This commit is contained in:
447
Scripts/XUIC/XUiC_VehicleFrameWindowRebirth.cs
Normal file
447
Scripts/XUIC/XUiC_VehicleFrameWindowRebirth.cs
Normal file
@@ -0,0 +1,447 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class XUiC_VehicleFrameWindowRebirth : XUiC_AssembleWindow
|
||||
{
|
||||
public XUiC_VehicleWindowGroupRebirth group;
|
||||
private bool RefuelButtonHovered;
|
||||
private XUiV_Button btnSiphon_Background;
|
||||
private XUiV_Button btnRepair_Background;
|
||||
private XUiV_Button btnRefuel_Background;
|
||||
private XUiV_Button btnAutoLoot_Background;
|
||||
private XUiV_Button btnTopUpOil_Background;
|
||||
private EntityVehicleRebirth vehicle;
|
||||
private readonly CachedStringFormatter<string, string> vehicleNameQualityFormatter = new CachedStringFormatter<string, string>((_s1, _s2) => string.Format(_s1, _s2));
|
||||
private readonly CachedStringFormatterInt vehicleQualityFormatter = new CachedStringFormatterInt();
|
||||
private readonly CachedStringFormatterXuiRgbaColor vehicleQualityColorFormatter = new CachedStringFormatterXuiRgbaColor();
|
||||
private readonly CachedStringFormatter<int, int> vehicleDurabilityFormatter = new CachedStringFormatter<int, int>((_i1, _i2) => string.Format("{0}/{1}", _i1, _i2));
|
||||
private readonly CachedStringFormatterInt speedFormatter = new CachedStringFormatterInt();
|
||||
private readonly CachedStringFormatterInt protectionFormatter = new CachedStringFormatterInt();
|
||||
private readonly CachedStringFormatterInt fuelFormatter = new CachedStringFormatterInt();
|
||||
private readonly CachedStringFormatterInt passengersFormatter = new CachedStringFormatterInt();
|
||||
private readonly CachedStringFormatterFloat potentialFuelFillFormatter = new CachedStringFormatterFloat();
|
||||
private readonly CachedStringFormatterFloat fuelFillFormatter = new CachedStringFormatterFloat();
|
||||
private bool activeKeyDown;
|
||||
private bool wasReleased;
|
||||
|
||||
public EntityVehicleRebirth Vehicle
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.vehicle;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.vehicle = value;
|
||||
this.RefreshBindings();
|
||||
this.isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
XUiController childById = base.GetChildById("btnSiphon");
|
||||
if (childById != null)
|
||||
{
|
||||
this.btnSiphon_Background = (XUiV_Button)childById.GetChildById("clickable").ViewComponent;
|
||||
this.btnSiphon_Background.Controller.OnPress += new XUiEvent_OnPressEventHandler(this.BtnSiphon_OnPress);
|
||||
}
|
||||
|
||||
XUiController childById1 = this.GetChildById("btnRepair");
|
||||
if (childById1 != null)
|
||||
{
|
||||
this.btnRepair_Background = (XUiV_Button)childById1.GetChildById("clickable").ViewComponent;
|
||||
this.btnRepair_Background.Controller.OnPress += new XUiEvent_OnPressEventHandler(this.BtnRepair_OnPress);
|
||||
}
|
||||
|
||||
XUiController childById2 = this.GetChildById("btnTopUpOil");
|
||||
if (childById2 != null)
|
||||
{
|
||||
this.btnTopUpOil_Background = (XUiV_Button)childById2.GetChildById("clickable").ViewComponent;
|
||||
this.btnTopUpOil_Background.Controller.OnPress += new XUiEvent_OnPressEventHandler(this.BtnTopUpOil_OnPress);
|
||||
}
|
||||
|
||||
XUiController childById3 = this.GetChildById("btnAutoLoot");
|
||||
if (childById3 != null)
|
||||
{
|
||||
this.btnAutoLoot_Background = (XUiV_Button)childById3.GetChildById("clickable").ViewComponent;
|
||||
this.btnAutoLoot_Background.Controller.OnPress += new XUiEvent_OnPressEventHandler(this.BtnAutoLoot_OnPress);
|
||||
}
|
||||
|
||||
XUiController childById4 = this.GetChildById("btnRefuel");
|
||||
if (childById4 == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.btnRefuel_Background = (XUiV_Button)childById4.GetChildById("clickable").ViewComponent;
|
||||
this.btnRefuel_Background.Controller.OnPress += new XUiEvent_OnPressEventHandler(this.BtnRefuel_OnPress);
|
||||
this.btnRefuel_Background.Controller.OnHover += new XUiEvent_OnHoverEventHandler(this.btnRefuel_OnHover);
|
||||
}
|
||||
|
||||
private void BtnSiphon_OnPress(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnSiphon_OnPress START");
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnSiphon_OnPress this.Vehicle.vehicle.GetFuelPercent(): " + this.Vehicle.vehicle.GetFuelPercent());
|
||||
if (this.Vehicle.vehicle.GetFuelPercent() > 0f)
|
||||
{
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnSiphon_OnPress 1");
|
||||
if ((Vehicle != null && !this.Vehicle.GetVehicle().HasEnginePart()))
|
||||
{
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnSiphon_OnPress 2");
|
||||
return;
|
||||
}
|
||||
|
||||
float fuelLevel = this.Vehicle.vehicle.GetFuelLevel() * 25;
|
||||
|
||||
int numGas = Mathf.RoundToInt(fuelLevel);
|
||||
|
||||
ItemStack gas = new ItemStack(ItemClass.GetItem("ammoGasCan"), numGas);
|
||||
LocalPlayerUI.GetUIForPlayer(_sender.xui.playerUI.entityPlayer).entityPlayer.AddUIHarvestingItem(gas, true);
|
||||
|
||||
RebirthUtilities.addToPlayerBag(ItemClass.GetItem("ammoGasCan"), _sender.xui.playerUI.entityPlayer, numGas, "useactions/gas_refill");
|
||||
|
||||
this.xui.vehicle.vehicle.SetFuelLevel(0f);
|
||||
base.RefreshBindings(true);
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnRepair_OnPress(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnRepair_OnPress Vehicle.bodyDurability: " + Vehicle.bodyDurability);
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnRepair_OnPress Vehicle.maxBodyDurability: " + Vehicle.maxBodyDurability);
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnRepair_OnPress Vehicle.Health: " + Vehicle.Health);
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-BtnRepair_OnPress Vehicle.GetMaxHealth(): " + Vehicle.GetMaxHealth());
|
||||
|
||||
if (Vehicle.Health < Vehicle.GetMaxHealth() && RebirthUtilities.useInventoryBagItem(xui.playerUI.entityPlayer, "resourceRepairKit", 1))
|
||||
{
|
||||
float health = Vehicle.Health + 2500f;
|
||||
|
||||
if (health > Vehicle.GetMaxHealth())
|
||||
{
|
||||
health = Vehicle.GetMaxHealth();
|
||||
}
|
||||
|
||||
vehicle.Health = (int)health;
|
||||
//Vehicle.AddHealth(5000 - Mathf.RoundToInt(Vehicle.bodyDurability));
|
||||
//Vehicle.bodyDurability = health;
|
||||
|
||||
Vehicle.PlayOneShot("craft_complete_item", false);
|
||||
|
||||
RefreshBindings();
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnAutoLoot_OnPress(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
string optionQoL = RebirthVariables.customQualityOfLife;
|
||||
|
||||
if (optionQoL == "none" || optionQoL == "quickstackonly")
|
||||
{
|
||||
EntityPlayerLocal primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
||||
|
||||
if (primaryPlayer != null)
|
||||
{
|
||||
GameManager.ShowTooltip(primaryPlayer, Localization.Get("xuiFeatureOff"), string.Empty, "ui_denied", null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.vehicle != null)
|
||||
{
|
||||
EntityPlayerLocal primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
||||
|
||||
if (primaryPlayer != null)
|
||||
{
|
||||
ProgressionValue progressionValue = primaryPlayer.Progression.GetProgressionValue("perkPackMule");
|
||||
|
||||
if (RebirthUtilities.GetCalculatedLevel(primaryPlayer, progressionValue) >= 4)
|
||||
{
|
||||
float isAutoLootOn = this.vehicle.Buffs.GetCustomVar("$autoLoot");
|
||||
|
||||
if (isAutoLootOn == 0)
|
||||
{
|
||||
this.vehicle.Buffs.SetCustomVar("$autoLoot", 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.vehicle.Buffs.SetCustomVar("$autoLoot", 0f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.vehicle.Buffs.SetCustomVar("$autoLoot", 0f);
|
||||
GameManager.ShowTooltip(primaryPlayer, Localization.Get("xuiAutoLootDenied"), string.Empty, "ui_denied", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RefreshBindings();
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
private void BtnTopUpOil_OnPress(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
if (Vehicle.OilPerc < 1f)
|
||||
{
|
||||
if (RebirthUtilities.useInventoryBagItem(xui.playerUI.entityPlayer, "resourceOil", 1))
|
||||
{
|
||||
Vehicle.OilPerc += 0.25f;
|
||||
Vehicle.OilPerc = Mathf.Clamp01(Vehicle.OilPerc);
|
||||
|
||||
xui.playerUI.entityPlayer.PlayOneShot("useactions/gas_refill", false);
|
||||
|
||||
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
||||
{
|
||||
int playerID = this.xui.playerUI.entityPlayer.entityId;
|
||||
int currentVehicleID = vehicle.entityId;
|
||||
|
||||
NetPackageVehicleUpdateStatsRebirth package = NetPackageManager.GetPackage<NetPackageVehicleUpdateStatsRebirth>().Setup(playerID, currentVehicleID, Vehicle.OilPerc);
|
||||
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(package, false);
|
||||
}
|
||||
|
||||
this.RefreshBindings();
|
||||
isDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RebirthUtilities.notifyMissingItem(ItemClass.GetItem("resourceOil"), this.xui.playerUI.entityPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnRefuel_OnHover(XUiController _sender, bool _isOver)
|
||||
{
|
||||
if (Vehicle != null && !this.Vehicle.GetVehicle().HasEnginePart())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.RefuelButtonHovered = _isOver;
|
||||
this.RefreshBindings();
|
||||
}
|
||||
|
||||
private void BtnRefuel_OnPress(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
if (this.Vehicle.vehicle.GetFuelPercent() < 1f)
|
||||
{
|
||||
if (!RebirthUtilities.hasItem(ItemClass.GetItem("ammoGasCan"), this.xui.playerUI.entityPlayer))
|
||||
{
|
||||
RebirthUtilities.notifyMissingItem(ItemClass.GetItem("ammoGasCan"), this.xui.playerUI.entityPlayer);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((Vehicle != null && !this.Vehicle.GetVehicle().HasEnginePart()) || !this.xui.vehicle.AddFuelFromInventory(xui.playerUI.entityPlayer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.RefreshBindings();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool GetBindingValue(ref string value, string bindingName)
|
||||
{
|
||||
global::Vehicle vehicle = (UnityEngine.Object)this.vehicle != (UnityEngine.Object)null ? this.vehicle.GetVehicle() : (global::Vehicle)null;
|
||||
switch (bindingName)
|
||||
{
|
||||
case "oil":
|
||||
if (this.Vehicle != null)
|
||||
{
|
||||
value = ((int)(this.Vehicle.OilPerc * 100)).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "N/A";
|
||||
}
|
||||
|
||||
return true;
|
||||
case "oiltitle":
|
||||
value = Localization.Get("xuiOil");
|
||||
return true;
|
||||
case "bodydurability":
|
||||
if (this.Vehicle != null)
|
||||
{
|
||||
value = ((int)this.Vehicle.bodyDurability).ToString() + "/" + ((int)this.Vehicle.maxBodyDurability).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "N/A";
|
||||
}
|
||||
|
||||
return true;
|
||||
case "bodydurabilitytitle":
|
||||
value = Localization.Get("xuiBodyDurability");
|
||||
return true;
|
||||
case "fuel":
|
||||
value = this.fuelFormatter.Format((int)XUiM_Vehicle.GetFuelLevel(this.xui));
|
||||
return true;
|
||||
case "fuelfill":
|
||||
value = this.fuelFillFormatter.Format(XUiM_Vehicle.GetFuelFill(this.xui));
|
||||
return true;
|
||||
case "fueltitle":
|
||||
value = Localization.Get("xuiGas");
|
||||
return true;
|
||||
case "locktype":
|
||||
value = Localization.Get("none");
|
||||
return true;
|
||||
case "noise":
|
||||
value = XUiM_Vehicle.GetNoise(this.xui);
|
||||
return true;
|
||||
case "noisetitle":
|
||||
value = Localization.Get("xuiNoise");
|
||||
return true;
|
||||
case "passengers":
|
||||
value = this.passengersFormatter.Format(XUiM_Vehicle.GetPassengers(xui));
|
||||
return true;
|
||||
case "passengerstitle":
|
||||
value = Localization.Get("xuiSeats");
|
||||
return true;
|
||||
case "potentialfuelfill":
|
||||
value = this.RefuelButtonHovered ? this.potentialFuelFillFormatter.Format(vehicle.GetFuelPercent()) : "0";
|
||||
return true;
|
||||
case "protection":
|
||||
value = this.protectionFormatter.Format((int)XUiM_Vehicle.GetProtection(this.xui));
|
||||
return true;
|
||||
case "protectiontitle":
|
||||
value = Localization.Get("xuiDefense");
|
||||
return true;
|
||||
case "refueltext":
|
||||
value = !(Vehicle != null) || !this.Vehicle.GetVehicle().HasEnginePart() ? Localization.Get("xuiRefuelNotAllowed") : Localization.Get("xuiRefuel");
|
||||
return true;
|
||||
case "showfuel":
|
||||
value = (Vehicle != null && this.Vehicle.GetVehicle().HasEnginePart()).ToString();
|
||||
return true;
|
||||
case "speed":
|
||||
value = this.speedFormatter.Format((int)XUiM_Vehicle.GetSpeed(this.xui));
|
||||
return true;
|
||||
case "speedtext":
|
||||
value = XUiM_Vehicle.GetSpeedText(this.xui);
|
||||
return true;
|
||||
case "speedtitle":
|
||||
value = Localization.Get("xuiSpeed");
|
||||
return true;
|
||||
case "storage":
|
||||
value = "BASKET";
|
||||
return true;
|
||||
case "vehicledurability":
|
||||
value = vehicle != null ? this.vehicleDurabilityFormatter.Format(vehicle.entity.Health, vehicle.GetMaxHealth()) : "";
|
||||
return true;
|
||||
case "vehicledurabilitytitle":
|
||||
value = Localization.Get("xuiDurability");
|
||||
return true;
|
||||
case "vehicleicon":
|
||||
value = this.vehicle != null ? this.vehicle.GetMapIcon() : "";
|
||||
return true;
|
||||
case "vehiclename":
|
||||
value = Localization.Get(XUiM_Vehicle.GetEntityName(this.xui));
|
||||
return true;
|
||||
case "vehiclenamequality":
|
||||
value = "";
|
||||
return true;
|
||||
case "vehiclequality":
|
||||
value = "";
|
||||
return true;
|
||||
case "vehiclequalitycolor":
|
||||
if (this.vehicle != null)
|
||||
{
|
||||
Color32 qualityColor = (Color32)QualityInfo.GetQualityColor(vehicle.GetVehicleQuality());
|
||||
value = this.vehicleQualityColorFormatter.Format(qualityColor);
|
||||
}
|
||||
|
||||
return true;
|
||||
case "vehiclequalitytitle":
|
||||
value = "";
|
||||
return true;
|
||||
case "vehiclestatstitle":
|
||||
value = Localization.Get("xuiStats");
|
||||
return true;
|
||||
case "autoLootColor":
|
||||
if (this.vehicle != null)
|
||||
{
|
||||
float isAutoLootOn = this.vehicle.Buffs.GetCustomVar("$autoLoot");
|
||||
|
||||
if (isAutoLootOn == 1f)
|
||||
{
|
||||
value = "54, 97, 40";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
value = "97, 40, 40";
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float _dt)
|
||||
{
|
||||
if (this.isDirty)
|
||||
{
|
||||
this.btnRefuel_Background.Enabled = Vehicle != null && this.Vehicle.GetVehicle().HasEnginePart();
|
||||
}
|
||||
|
||||
if (this.windowGroup.isShowing)
|
||||
{
|
||||
if (!base.xui.playerUI.playerInput.PermanentActions.Activate.IsPressed)
|
||||
{
|
||||
this.wasReleased = true;
|
||||
}
|
||||
|
||||
if (this.wasReleased)
|
||||
{
|
||||
if (base.xui.playerUI.playerInput.PermanentActions.Activate.IsPressed)
|
||||
{
|
||||
this.activeKeyDown = true;
|
||||
}
|
||||
|
||||
if (base.xui.playerUI.playerInput.PermanentActions.Activate.WasReleased && this.activeKeyDown)
|
||||
{
|
||||
this.activeKeyDown = false;
|
||||
base.xui.playerUI.windowManager.CloseAllOpenWindows(null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.Update(_dt);
|
||||
}
|
||||
|
||||
public override void OnOpen()
|
||||
{
|
||||
base.OnOpen();
|
||||
this.isDirty = true;
|
||||
}
|
||||
|
||||
public override void OnClose()
|
||||
{
|
||||
this.wasReleased = false;
|
||||
this.activeKeyDown = false;
|
||||
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
public override ItemStack ItemStack
|
||||
{
|
||||
set
|
||||
{
|
||||
this.vehicle.GetVehicle().SetItemValueMods(value.itemValue);
|
||||
base.ItemStack = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChanged()
|
||||
{
|
||||
//Log.Out("XUiC_VehicleFrameWindowRebirth-OnChanged this.ItemStack.count:" + this.ItemStack.count);
|
||||
|
||||
this.group = base.GetParentByType<XUiC_VehicleWindowGroupRebirth>();
|
||||
|
||||
this.group.OnItemChanged(this.ItemStack);
|
||||
this.isDirty = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user