Update EC_InventoryUI.cs
This commit is contained in:
@@ -21,6 +21,7 @@ namespace PerfectWorld.Scripts.Managers
|
||||
|
||||
[Header("Detail Panel (assign in Inspector)")]
|
||||
[SerializeField] private GameObject detailPanelRoot;
|
||||
[SerializeField] private Vector2 detailPanelOffset = new Vector2(20f, 0f);
|
||||
[SerializeField] private bool hideDetailOnStart = true;
|
||||
[SerializeField] private TextOutlet nameText;
|
||||
[SerializeField] private TextOutlet descriptionText;
|
||||
@@ -212,6 +213,9 @@ namespace PerfectWorld.Scripts.Managers
|
||||
|
||||
// Create equipment object if this is equipment
|
||||
currentSelectedEquipment = CreateEquipmentFromItemData(itemData);
|
||||
|
||||
// Position detail panel near the clicked item button
|
||||
PositionDetailPanelNearButton(package, slot);
|
||||
|
||||
FillDetailPanel(package, itemData);
|
||||
}
|
||||
@@ -655,6 +659,116 @@ namespace PerfectWorld.Scripts.Managers
|
||||
}
|
||||
}
|
||||
|
||||
private Button GetButtonForSlot(byte package, int slot)
|
||||
{
|
||||
List<Button> list = null;
|
||||
switch (package)
|
||||
{
|
||||
case PKG_INVENTORY:
|
||||
list = inventoryPackButtons;
|
||||
break;
|
||||
case PKG_EQUIPMENT:
|
||||
list = equipmentPackButtons;
|
||||
break;
|
||||
case PKG_FASHION:
|
||||
list = fashionPackButtons;
|
||||
break;
|
||||
}
|
||||
if (list == null || slot < 0 || slot >= list.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list[slot];
|
||||
}
|
||||
|
||||
private void PositionDetailPanelNearButton(byte package, int slot)
|
||||
{
|
||||
if (detailPanelRoot == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var panelRect = detailPanelRoot.transform as RectTransform;
|
||||
if (panelRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var button = GetButtonForSlot(package, slot);
|
||||
if (button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var buttonRect = button.transform as RectTransform;
|
||||
if (buttonRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var canvas = panelRect.GetComponentInParent<Canvas>();
|
||||
if (canvas == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var parentRect = panelRect.parent as RectTransform;
|
||||
if (parentRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Camera eventCamera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
|
||||
Vector3 worldCenter = buttonRect.TransformPoint(buttonRect.rect.center);
|
||||
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(eventCamera, worldCenter);
|
||||
Vector2 localPoint;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRect, screenPoint, eventCamera, out localPoint))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float btnHalfW = buttonRect.rect.width * 0.5f;
|
||||
float panelW = panelRect.rect.width;
|
||||
float panelH = panelRect.rect.height;
|
||||
float pivotX = panelRect.pivot.x;
|
||||
float pivotY = panelRect.pivot.y;
|
||||
|
||||
// Compute right-placement candidate (panel's left edge at button's right edge + offset)
|
||||
float leftEdgeRightPlacement = localPoint.x + btnHalfW + detailPanelOffset.x;
|
||||
float candidateXRight = leftEdgeRightPlacement + pivotX * panelW;
|
||||
|
||||
// Compute left-placement candidate (panel's right edge at button's left edge - offset)
|
||||
float rightEdgeLeftPlacement = localPoint.x - btnHalfW - detailPanelOffset.x;
|
||||
float candidateXLeft = rightEdgeLeftPlacement - (1f - pivotX) * panelW;
|
||||
|
||||
// Vertical clamping honoring pivot
|
||||
float minY = parentRect.rect.yMin + pivotY * panelH;
|
||||
float maxY = parentRect.rect.yMax - (1f - pivotY) * panelH;
|
||||
float candidateY = Mathf.Clamp(localPoint.y + detailPanelOffset.y, minY, maxY);
|
||||
|
||||
// Choose side based on available space
|
||||
float rightEdgeOfRight = candidateXRight + (1f - pivotX) * panelW;
|
||||
float canvasRight = parentRect.rect.xMax;
|
||||
float canvasLeft = parentRect.rect.xMin;
|
||||
float leftEdgeOfLeft = candidateXLeft - pivotX * panelW;
|
||||
|
||||
Vector2 finalPos;
|
||||
if (rightEdgeOfRight <= canvasRight)
|
||||
{
|
||||
finalPos = new Vector2(candidateXRight, candidateY);
|
||||
}
|
||||
else if (leftEdgeOfLeft >= canvasLeft)
|
||||
{
|
||||
finalPos = new Vector2(candidateXLeft, candidateY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: clamp within canvas horizontally
|
||||
float minX = canvasLeft + pivotX * panelW;
|
||||
float maxX = canvasRight - (1f - pivotX) * panelW;
|
||||
finalPos = new Vector2(Mathf.Clamp(candidateXRight, minX, maxX), candidateY);
|
||||
}
|
||||
|
||||
panelRect.anchoredPosition = finalPos;
|
||||
}
|
||||
|
||||
private void FillDetailPanel(byte package, InventoryItemData item)
|
||||
{
|
||||
if (item == null)
|
||||
@@ -786,7 +900,7 @@ namespace PerfectWorld.Scripts.Managers
|
||||
}
|
||||
}
|
||||
|
||||
// Properties + Base Stats
|
||||
// Properties + Base Stats + Engraved + Stones (more closely matching original)
|
||||
if (propertiesText != null)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
@@ -798,7 +912,7 @@ namespace PerfectWorld.Scripts.Managers
|
||||
lines.Add(baseStats);
|
||||
}
|
||||
|
||||
// Add-on properties from detail payload
|
||||
// Add-on properties from detail payload (non-embedded, non-suite, non-engraved)
|
||||
if (currentSelectedEquipment.Props.Count > 0)
|
||||
{
|
||||
foreach (var prop in currentSelectedEquipment.Props)
|
||||
@@ -812,6 +926,35 @@ namespace PerfectWorld.Scripts.Managers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Engraved properties (displayed after normal add-ons)
|
||||
foreach (var prop in currentSelectedEquipment.Props)
|
||||
{
|
||||
if (prop.Engraved)
|
||||
{
|
||||
string propDesc = currentSelectedEquipment.FormatPropDesc(prop);
|
||||
if (!string.IsNullOrEmpty(propDesc))
|
||||
{
|
||||
lines.Add(propDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Socketed stones (show name and a basic description)
|
||||
if (currentSelectedEquipment.Holes != null && currentSelectedEquipment.Holes.Count > 0)
|
||||
{
|
||||
foreach (int holeTid in currentSelectedEquipment.Holes)
|
||||
{
|
||||
if (holeTid == 0) continue;
|
||||
string stoneName = EC_IvtrItem.ResolveItemName(holeTid);
|
||||
// Try to fetch a description from string tables; fallback to name if unavailable
|
||||
string stoneDesc = GetItemDescription(holeTid) ?? stoneName;
|
||||
if (!string.IsNullOrEmpty(stoneName))
|
||||
{
|
||||
lines.Add($"{stoneName}: {stoneDesc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string combined = string.Join("\\r", lines);
|
||||
|
||||
Reference in New Issue
Block a user