231 lines
6.7 KiB
C#
231 lines
6.7 KiB
C#
using BrewMonster.Network;
|
|
using BrewMonster.Scripts.Managers;
|
|
using BrewMonster.Scripts.Task;
|
|
using BrewMonster.UI;
|
|
using CSNetwork;
|
|
using ModelRenderer.Scripts.Common;
|
|
using PerfectWorld.Scripts.Managers;
|
|
using PerfectWorld.Scripts.Task;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class DlgInstall : AUIDialog
|
|
{
|
|
[Header("Slot First")]
|
|
[SerializeField] private Transform m_SlotFirstParent;
|
|
[SerializeField] private TextMeshProUGUI m_TxtFirstName;
|
|
|
|
[Header("Slot Second")]
|
|
[SerializeField] private Transform m_SlotSecondlParent;
|
|
[SerializeField] private TextMeshProUGUI m_TxtSecondName;
|
|
|
|
[Header("Buttons and Money")]
|
|
[SerializeField] private TextMeshProUGUI m_TxtMoney;
|
|
[SerializeField] private Button m_BtnInstall;
|
|
[SerializeField] private Button m_BtnCancel;
|
|
|
|
[Header("Item Info Panel")]
|
|
public Transform itemInfoRoot;
|
|
public TextMeshProUGUI infoNameText;
|
|
public TextMeshProUGUI infoDescText;
|
|
public TextMeshProUGUI infoExtraText;
|
|
|
|
private EC_IvtrItem m_SelectedEquip;
|
|
private EC_IvtrItem m_SelectedMaterial;
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
RegisterDrop(m_SlotFirstParent, OnDropEquip);
|
|
RegisterDrop(m_SlotSecondlParent, OnDropMaterial);
|
|
RegisterClick(m_SlotFirstParent, OnClickEquipSlot);
|
|
RegisterClick(m_SlotSecondlParent, OnClickMaterialSlot);
|
|
|
|
// Hide item info panel initially
|
|
if (itemInfoRoot != null)
|
|
itemInfoRoot.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnpenInstall(uint npcId)
|
|
{
|
|
|
|
}
|
|
|
|
public void CloseInstall()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void RegisterDrop(Transform target, Action<PointerEventData> callback)
|
|
{
|
|
var trigger = target.GetComponent<EventTrigger>();
|
|
if (trigger == null)
|
|
trigger = target.gameObject.AddComponent<EventTrigger>();
|
|
|
|
trigger.triggers.Clear();
|
|
|
|
var entry = new EventTrigger.Entry
|
|
{
|
|
eventID = EventTriggerType.Drop
|
|
};
|
|
entry.callback.AddListener((data) =>
|
|
{
|
|
callback((PointerEventData)data);
|
|
});
|
|
|
|
trigger.triggers.Add(entry);
|
|
}
|
|
|
|
private void RegisterClick(Transform target, Action<PointerEventData> callback)
|
|
{
|
|
var trigger = target.GetComponent<EventTrigger>();
|
|
if (trigger == null)
|
|
trigger = target.gameObject.AddComponent<EventTrigger>();
|
|
|
|
var entry = new EventTrigger.Entry
|
|
{
|
|
eventID = EventTriggerType.PointerClick
|
|
};
|
|
entry.callback.AddListener((data) =>
|
|
{
|
|
callback((PointerEventData)data);
|
|
});
|
|
|
|
trigger.triggers.Add(entry);
|
|
}
|
|
|
|
private void OnClickEquipSlot(PointerEventData eventData)
|
|
{
|
|
if (m_SelectedEquip != null)
|
|
{
|
|
ShowItemInfo(m_SelectedEquip);
|
|
}
|
|
}
|
|
|
|
private void OnClickMaterialSlot(PointerEventData eventData)
|
|
{
|
|
if (m_SelectedMaterial != null)
|
|
{
|
|
ShowItemInfo(m_SelectedMaterial);
|
|
}
|
|
}
|
|
|
|
private void ShowItemInfo(EC_IvtrItem item)
|
|
{
|
|
if (item == null || itemInfoRoot == null)
|
|
return;
|
|
|
|
itemInfoRoot.gameObject.SetActive(true);
|
|
|
|
if (infoDescText != null)
|
|
{
|
|
string rawDesc = item.GetDesc();
|
|
|
|
// Process the description: replace \\r with newlines and handle color codes
|
|
string processedDesc = EC_Utility.ProcessColorCodes(new StringBuilder(rawDesc.Replace("\\r", "\n")));
|
|
|
|
infoDescText.text = processedDesc;
|
|
|
|
Debug.Log($"[Install] Raw desc: {rawDesc}");
|
|
Debug.Log($"[Install] Processed desc: {processedDesc}");
|
|
}
|
|
|
|
// Force rebuild layout to ensure proper sizing
|
|
ForceRefreshItemInfoLayout();
|
|
|
|
Debug.Log($"[Install] Showing info for item: {item.GetName()}");
|
|
}
|
|
|
|
private void ForceRefreshItemInfoLayout()
|
|
{
|
|
if (itemInfoRoot == null)
|
|
return;
|
|
|
|
var rt = itemInfoRoot.GetComponent<RectTransform>();
|
|
if (rt != null)
|
|
{
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(rt);
|
|
}
|
|
}
|
|
|
|
private void HideItemInfo()
|
|
{
|
|
if (itemInfoRoot != null)
|
|
itemInfoRoot.gameObject.SetActive(false);
|
|
}
|
|
|
|
private EC_IvtrItem GetItemFromDrag(PointerEventData eventData)
|
|
{
|
|
if (eventData.pointerDrag == null)
|
|
return null;
|
|
|
|
var btn = eventData.pointerDrag.GetComponent<Button>();
|
|
if (btn == null)
|
|
return null;
|
|
|
|
// Slot index
|
|
int slotIndex = btn.transform.GetSiblingIndex();
|
|
|
|
// Inventory package = 0
|
|
var host = CECGameRun.Instance?.GetHostPlayer();
|
|
if (host == null)
|
|
return null;
|
|
|
|
var inv = host.GetInventory(0);
|
|
if (inv == null)
|
|
return null;
|
|
|
|
return inv.GetItem(slotIndex, false);
|
|
}
|
|
|
|
private void OnDropEquip(PointerEventData eventData)
|
|
{
|
|
var item = GetItemFromDrag(eventData);
|
|
if (item == null)
|
|
return;
|
|
|
|
m_SelectedEquip = item;
|
|
m_TxtFirstName.text = item.GetName();
|
|
SetSlotIcon(m_SlotFirstParent, item);
|
|
|
|
Debug.Log($"[Install] Equiment: {item.m_tid}");
|
|
}
|
|
|
|
private void OnDropMaterial(PointerEventData eventData)
|
|
{
|
|
var item = GetItemFromDrag(eventData);
|
|
if (item == null)
|
|
return;
|
|
|
|
m_SelectedMaterial = item;
|
|
m_TxtSecondName.text = item.GetName();
|
|
|
|
SetSlotIcon(m_SlotSecondlParent, item);
|
|
|
|
Debug.Log($"[Install] Attached material: {item.m_tid}");
|
|
}
|
|
|
|
private void SetSlotIcon(Transform slot, EC_IvtrItem item)
|
|
{
|
|
if (slot == null || item == null)
|
|
return;
|
|
|
|
var img = slot.GetComponentInChildren<Image>(true);
|
|
if (img == null)
|
|
return;
|
|
|
|
img.sprite = EC_IvtrItemUtils.Instance.ResolveItemIconSprite(item.m_tid);
|
|
img.enabled = img.sprite != null;
|
|
|
|
img.color = Color.white;
|
|
img.SetNativeSize();
|
|
}
|
|
}
|
|
} |