148 lines
5.3 KiB
C#
148 lines
5.3 KiB
C#
internal class XUiC_SelectClassRebirth : XUiController
|
|
{
|
|
private static float uiCheck = 0f;
|
|
public float uiTick = 0.5f;
|
|
public XUiV_Sprite classIcon;
|
|
public XUiV_Label className;
|
|
public XUiV_Label classDescription;
|
|
|
|
public XUiV_Texture imagePreview;
|
|
private XUiC_ComboBoxList<string> cbxTargetSelectClass;
|
|
|
|
public string ModsBasePath = GameIO.GetUserGameDataDir() + "/Mods";
|
|
public string ModsBasePathLegacy = Application.platform != UnityEngine.RuntimePlatform.OSXPlayer ? (Application.dataPath + "/../Mods") : (Application.dataPath + "/../../Mods");
|
|
public string imagePath = "";
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
((XUiC_SimpleButton)GetChildById("btnConfirm")).OnPressed += BtnConfirm_OnPressed;
|
|
|
|
classIcon = (XUiV_Sprite)GetChildById("classImage").ViewComponent;
|
|
className = (XUiV_Label)GetChildById("className").ViewComponent;
|
|
classDescription = (XUiV_Label)GetChildById("descriptionClass").ViewComponent;
|
|
|
|
this.cbxTargetSelectClass = (base.GetChildById("cbxSelectClass") as XUiC_ComboBoxList<string>);
|
|
if (this.cbxTargetSelectClass != null)
|
|
{
|
|
this.cbxTargetSelectClass.Elements.Add("None");
|
|
this.cbxTargetSelectClass.Elements.Add("Hunter");
|
|
this.cbxTargetSelectClass.Elements.Add("Thug");
|
|
this.cbxTargetSelectClass.Elements.Add("Butcher");
|
|
this.cbxTargetSelectClass.Elements.Add("Soldier");
|
|
this.cbxTargetSelectClass.Elements.Add("Technogeek");
|
|
this.cbxTargetSelectClass.Elements.Add("Madman");
|
|
this.cbxTargetSelectClass.Elements.Add("Builder");
|
|
this.cbxTargetSelectClass.Elements.Add("Sous-Chef");
|
|
this.cbxTargetSelectClass.Elements.Add("Witch Doctor");
|
|
this.cbxTargetSelectClass.Elements.Add("Berserker");
|
|
this.cbxTargetSelectClass.OnValueChanged += this.cbxTargetSelectClass_OnValueChanged;
|
|
}
|
|
}
|
|
|
|
private void cbxTargetSelectClass_OnValueChanged(XUiController _sender, string _oldValue, string _newValue)
|
|
{
|
|
changeValue();
|
|
}
|
|
|
|
public override void Update(float _dt)
|
|
{
|
|
base.Update(_dt);
|
|
|
|
if ((Time.time - uiCheck) > uiTick)
|
|
{
|
|
uiCheck = Time.time;
|
|
}
|
|
}
|
|
|
|
public override void OnOpen()
|
|
{
|
|
if (Directory.Exists(ModsBasePathLegacy + "/zzz_REBIRTH__Utils"))
|
|
{
|
|
imagePath = ModsBasePathLegacy + "/zzz_REBIRTH__Utils" + "/Resources/Previews/";
|
|
}
|
|
else
|
|
{
|
|
imagePath = ModsBasePath + "/zzz_REBIRTH__Utils" + "/Resources/Previews/";
|
|
}
|
|
|
|
cbxTargetSelectClass.SelectedIndex = 0;
|
|
|
|
changeValue();
|
|
|
|
base.OnOpen();
|
|
}
|
|
|
|
private void BtnConfirm_OnPressed(XUiController _sender, int _mouseButton)
|
|
{
|
|
if (!CheckQuestState())
|
|
{
|
|
CloseSelf();
|
|
return;
|
|
}
|
|
|
|
string classIdentifier = cbxTargetSelectClass.Value.Replace(" ", "").Replace("Sous-", "");
|
|
|
|
if (classIdentifier != "None")
|
|
{
|
|
Quest quest = QuestClass.CreateQuest("quest_BasicSurvival_" + classIdentifier);
|
|
base.xui.playerUI.entityPlayer.Buffs.SetCustomVar("$FR_SelectedClass", RebirthUtilities.GetIDFromClassName(classIdentifier));
|
|
base.xui.playerUI.entityPlayer.QuestJournal.AddQuest(quest);
|
|
xui.playerUI.entityPlayer.Buffs.SetCustomVar("$FR_InitialClassChosen", 1f);
|
|
CloseSelf();
|
|
}
|
|
}
|
|
|
|
public override void OnClose()
|
|
{
|
|
//Log.Out("XUiC_SelectClassRebirth-OnClose START");
|
|
if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog"))
|
|
xui.playerUI.windowManager.Close("dialog");
|
|
base.OnClose();
|
|
}
|
|
|
|
private void changeValue()
|
|
{
|
|
string classIdentifier = cbxTargetSelectClass.Value.Replace(" ", "").Replace("Sous-", "");
|
|
|
|
classDescription.Text = Localization.Get("xuiClassDescription" + classIdentifier);
|
|
className.Text = Localization.Get("xuiClassName" + classIdentifier);
|
|
classIcon.SpriteName = "Class" + classIdentifier;
|
|
|
|
if (classIdentifier != "None")
|
|
{
|
|
((XUiC_SimpleButton)GetChildById("btnConfirm")).Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
((XUiC_SimpleButton)GetChildById("btnConfirm")).Enabled = false;
|
|
}
|
|
}
|
|
|
|
bool CheckQuestState()
|
|
{
|
|
var prereqQuest = xui.playerUI.entityPlayer.QuestJournal.FindQuest("quest_basicsurvival_3");
|
|
if (prereqQuest == null)
|
|
{
|
|
GameManager.ShowTooltip(xui.playerUI.entityPlayer, Localization.Get("ttPrereqClassUninitiated"), string.Empty, "ui_denied");
|
|
return false;
|
|
}
|
|
if (prereqQuest.CurrentState != Quest.QuestState.Completed)
|
|
{
|
|
GameManager.ShowTooltip(xui.playerUI.entityPlayer, Localization.Get("ttPrereqClassIncomplete"), string.Empty, "ui_denied");
|
|
return false;
|
|
}
|
|
if ((int)xui.playerUI.entityPlayer.Buffs.GetCustomVar("$FR_InitialClassChosen", 0f) > 0)
|
|
{
|
|
GameManager.ShowTooltip(xui.playerUI.entityPlayer, Localization.Get("ttInitialClassChosen"), string.Empty, "ui_denied");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void CloseSelf()
|
|
{
|
|
xui.playerUI.windowManager.Close(windowGroup.ID);
|
|
}
|
|
} |