protected override void OnStart() { for(int i = 0; i < m_Slots.Length; ++i) { m_Slots[i] = new ItemSlotGUI(EmptySlotTextures[i]); m_Slots[i].ImgRect.width = m_Slots[i].ImgRect.height = GameGUI.Singleton.Styles.ItemSlot.fixedHeight; } MainWndRect.x = Screen.currentResolution.width * 0.3f; MainWndRect.y = Screen.currentResolution.height * 0.1f; //OnResize(); }
protected override void OnDraw() { MainWndRect = GUI.Window(this.MainWndID, MainWndRect, WndFunc, m_Unit.Name); if(m_CurrSlot != null) { m_ItemTooltip.Show(m_CurrSlot.Item, Event.current.mousePosition.x, Event.current.mousePosition.y); m_CurrSlot = null; } else { m_ItemTooltip.Show(false); } }
private void CreateItemSlot(ItemInstanceModel itemInstance, ItemModel item, int count) { float yOffset = (this.itemSlotPadding * (float)count); ItemSlotGUI itemSlot = (ItemSlotGUI)Instantiate(this.itemSlotPrefab, this.itemSlotPrefab.transform.position - new Vector3(0, yOffset, 1), this.itemSlotPrefab.transform.rotation); itemSlot.gameObject.transform.parent = this.gameObject.transform; itemSlot.type = this.type; itemSlot.SetItemInstance(itemInstance); itemSlot.SetItem(item); this.itemSlots.Add(itemSlot); }
void OnSlotClick(int slotId, ItemSlotGUI Slot) { if (Slot == null) return; Gameplay.EquipmentSlotType CurrSlot = (Gameplay.EquipmentSlotType)slotId; if (Slot.Item == null) { if (Event.current.button == 0) { if (GameGUI.Singleton.ItemDrag.Active) { /*if (!m_Unit.Equipment.CanSetItem((Gameplay.EquipmentSlotType)slotId, GameGUI.Singleton.ItemDrag.Item)) { //Wrong slot return; }*/ GameplayItem Item = GameGUI.Singleton.ItemDrag.Item; if(Item == null) return; List<Gameplay.EquipmentSlotType> SlotsToLock = m_Unit.Equipment.CheckItemSlots(CurrSlot, Item); List<Gameplay.EquipmentSlotType> SlotsToRemove = m_Unit.Equipment.SetItem(CurrSlot, Item, SlotsToLock); if(SlotsToRemove == null) //error no space in the backpack { return; } foreach(Gameplay.EquipmentSlotType TmpSlot in SlotsToRemove) { //Add item to backpack m_Unit.Inventory.AddItem(m_Slots[(int)TmpSlot].Item); m_Slots[(int)TmpSlot].Item = null; } foreach(Gameplay.EquipmentSlotType TmpSlot in SlotsToLock) { m_Slots[(int)TmpSlot].Lock(true); } Item = GameGUI.Singleton.ItemDrag.Drop(this); GameGUI.Singleton.ItemDrag.Show(false); Slot.Item = Item; return; } } } else { if (Event.current.button == 0) { GameGUI.Singleton.ItemDrag.Drag(this, Slot.Item); GameGUI.Singleton.ItemDrag.Show(true); Slot.Item = null; //Unlock all locked slot by this slot List<Gameplay.EquipmentSlotType> SlotsToUnlock = m_Unit.Equipment.RemoveItem(CurrSlot); foreach(Gameplay.EquipmentSlotType TmpSlot in SlotsToUnlock) { m_Slots[(int)TmpSlot].Lock(false); } return; } } }
void OnMouseOverSlot(ItemSlotGUI Slot) { }
void WndFunc(int wndId) { ItemSlotGUI Slot; for(int i = 0; i < m_Slots.Length; ++i) { Slot = m_Slots[i]; Slot.Draw(); if(Slot.MouseOver) { m_CurrSlot = Slot; OnMouseOverSlot(m_CurrSlot); if (Slot.MouseDown) { OnSlotClick(i, Slot); } } } GUI.Box(m_CenterBoxRect, base.Player.CurrentPartyUnit.Portrait); GUI.DragWindow(m_WndDragRect); }
void CreateItemSlots() { int count = m_rowWidth * m_colHeight; for (int i = 0; i < count; ++i) { ItemSlotGUI ItemSlot = new ItemSlotGUI(); ItemSlot.ImgRect = new Rect(0, 0, m_imgSize, m_imgSize); //ItemSlot.Content.image = EmptySlotTexture; m_ItemSlots.Add(ItemSlot); } }
//protected virtual void OnMouseOverMainWindow(){} protected virtual void OnMouseOverItemSlot(ItemSlotGUI Slot) { }