Files
zzz_REBIRTH__Utils/Scripts/XUIC/XUiC_TradeDNABlueprintsRebirth.cs
2025-06-04 16:44:53 +09:30

318 lines
13 KiB
C#

internal class XUiC_TradeDNABlueprintsRebirth : XUiController
{
private static float uiCheck = 0f;
public float uiTick = 0.5f;
public float barterPerc = 0f;
public XUiV_Label LabelTotal;
private XUiC_ComboBoxList<string> cbxTargetDNABlueprintsType;
public XUiC_ComboBoxInt comboStrength;
public XUiC_ComboBoxInt comboDexterity;
public XUiC_ComboBoxInt comboConstitution;
public XUiC_ComboBoxInt comboIntelligence;
public XUiC_ComboBoxInt comboCharisma;
public XUiV_Label Resource;
public XUiV_Label ResourceMultiplier;
public XUiV_Label GatherType;
public XUiV_Label LabelDescription;
public XUiV_Panel Panel;
public XUiV_Sprite spriteDNABlueprintImage;
public override void Init()
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-Init START");
base.Init();
Panel = (XUiV_Panel)GetChildById("Popup").ViewComponent;
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnCancel")).OnPressed += BtnCancel_OnPressed;
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnConfirm")).OnPressed += BtnConfirm_OnPressed;
spriteDNABlueprintImage = (XUiV_Sprite)GetChildById("DNABlueprintsImage").ViewComponent;
LabelTotal = (XUiV_Label)Panel.Controller.GetChildById("lblTotal").ViewComponent;
LabelDescription = (XUiV_Label)Panel.Controller.GetChildById("lblDescription").ViewComponent;
LabelTotal.Enabled = false;
this.cbxTargetDNABlueprintsType = (base.GetChildById("cbxDNABlueprintsType") as XUiC_ComboBoxList<string>);
if (this.cbxTargetDNABlueprintsType != null)
{
this.cbxTargetDNABlueprintsType.Elements.Add("Strength");
this.cbxTargetDNABlueprintsType.Elements.Add("Dexterity");
this.cbxTargetDNABlueprintsType.Elements.Add("Constitution");
this.cbxTargetDNABlueprintsType.Elements.Add("Intelligence");
this.cbxTargetDNABlueprintsType.Elements.Add("Charisma");
this.cbxTargetDNABlueprintsType.OnValueChanged += this.cbxTargetDNABlueprintsType_OnValueChanged;
}
comboStrength = GetChildById("cbxStrength").GetChildByType<XUiC_ComboBoxInt>();
comboDexterity = GetChildById("cbxDexterity").GetChildByType<XUiC_ComboBoxInt>();
comboConstitution = GetChildById("cbxConstitution").GetChildByType<XUiC_ComboBoxInt>();
comboIntelligence = GetChildById("cbxIntelligence").GetChildByType<XUiC_ComboBoxInt>();
comboCharisma = GetChildById("cbxCharisma").GetChildByType<XUiC_ComboBoxInt>();
this.comboStrength.OnValueChanged += new XUiC_ComboBox<long>.XUiEvent_ValueChanged(this.comboStrength_OnValueChanged);
this.comboDexterity.OnValueChanged += new XUiC_ComboBox<long>.XUiEvent_ValueChanged(this.comboDexterity_OnValueChanged);
this.comboConstitution.OnValueChanged += new XUiC_ComboBox<long>.XUiEvent_ValueChanged(this.comboConstitution_OnValueChanged);
this.comboIntelligence.OnValueChanged += new XUiC_ComboBox<long>.XUiEvent_ValueChanged(this.comboIntelligence_OnValueChanged);
this.comboCharisma.OnValueChanged += new XUiC_ComboBox<long>.XUiEvent_ValueChanged(this.comboCharisma_OnValueChanged);
}
private void comboStrength_OnValueChanged(XUiController _sender, long _oldValue, long _newValue)
{
EntityPlayer player = xui.playerUI.entityPlayer;
CalculateDNABlueprintsTotal(player);
}
private void comboDexterity_OnValueChanged(XUiController _sender, long _oldValue, long _newValue)
{
EntityPlayer player = xui.playerUI.entityPlayer;
CalculateDNABlueprintsTotal(player);
}
private void comboConstitution_OnValueChanged(XUiController _sender, long _oldValue, long _newValue)
{
EntityPlayer player = xui.playerUI.entityPlayer;
CalculateDNABlueprintsTotal(player);
}
private void comboIntelligence_OnValueChanged(XUiController _sender, long _oldValue, long _newValue)
{
EntityPlayer player = xui.playerUI.entityPlayer;
CalculateDNABlueprintsTotal(player);
}
private void comboCharisma_OnValueChanged(XUiController _sender, long _oldValue, long _newValue)
{
EntityPlayer player = xui.playerUI.entityPlayer;
CalculateDNABlueprintsTotal(player);
}
private void cbxTargetDNABlueprintsType_OnValueChanged(XUiController _sender, string _oldValue, string _newValue)
{
EntityPlayer player = xui.playerUI.entityPlayer;
//Log.Out("XUiC_TradeDNABlueprintsRebirth-XUiC_TradeDNABlueprintsRebirth cbxTargetDNABlueprintsType: " + cbxTargetDNABlueprintsType.Value);
ResetDNABlueprintsCount(player, cbxTargetDNABlueprintsType.Value);
}
public override void Update(float _dt)
{
base.Update(_dt);
if ((Time.time - uiCheck) > uiTick)
{
uiCheck = Time.time;
//Log.Out("XUiC_TradeDNABlueprintsRebirth-Update 1");
}
EntityPlayer player = xui.playerUI.entityPlayer;
}
public override void OnOpen()
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-OnOpen START");
EntityPlayer player = xui.playerUI.entityPlayer;
var entityID = 0;
if (player.Buffs.HasCustomVar("CurrentNPC"))
{
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
//Log.Out("XUiC_TradeDNABlueprintsRebirth-OnOpen 1, entityID: " + entityID);
}
if (entityID == 0)
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-OnOpen 2");
return;
}
float progressionLevel = 0;
ProgressionValue progressionValue = player.Progression.GetProgressionValue("perkBetterBarter");
if (progressionValue != null)
{
progressionLevel = RebirthUtilities.GetCalculatedLevel(player, progressionValue);
}
barterPerc = 0.5f + (progressionLevel * 0.05f);
LabelDescription.Text = Localization.Get("xuiTradeDNABlueprintsDescription").Replace("{0}", ((int)(barterPerc * 100)).ToString() + "%");
//comboStrength.Value = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("geneticBlueprintStrength", false), player); ;
cbxTargetDNABlueprintsType.SelectedIndex = 0;
ResetDNABlueprintsCount(player, "Strength");
base.OnOpen();
}
private void CalculateDNABlueprintsTotal(EntityPlayer player)
{
float total = 0;
string DNABlueprintsType = cbxTargetDNABlueprintsType.Value;
comboStrength.Enabled = true;
comboDexterity.Enabled = true;
comboConstitution.Enabled = true;
comboIntelligence.Enabled = true;
comboCharisma.Enabled = true;
if (DNABlueprintsType == "Strength")
{
comboStrength.Max = 0;
comboStrength.Value = 0;
comboStrength.Enabled = false;
total = (comboDexterity.Value + comboConstitution.Value + comboIntelligence.Value + comboCharisma.Value) * barterPerc;
}
if (DNABlueprintsType == "Dexterity")
{
comboDexterity.Max = 0;
comboDexterity.Value = 0;
comboDexterity.Enabled = false;
total = (comboStrength.Value + comboConstitution.Value + comboIntelligence.Value + comboCharisma.Value) * barterPerc;
}
if (DNABlueprintsType == "Constitution")
{
comboConstitution.Max = 0;
comboConstitution.Value = 0;
comboConstitution.Enabled = false;
total = (comboStrength.Value + comboDexterity.Value + comboIntelligence.Value + comboCharisma.Value) * barterPerc;
}
if (DNABlueprintsType == "Intelligence")
{
comboIntelligence.Max = 0;
comboIntelligence.Value = 0;
comboIntelligence.Enabled = false;
total = (comboStrength.Value + comboDexterity.Value + comboConstitution.Value + comboCharisma.Value) * barterPerc;
}
if (DNABlueprintsType == "Charisma")
{
comboCharisma.Max = 0;
comboCharisma.Value = 0;
comboCharisma.Enabled = false;
total = (comboStrength.Value + comboDexterity.Value + comboConstitution.Value + comboIntelligence.Value) * barterPerc;
}
LabelTotal.Text = ((int)total).ToString();
}
private void ResetDNABlueprintsCount(EntityPlayer player, string DNABlueprintsType)
{
comboStrength.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("geneticBlueprintStrength", false), player);
comboDexterity.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("geneticBlueprintDexterity", false), player);
comboConstitution.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("geneticBlueprintConstitution", false), player);
comboIntelligence.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("geneticBlueprintIntelligence", false), player);
comboCharisma.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("geneticBlueprintCharisma", false), player);
if (DNABlueprintsType == "Strength")
{
comboStrength.Max = 0;
}
if (DNABlueprintsType == "Dexterity")
{
comboDexterity.Max = 0;
}
if (DNABlueprintsType == "Constitution")
{
comboConstitution.Max = 0;
}
if (DNABlueprintsType == "Intelligence")
{
comboIntelligence.Max = 0;
}
if (DNABlueprintsType == "Charisma")
{
comboCharisma.Max = 0;
}
comboStrength.Value = comboStrength.Max;
comboDexterity.Value = comboDexterity.Max;
comboConstitution.Value = comboConstitution.Max;
comboIntelligence.Value = comboIntelligence.Max;
comboCharisma.Value = comboCharisma.Max;
CalculateDNABlueprintsTotal(player);
spriteDNABlueprintImage.SpriteName = "ui_game_symbol_FR_Blueprint" + cbxTargetDNABlueprintsType.Value;
}
private void BtnConfirm_OnPressed(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed START");
int totalReceived = Int32.Parse(LabelTotal.Text);
if (totalReceived == 0)
{
return;
}
EntityPlayer player = xui.playerUI.entityPlayer;
string DNABlueprintsType = cbxTargetDNABlueprintsType.Value;
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed DNABlueprintsType: " + DNABlueprintsType);
string itemTradeFor = "";
int numStrength = (int)(comboStrength.Value);
if (numStrength > 0 && DNABlueprintsType != "Strength")
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed dec Strength: " + numStrength);
RebirthUtilities.DecBagItem(ItemClass.GetItem("geneticBlueprintStrength", false), numStrength, player);
}
int numDexterity = (int)(comboDexterity.Value);
if (numDexterity > 0 && DNABlueprintsType != "Dexterity")
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed dec Dexterity: " + numDexterity);
RebirthUtilities.DecBagItem(ItemClass.GetItem("geneticBlueprintDexterity", false), numDexterity, player);
}
int numConstitution = (int)(comboConstitution.Value);
if (numConstitution > 0 && DNABlueprintsType != "Constitution")
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed dec Constitution: " + numConstitution);
RebirthUtilities.DecBagItem(ItemClass.GetItem("geneticBlueprintConstitution", false), numConstitution, player);
}
int numIntelligence = (int)(comboIntelligence.Value);
if (numIntelligence > 0 && DNABlueprintsType != "Intelligence")
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed dec Intelligence: " + numIntelligence);
RebirthUtilities.DecBagItem(ItemClass.GetItem("geneticBlueprintIntelligence", false), numIntelligence, player);
}
int numCharisma = (int)(comboCharisma.Value);
if (numCharisma > 0 && DNABlueprintsType != "Charisma")
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnConfirm_OnPressed dec Charisma: " + numCharisma);
RebirthUtilities.DecBagItem(ItemClass.GetItem("geneticBlueprintCharisma", false), numCharisma, player);
}
ItemValue itemReceived = ItemClass.GetItem("geneticBlueprint" + DNABlueprintsType, false);
RebirthUtilities.addToPlayerInventory(itemReceived, player, totalReceived);
xui.playerUI.windowManager.Close(windowGroup.ID);
}
private void BtnCancel_OnPressed(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-BtnCancel_OnPressed START");
Panel.IsVisible = false;
xui.playerUI.windowManager.Close(windowGroup.ID);
}
public override void OnClose()
{
//Log.Out("XUiC_TradeDNABlueprintsRebirth-OnClose START");
if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog"))
xui.playerUI.windowManager.Close("dialog");
base.OnClose();
}
}