123 lines
3.8 KiB
C#
123 lines
3.8 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using static RebirthManager;
|
|
|
|
internal class XUiC_ManageNPCs : XUiController
|
|
{
|
|
private static float uiCheck = 0f;
|
|
public float uiTick = 0.5f;
|
|
|
|
public XUiV_Label LabelDescription;
|
|
public XUiV_Panel Panel;
|
|
|
|
private EntityPlayerLocal _player;
|
|
|
|
private List<XUiC_HiredNPC> entryList = new List<XUiC_HiredNPC>();
|
|
|
|
public override void Init()
|
|
{
|
|
//Log.Out("XUiC_ManageNPCs-Init START");
|
|
base.Init();
|
|
Panel = (XUiV_Panel)GetChildById("Popup").ViewComponent;
|
|
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnCancel")).OnPressed += BtnCancel_OnPressed;
|
|
|
|
LabelDescription = (XUiV_Label)Panel.Controller.GetChildById("lblDescription").ViewComponent;
|
|
}
|
|
|
|
public override void Update(float _dt)
|
|
{
|
|
base.Update(_dt);
|
|
|
|
if ((Time.time - uiCheck) > uiTick)
|
|
{
|
|
uiCheck = Time.time;
|
|
//Log.Out("XUiC_ManageNPCs-Update 1");
|
|
}
|
|
}
|
|
|
|
public override void OnOpen()
|
|
{
|
|
//Log.Out("XUiC_ManageNPCs-OnOpen START");
|
|
base.OnOpen();
|
|
_player = xui.playerUI.entityPlayer;
|
|
if (_player == null)
|
|
{
|
|
OnClose();
|
|
return;
|
|
}
|
|
RefreshHires();
|
|
}
|
|
|
|
private void RefreshHires()
|
|
{
|
|
//Log.Out("XUiC_ManageNPCs-RefreshCompanions START");
|
|
|
|
var childrenByType = GetChildrenByType<XUiC_HiredNPC>(null);
|
|
foreach (var t in childrenByType)
|
|
{
|
|
t.ViewComponent.IsVisible = false;
|
|
entryList.Add(t);
|
|
}
|
|
|
|
//Log.Out("XUiC_ManageNPCs-RefreshCompanions entryList.Count: " + entryList.Count);
|
|
|
|
foreach (var t in entryList)
|
|
{
|
|
t.SetCompanion(null);
|
|
t.ViewComponent.IsVisible = false;
|
|
}
|
|
|
|
var j = 0;
|
|
|
|
foreach (hireInfo hire in playerHires)
|
|
{
|
|
if (hire.playerID == _player.entityId)
|
|
{
|
|
EntityNPCRebirth hiredNPC = GameManager.Instance.World.GetEntity(hire.hireID) as EntityNPCRebirth;
|
|
|
|
if (hiredNPC != null
|
|
)
|
|
{
|
|
//Log.Out("XUiC_ManageNPCs-RefreshCompanions hiredNPC: " + hiredNPC.EntityClass.entityClassName);
|
|
if (!hiredNPC.EntityClass.Tags.Test_AnySet(FastTags<TagGroup.Global>.Parse("temp")) && j <= entryList.Count - 1)
|
|
{
|
|
entryList[j].name = hire.name;
|
|
entryList[j].EntityID = hire.hireID;
|
|
entryList[j].position = hire.spawnPosition;
|
|
entryList[j].SetCompanion(hiredNPC);
|
|
entryList[j].ViewComponent.IsVisible = true;
|
|
j++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
entryList[j].name = hire.name;
|
|
entryList[j].EntityID = hire.hireID;
|
|
entryList[j].position = hire.spawnPosition;
|
|
entryList[j].ViewComponent.IsVisible = true;
|
|
j++;
|
|
}
|
|
}
|
|
}
|
|
//Log.Out("XUiC_ManageNPCs-RefreshCompanions num hires: " + j);
|
|
}
|
|
|
|
private void BtnCancel_OnPressed(XUiController _sender, int _mouseButton)
|
|
{
|
|
//Log.Out("XUiC_ManageNPCs-BtnCancel_OnPressed START");
|
|
/*Panel.IsVisible = false;
|
|
entryList.Clear();
|
|
xui.playerUI.windowManager.Close(windowGroup.ID);*/
|
|
OnClose();
|
|
}
|
|
|
|
public override void OnClose()
|
|
{
|
|
//Log.Out("XUiC_ManageNPCs-OnClose START");
|
|
if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog"))
|
|
xui.playerUI.windowManager.Close("dialog");
|
|
entryList.Clear();
|
|
base.OnClose();
|
|
}
|
|
} |