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

93 lines
3.1 KiB
C#

internal class ChangeSurvivorNameRebirth : XUiController
{
public XUiV_Label Label;
public XUiV_Panel Panel;
public XUiC_TextInput txtInput;
public override void Init()
{
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;
Label = (XUiV_Label)Panel.Controller.GetChildById("Label").ViewComponent;
txtInput = (XUiC_TextInput)this.windowGroup.Controller.GetChildById("txtInput");
}
public override void OnOpen()
{
EntityPlayer player = xui.playerUI.entityPlayer;
var entityID = 0;
if (player.Buffs.HasCustomVar("CurrentNPC"))
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
if (entityID == 0)
return;
var myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
if (myEntity != null)
{
Label.Text = string.Format(Localization.Get("ttChangeName"), myEntity.EntityName);
txtInput.Text = myEntity.EntityName;
}
base.OnOpen();
}
private void BtnConfirm_OnPressed(XUiController _sender, int _mouseButton)
{
EntityPlayer player = xui.playerUI.entityPlayer;
if (txtInput.Text.Trim() == "")
{
return;
}
var entityID = 0;
if (player.Buffs.HasCustomVar("CurrentNPC"))
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
if (entityID == 0)
{
return;
}
var myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
if (myEntity != null)
{
//Log.Out("ChangeSurvivorNameRebirth-BtnConfirm_OnPressed BEFORE: " + txtInput.Text.Trim());
string newName = txtInput.Text.Trim() + "REBIRTHREBIRTH";
myEntity.NewName = newName.Trim();
myEntity._strMyName = newName.Trim();
myEntity.SetEntityName(newName.Trim());
if (myEntity.NavObject != null)
{
myEntity.NavObject.name = txtInput.Text.Trim();
}
else
{
myEntity.NavObject = NavObjectManager.Instance.RegisterNavObject(EntityClass.list[myEntity.entityClass].NavObject, myEntity, "", false);
myEntity.NavObject.name = txtInput.Text.Trim();
}
//Log.Out("ChangeSurvivorNameRebirth-BtnConfirm_OnPressed AFTER: " + myEntity.EntityName + " / " + myEntity.NavObject.DisplayName + " / " + myEntity._strMyName);
}
xui.playerUI.windowManager.Close(windowGroup.ID);
}
private void BtnCancel_OnPressed(XUiController _sender, int _mouseButton)
{
Panel.IsVisible = false;
xui.playerUI.windowManager.Close(windowGroup.ID);
}
public override void OnClose()
{
if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog"))
xui.playerUI.windowManager.Close("dialog");
base.OnClose();
}
}