Merge pull request 'complete UI DlgInstall.prefab' (#133) from feature/produce-equipment into develop
Reviewed-on: https://git.brew.monster/Unity/perfect-world-unity/pulls/133
This commit is contained in:
@@ -31,15 +31,14 @@ namespace BrewMonster
|
||||
[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;
|
||||
[SerializeField] private Sprite khung_item;
|
||||
|
||||
private EC_IvtrItem m_SelectedEquip;
|
||||
private EC_IvtrItem m_SelectedMaterial;
|
||||
|
||||
private int m_FirstInvSlot = -1;
|
||||
private int m_SecondInvSlot = -1;
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -47,22 +46,61 @@ namespace BrewMonster
|
||||
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);
|
||||
RestoreInventoryColors();
|
||||
}
|
||||
|
||||
private void RestoreInventoryColors()
|
||||
{
|
||||
var canvas = FindFirstObjectByType<Canvas>();
|
||||
if (canvas == null)
|
||||
return;
|
||||
|
||||
if (m_FirstInvSlot >= 0)
|
||||
{
|
||||
var btn = FindInventoryButtonBySlot(m_FirstInvSlot);
|
||||
SetInventorySlotGray(btn, false);
|
||||
m_FirstInvSlot = -1;
|
||||
}
|
||||
|
||||
if (m_SecondInvSlot >= 0)
|
||||
{
|
||||
var btn = FindInventoryButtonBySlot(m_SecondInvSlot);
|
||||
SetInventorySlotGray(btn, false);
|
||||
m_SecondInvSlot = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private Button FindInventoryButtonBySlot(int slot)
|
||||
{
|
||||
var inventoryUI = FindFirstObjectByType<EC_InventoryUI>();
|
||||
if (inventoryUI == null)
|
||||
return null;
|
||||
|
||||
var field = typeof(EC_InventoryUI)
|
||||
.GetField("inventoryPackButtons", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
|
||||
if (field == null)
|
||||
return null;
|
||||
|
||||
var list = field.GetValue(inventoryUI) as List<Button>;
|
||||
if (list == null || slot < 0 || slot >= list.Count)
|
||||
return null;
|
||||
|
||||
return list[slot];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void RegisterDrop(Transform target, Action<PointerEventData> callback)
|
||||
{
|
||||
var trigger = target.GetComponent<EventTrigger>();
|
||||
@@ -105,7 +143,8 @@ namespace BrewMonster
|
||||
{
|
||||
if (m_SelectedEquip != null)
|
||||
{
|
||||
ShowItemInfo(m_SelectedEquip);
|
||||
ReturnItemToInventory(m_FirstInvSlot);
|
||||
ClearEquipSlot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,53 +152,11 @@ namespace BrewMonster
|
||||
{
|
||||
if (m_SelectedMaterial != null)
|
||||
{
|
||||
ShowItemInfo(m_SelectedMaterial);
|
||||
ReturnItemToInventory(m_SecondInvSlot);
|
||||
ClearMaterialSlot();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -187,31 +184,84 @@ namespace BrewMonster
|
||||
|
||||
private void OnDropEquip(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.pointerDrag == null)
|
||||
return;
|
||||
|
||||
var btn = eventData.pointerDrag.GetComponent<Button>();
|
||||
if (btn == null)
|
||||
return;
|
||||
|
||||
int slotIndex = btn.transform.GetSiblingIndex();
|
||||
|
||||
var item = GetItemFromDrag(eventData);
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
m_SelectedEquip = item;
|
||||
m_TxtFirstName.text = item.GetName();
|
||||
SetSlotIcon(m_SlotFirstParent, item);
|
||||
EC_IvtrItem detailedItem = EC_IvtrItem.CreateItem(item.m_tid, item.m_expire_date, item.m_iCount);
|
||||
if (item.Content != null && item.Content.Length > 0)
|
||||
detailedItem.SetItemInfo(item.Content, item.Content.Length);
|
||||
else
|
||||
detailedItem.GetDetailDataFromLocal();
|
||||
|
||||
Debug.Log($"[Install] Equiment: {item.m_tid}");
|
||||
m_SelectedEquip = detailedItem;
|
||||
m_FirstInvSlot = slotIndex;
|
||||
|
||||
m_TxtFirstName.text = detailedItem.GetName();
|
||||
SetSlotIcon(m_SlotFirstParent, detailedItem);
|
||||
|
||||
SetInventorySlotGray(btn, true);
|
||||
|
||||
Debug.Log($"[Install] Equipment: {detailedItem.m_tid} from slot {slotIndex}");
|
||||
}
|
||||
|
||||
|
||||
private void OnDropMaterial(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.pointerDrag == null)
|
||||
return;
|
||||
|
||||
var btn = eventData.pointerDrag.GetComponent<Button>();
|
||||
if (btn == null)
|
||||
return;
|
||||
|
||||
int slotIndex = btn.transform.GetSiblingIndex();
|
||||
|
||||
var item = GetItemFromDrag(eventData);
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
m_SelectedMaterial = item;
|
||||
m_TxtSecondName.text = item.GetName();
|
||||
EC_IvtrItem detailedItem = EC_IvtrItem.CreateItem(item.m_tid, item.m_expire_date, item.m_iCount);
|
||||
if (item.Content != null && item.Content.Length > 0)
|
||||
detailedItem.SetItemInfo(item.Content, item.Content.Length);
|
||||
else
|
||||
detailedItem.GetDetailDataFromLocal();
|
||||
|
||||
SetSlotIcon(m_SlotSecondlParent, item);
|
||||
m_SelectedMaterial = detailedItem;
|
||||
m_SecondInvSlot = slotIndex;
|
||||
|
||||
Debug.Log($"[Install] Attached material: {item.m_tid}");
|
||||
m_TxtSecondName.text = detailedItem.GetName();
|
||||
SetSlotIcon(m_SlotSecondlParent, detailedItem);
|
||||
|
||||
SetInventorySlotGray(btn, true);
|
||||
|
||||
Debug.Log($"[Install] Material: {detailedItem.m_tid} from slot {slotIndex}");
|
||||
}
|
||||
|
||||
private void SetInventorySlotGray(Button btn, bool gray)
|
||||
{
|
||||
if (btn == null)
|
||||
return;
|
||||
|
||||
var img = btn.GetComponent<Image>();
|
||||
if (img == null)
|
||||
return;
|
||||
|
||||
img.color = gray
|
||||
? new Color(0.3f, 0.3f, 0.3f, 1f)
|
||||
: Color.white;
|
||||
}
|
||||
|
||||
|
||||
private void SetSlotIcon(Transform slot, EC_IvtrItem item)
|
||||
{
|
||||
if (slot == null || item == null)
|
||||
@@ -227,5 +277,46 @@ namespace BrewMonster
|
||||
img.color = Color.white;
|
||||
img.SetNativeSize();
|
||||
}
|
||||
|
||||
private void ReturnItemToInventory(int slotIndex)
|
||||
{
|
||||
if (slotIndex < 0)
|
||||
return;
|
||||
|
||||
var btn = FindInventoryButtonBySlot(slotIndex);
|
||||
SetInventorySlotGray(btn, false);
|
||||
}
|
||||
|
||||
private void ClearEquipSlot()
|
||||
{
|
||||
m_SelectedEquip = null;
|
||||
m_FirstInvSlot = -1;
|
||||
m_TxtFirstName.text = "___";
|
||||
ClearSlotIcon(m_SlotFirstParent);
|
||||
|
||||
Debug.Log("[Install] Equipment slot cleared");
|
||||
}
|
||||
|
||||
private void ClearMaterialSlot()
|
||||
{
|
||||
m_SelectedMaterial = null;
|
||||
m_SecondInvSlot = -1;
|
||||
m_TxtSecondName.text = "___";
|
||||
ClearSlotIcon(m_SlotSecondlParent);
|
||||
|
||||
Debug.Log("[Install] Material slot cleared");
|
||||
}
|
||||
|
||||
private void ClearSlotIcon(Transform slot)
|
||||
{
|
||||
if (slot == null)
|
||||
return;
|
||||
|
||||
var img = slot.GetComponentInChildren<Image>(true);
|
||||
if (img == null)
|
||||
return;
|
||||
|
||||
img.sprite = khung_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3616,7 +3616,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: "Thanh Tuy\u1EC1n Th\u1EE7y"
|
||||
m_text: ___
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2}
|
||||
m_sharedMaterial: {fileID: 9092487103257209053, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2}
|
||||
@@ -6127,10 +6127,7 @@ MonoBehaviour:
|
||||
m_TxtMoney: {fileID: 6140428454487430115}
|
||||
m_BtnInstall: {fileID: 8208092408021918524}
|
||||
m_BtnCancel: {fileID: 4503836757578509720}
|
||||
itemInfoRoot: {fileID: 7750009739432212686}
|
||||
infoNameText: {fileID: 0}
|
||||
infoDescText: {fileID: 645831281989042977}
|
||||
infoExtraText: {fileID: 0}
|
||||
khung_item: {fileID: 21300000, guid: a5366f3bce011c046902e39b6bd3a077, type: 3}
|
||||
--- !u!1 &5644241573758805168
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -7139,7 +7136,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: "To\xE0 T\u1EED Th\u1ED1i Gi\xE1p"
|
||||
m_text: ___
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2}
|
||||
m_sharedMaterial: {fileID: 9092487103257209053, guid: 369c2e14814cc9a4b8e3ad4e37769134, type: 2}
|
||||
|
||||
Reference in New Issue
Block a user