/// <summary> /// Save toolbar data to PlayerPrefs as string /// </summary> public static void LoadToolbar() { string toolbarData = PlayerPrefs.GetString(TOOLBAR_PLAYERPREFS_KEY); // split data string[] toolbarCells = toolbarData.Split('|'); for (int i = 0; i < toolbarCells.Length - 1; i++) { // parse strings to ints string[] cellData = toolbarCells[i].Split(';'); int index = int.Parse(cellData[0]); int indexPositionX = int.Parse(cellData[1]); int indexPositionY = int.Parse(cellData[2]); InventoryCellUI inventoryCell = Instance.GetInventoryCell(indexPositionX, indexPositionY); ToolbarCellUI toolbarCell; // if can set current item to toolbar if (CanSetToolbarItem(index, inventoryCell, out toolbarCell)) { // assing cell toolbarIndex inventoryCell.toolbarIndex = index; // set toolbarCell to inventoryCell toolbarCell.SetCell(inventoryCell); } } }
public InventoryCellUI GetCrewViewUI(int index) { InventoryCellUI cell = _orderedCrewViews[index]; cell.Show(); return(cell); }
public InventoryCellUI GetShipHoldUI(int index) { InventoryCellUI cell = _orderedHolds[index]; cell.Show(); return(cell); }
/// <summary> /// Check if player can set toolbar target to selected cell /// </summary> /// <param name="index">Toolbar cell index</param> /// <param name="cell">Inventory cell</param> /// <param name="toolbarCell">if true returns selected cell</param> /// <returns></returns> public static bool CanSetToolbarItem(int index, InventoryCellUI cell, out ToolbarCellUI toolbarCell) { toolbarCell = null; if (index < 0 || index >= Instance.toolbarCells.Length || cell.item == null) { return(false); } toolbarCell = Instance.toolbarCells[index]; return(true); }
/// <summary> /// Equip item /// </summary> /// <param name="position"></param> public override void UseItem(Vector2Byte position) { // get inventory cell InventoryCellUI cell = InventorySystem.Instance.GetInventoryCell(position.x, position.y); // check if player can set equipment and remove item from toolbar if so if (cell && (!Player.localPlayer.equipmentData.ContainsKey(equipmentSlot) || Player.localPlayer.equipmentData[equipmentSlot].Count == 0 || Player.localPlayer.equipmentData[equipmentSlot].ID != ID)) { // clear cell data cell.ClearData(); cell.toolbarIndex = -1; // equip item Player.localPlayer.CmdSetEquipment(equipmentSlot, new ItemData(ID, 1), position); } }
public void SetCurrent(Crew crew, int index, bool doAnim) { _current = crew; if (current != null) { current.transform.SetParent(transform, false); } _view = UILayoutInventory.instance.GetCrewViewUI(index); _view.Refresh(this); if (doAnim) { if (current != null) { _view.DoGrowAnim(true); } else { _view.DoReduceAnim(false); } } }
public void Init(int index) { _view = UILayoutInventory.instance.GetShipHoldUI(index); _view.Refresh(this); }