public void OnBeginDrag(PointerEventData eventData) { currentSlot = transform.GetComponentInParent <SlotHolder>(); // Record original data InventoryManager.Instance.currentDragData = new InventoryManager.DragData(); InventoryManager.Instance.currentDragData.originalSlot = transform.GetComponentInParent <SlotHolder>(); InventoryManager.Instance.currentDragData.originalParent = (RectTransform)transform.parent; }
private void GetSummons(SlotHolder sh, List <SummonMenuEntry> list) { // First, add all the new summons. foreach (MateriaOrb m in sh.Slots) { if (m != null && m.Type == MateriaType.Summon) { foreach (string ability in m.Abilities) { Spell summon = CurrentBattle.Seven.Data.GetSummonSpell(ability); if (!list.Any(x => x.Name == summon.Name)) { list.Add(new SummonMenuEntry(m.Name, summon)); } } } } // Then, go through and attach any support abilities for (int i = 0; i < sh.Links; i++) { MateriaOrb left = sh.Slots[i * 2]; MateriaOrb right = sh.Slots[(i * 2) + 1]; if (left != null && right != null) { if (left.Type == MateriaType.Summon && right.Type == MateriaType.Support) { MateriaOrb temp = left; left = right; right = temp; } if (right.Type == MateriaType.Summon && left.Type == MateriaType.Support) { foreach (string ability in right.Abilities) { Spell summon = CurrentBattle.Seven.Data.GetSummonSpell(ability); foreach (SummonMenuEntry entry in list.Where(x => x.Name == summon.Name)) { entry.AddAbility(left); } } } } } }
private void GetMagicSpells(SlotHolder sh, List <MagicMenuEntry> list) { // First, add all the new magic spells. foreach (MateriaOrb m in sh.Slots) { if (m != null && m.Type == MateriaType.Magic) { foreach (string ability in m.Abilities) { Spell magicSpell = CurrentBattle.Seven.Data.GetMagicSpell(ability); if (!list.Any(x => x.Name == magicSpell.Name)) { list.Add(new MagicMenuEntry(magicSpell)); } } } } for (int i = 0; i < sh.Links; i++) { MateriaOrb left = sh.Slots[i * 2]; MateriaOrb right = sh.Slots[(i * 2) + 1]; if (left != null && right != null) { if (left.Type == MateriaType.Magic && right.Type == MateriaType.Support) { MateriaOrb temp = left; left = right; right = temp; } if (right.Type == MateriaType.Magic && left.Type == MateriaType.Support) { foreach (string ability in right.Abilities) { Spell magicSpell = CurrentBattle.Seven.Data.GetMagicSpell(ability); foreach (MagicMenuEntry entry in list.Where(x => x.Name == magicSpell.Name)) { entry.AddAbility(left); } } } } } }
public void OnEndDrag(PointerEventData eventData) { //放下物品,交换数据 if (EventSystem.current.IsPointerOverGameObject()) { if (InventoryManager.Instance.CheckInInventoryUI(eventData.position) || InventoryManager.Instance.CheckInActionUI(eventData.position)) { if (eventData.pointerEnter.gameObject.GetComponent <SlotHolder>()) { targetSlotholder = eventData.pointerEnter.gameObject.GetComponent <SlotHolder>(); } else { targetSlotholder = eventData.pointerEnter.gameObject.GetComponentInParent <SlotHolder>(); } switch (targetSlotholder.slotType) { case SlotType.BAG: SwapItem(); break; case SlotType.ACTION: if (currentItemUI.Bag.items[currentItemUI.Index].ItemData.itemType == ItemType.Useable) { SwapItem(); } break; } currentSlotholder.UpdateItem(); targetSlotholder.UpdateItem(); } } transform.SetParent(InventoryManager.Instance.currentDrag.originalParent); RectTransform t = transform as RectTransform; t.offsetMax = -Vector2.one * 5; t.offsetMin = Vector2.one * 5; }
public void Swap(SlotHolder @from, SlotHolder to, Character c) { for (int i = 0; i < @from.Slots.Length; i++) { MateriaOrb m = @from.Slots[i]; if (m != null) { if (i >= to.Slots.Length) { m.Detach(c); Put(m); } else { to.Slots[i] = m; } } @from.Slots[i] = null; } }
public static void Render(Cairo.Context g, SlotHolder equipment, int x, int y, bool renderOrbs, bool renderBackground = true) { if (renderBackground) { g.Color = Colors.GRAY_1; g.Rectangle(x, y, 8 * SLOT_SPACING, SLOT_RADIUS * 2); g.Fill(); } for (int j = 0; j < equipment.Links; j++) { Shapes.RenderLine(g, gray2, 3, x + (SLOT_SPACING / 2) + (j * 2 * SLOT_SPACING), y + ys - zs, x + (SLOT_SPACING / 2) + ((j * 2 + 1) * SLOT_SPACING), y + ys - zs); Shapes.RenderLine(g, gray2, 3, x + (SLOT_SPACING / 2) + (j * 2 * SLOT_SPACING), y + ys, x + (SLOT_SPACING / 2) + ((j * 2 + 1) * SLOT_SPACING), y + ys); Shapes.RenderLine(g, gray2, 3, x + (SLOT_SPACING / 2) + (j * 2 * SLOT_SPACING), y + ys + zs, x + (SLOT_SPACING / 2) + ((j * 2 + 1) * SLOT_SPACING), y + ys + zs); } for (int i = 0; i < equipment.Slots.Length; i++) { Shapes.RenderCircle(g, gray2, SLOT_RADIUS, x + (i * SLOT_SPACING) + (SLOT_SPACING / 2), y + ys); if (equipment.Slots[i] == null || !renderOrbs) { Shapes.RenderCircle(g, gray1, MATERIA_RADIUS, x + (i * SLOT_SPACING) + (SLOT_SPACING / 2), y + ys); } else { Shapes.RenderCircle(g, equipment.Slots[i].Color, MATERIA_RADIUS, x + (i * SLOT_SPACING) + (SLOT_SPACING / 2), y + ys); } } }
public static void Render(Cairo.Context g, SlotHolder equipment, int x, int y) { Render(g, equipment, x, y, true); }
private void Awake() { currentItemUI = GetComponent <ItemUI>(); currentSlotholder = GetComponentInParent <SlotHolder>(); }
private void Awake() { currentSlot = GetComponent <SlotHolder>(); }
public void OnEndDrag(PointerEventData eventData) { // if the pointer over UI if (EventSystem.current.IsPointerOverGameObject()) { if (InventoryManager.Instance.CheckInInventoryUI(eventData.position) || InventoryManager.Instance.CheckInActionUI(eventData.position) || InventoryManager.Instance.CheckInEquipmentUI(eventData.position)) { if (eventData.pointerEnter.gameObject.GetComponent <SlotHolder>()) { targetSlot = eventData.pointerEnter.gameObject.GetComponent <SlotHolder>(); } else { targetSlot = eventData.pointerEnter.gameObject.GetComponentInParent <SlotHolder>(); } switch (targetSlot.slotType) { case SlotType.BAG: if (currentSlot.slotType == SlotType.WEAPON) { GameManager.Instance.player.UnEquipWeapon(currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData); } SwapItem(); break; case SlotType.ACTION: if (currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData.itemType == ItemType.Usable) { SwapItem(); } break; case SlotType.WEAPON: if (currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData.itemType == ItemType.Weapon && currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData.playerStyle == GameManager.Instance.player.characterData.playerStyle) { if (targetSlot.itemUI.bag.items[targetSlot.itemUI.itemIndex].itemData == null) { GameManager.Instance.player.EquipWeapon(currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData); } else { GameManager.Instance.player.ChangeWeapon(targetSlot.itemUI.bag.items[targetSlot.itemUI.itemIndex].itemData, currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData); } SwapItem(); } break; case SlotType.ARMOR: if (currentSlot.itemUI.bag.items[currentSlot.itemUI.itemIndex].itemData.itemType == ItemType.Armor) { SwapItem(); } break; default: break; } } } currentSlot.UpdataItem(); if (targetSlot != null) { targetSlot.UpdataItem(); } transform.SetParent(InventoryManager.Instance.currentDragData.originalParent); RectTransform tmpT = transform as RectTransform; // Drag would let the itemslot to the wrong position, we need to reset it. tmpT.offsetMax = -Vector2.one * 5; tmpT.offsetMin = Vector2.one * 5; }