public override void _Process(float delta) { if (Input.IsActionJustPressed("click") && mouseOver) { followMouse = true; } if (Input.IsActionJustReleased("click")) { followMouse = false; } if (!followMouse && hoveredSlot != null && hoveredSlot.item == null) { usedSlot = hoveredSlot; usedSlot.item = this; } if (followMouse) { GlobalPosition = GetGlobalMousePosition(); if (usedSlot != null) { usedSlot.item = null; } } else if (usedSlot != null) { GlobalPosition = usedSlot.GlobalPosition; } if (GetOverlappingAreas().Count > 0) { hoveredSlot = GetOverlappingAreas()[0] as InventoryCell; } }
public InventoryCell RemoveEquip() { InventoryCell cell = child; child = null; return(child); }
private InventoryCellsGroup FindFreeGroup(Item item, int req_x, int req_y) { InventoryCell[,] cells = this.m_Cells; int upperBound = cells.GetUpperBound(0); int upperBound2 = cells.GetUpperBound(1); for (int i = cells.GetLowerBound(0); i <= upperBound; i++) { for (int j = cells.GetLowerBound(1); j <= upperBound2; j++) { InventoryCell inventoryCell = cells[i, j]; if (inventoryCell.m_IndexX + req_x <= (int)this.m_GridSize.x && inventoryCell.m_IndexY + req_y <= (int)this.m_GridSize.y) { InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(this.m_Pocked); for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + req_x; k++) { for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + req_y; l++) { inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]); } } if (inventoryCellsGroup.m_Cells.Count != 0 && inventoryCellsGroup.IsFree()) { inventoryCellsGroup.Setup(); return(inventoryCellsGroup); } } } } return(null); }
public void AddItem(InventoryCell cell, Block item, int count = 1, bool must_find = false) { if (Cells.Count == Full_Cells.Count) { return; } if (must_find && IsSimilar(item)) { AddItem(FindSimilar(item), item, count); } else { if (!CheckCount(cell, item, count)) { AddItem(FindEmptyCell(), item, item.limit); AddItem(FindEmptyCell(), item, count - item.limit); Full_Cells.Add(cell); } else { SetIcon(cell, item); cell.count_item += count; cell.is_item = true; cell.id_item_in_cell = item.BlockID; cell.name_item = item.name; cell.object_save = item.ObjectToSave; for (int i = 0; i < count; i++) { item_list.Add(item.ObjectToSave.GetComponent <Block>()); } } } }
private InventoryCellsGroup FindFreeGroup(Item item, int req_x, int req_y) { InventoryCell[,] cells = this.m_Cells; int length = cells.GetLength(0); int length2 = cells.GetLength(1); for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { InventoryCell inventoryCell = cells[i, j]; if (inventoryCell.m_IndexX + req_x <= (int)this.m_GridSize.x) { if (inventoryCell.m_IndexY + req_y <= (int)this.m_GridSize.y) { InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(); for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + req_x; k++) { for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + req_y; l++) { inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]); } } if (inventoryCellsGroup.m_Cells.Count != 0 && inventoryCellsGroup.IsFree()) { inventoryCellsGroup.Setup(); return(inventoryCellsGroup); } } } } } return(null); }
void PotentialSlotExited(InventoryCell slot) { if (slot == usedSlot) { usedSlot.item = null; } }
public void PutItem(GameObject weap, InventoryCell cell) { if (currentWeapon) { cell.PutItem(currentWeapon, this); } currentWeapon = weap; }
bool CheckCount(InventoryCell cell, Block item, int count) { if (cell.count_item + count <= item.limit) { return(true); } return(false); }
public void SetCurrentSelection(GameObject obj, InventoryCell cell) { if (!cell.IsEmpty) { return; } lastSelectedCell = selectedCell; selectedCell = obj; }
private void OnEnable() { var playerMainScript = GetComponent <PlayerMainScript>(); if (playerMainScript != null) { _rangedWeapon = playerMainScript.equipment.weapon; } }
void AddTool(InventoryCell cell, GameObject ToolObject) { Tool tool = ToolObject.GetComponent <Tool>(); cell.count_item = 1; cell.is_item = true; cell.id_item_in_cell = tool.my_id; cell.name_item = tool.name; }
private void SlotOnUse(InventoryCell inventoryCell) { if (inventoryCell.item.ItemType == ItemObjectType.Consumable) { inventoryCell.Use(PlayerMainScript.MyPlayer.playerObject); inventory.RemoveItem(inventoryCell); } Display(); }
public virtual void InitializeComponent() { Children.Clear(); _ingredientsRect = new RectangleF(240, 275, 360, 42); _recipesList = new ListControl { SelectionMode = ListSelectionMode.Single }; _recipesList.Bounds = new UniRectangle(20, 50, 200, 300); _recipesList.SelectionChanged += RecipesListOnSelectionChanged; foreach (var recipe in _conf.Recipes.Where(r => r.ContainerBlueprintId == 0)) { _recipesList.Items.Add(recipe); } Children.Add(_recipesList); // cells _resultModel = new ModelControl(_iconFactory.VoxelModelManager) { Bounds = new UniRectangle(300, 10, 230, 230) }; Children.Add(_resultModel); _ingredientCells = new List <InventoryCell>(); for (int i = 0; i < 6; i++) { var cell = new InventoryCell(null, _iconFactory, new Vector2I(), _inputsManager) { DrawIconsGroupId = 5, DrawIconsActiveCellId = 6, IsVisible = false }; _ingredientCells.Add(cell); Children.Add(cell); } // craft button const int buttonWidth = 212; const int buttomHeight = 40; _craftButton = new ButtonControl { Text = "Craft", Bounds = new UniRectangle(340, 300, buttonWidth, buttomHeight) }; Children.Add(_craftButton); }
/// <summary> /// ViewModel for an invetory cell. /// </summary> /// <param name="mediaPlayerWrapper">Media player for sounds.</param> public InventoryCellViewModel(IMediaPlayerWrapper mediaPlayerWrapper, IInventoryCellDbRepository inventoryCellRepository, IItemsDbRepository itemsRepository, InventoryCell inventoryCell) { _mediaPlayerWrapper = mediaPlayerWrapper; _inventoryCellRepository = inventoryCellRepository; _itemsRepository = itemsRepository; _inventoryCell = inventoryCell; }
void ChangeInts(InventoryCell cell_one, InventoryCell cell_two) { int cell_one_count_copy = cell_one.count_item; cell_one.count_item = cell_two.count_item; cell_two.count_item = cell_one_count_copy; int cell_one_id_item_in_cell_copy = cell_one.id_item_in_cell; cell_one.id_item_in_cell = cell_two.id_item_in_cell; cell_two.id_item_in_cell = cell_one_id_item_in_cell_copy; }
public void AddItemHud(InventoryCell cell, GameObject item, int count) { if (item.GetComponent <Block>() != null) { AddItem(cell, item.GetComponent <Block>(), count); return; } if (item.GetComponent <Tool>() != null) { AddTool(cell, item); return; } }
void ChangeCells(InventoryCell cell_one, InventoryCell cell_two) { ChangeInts(cell_one, cell_two); ChangeGameObjects(cell_one, cell_two); string copy_name_cell_one = cell_one.name_item; cell_one.name_item = cell_two.name_item; cell_two.name_item = copy_name_cell_one; cell_one.i_choose = false; cell_two.i_choose = false; }
public void OnSetSelectedGroup(InventoryCellsGroup group) { InventoryCell[,] cells = this.m_Cells; int length = cells.GetLength(0); int length2 = cells.GetLength(1); for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { InventoryCell inventoryCell = cells[i, j]; inventoryCell.m_Renderer.enabled = false; } } if (group == null) { return; } bool flag = group.IsFree(); if (flag) { for (int k = 0; k < group.m_Cells.Count; k++) { group.m_Cells[k].m_Renderer.enabled = true; group.m_Cells[k].m_Renderer.material.color = InventoryBackpack.Get().m_FreeColor; } } else { for (int l = 0; l < group.m_Cells.Count; l++) { group.m_Cells[l].m_Renderer.enabled = true; group.m_Cells[l].m_Renderer.material.color = InventoryBackpack.Get().m_OccupiedColor; if (group.m_Cells[l].m_Items.Count > 0) { for (int m = 0; m < group.m_Cells[l].m_Items.Count; m++) { InventoryCellsGroup inventoryCellsGroup = group.m_Cells[l].m_Items[m].m_Info.m_InventoryCellsGroup; for (int n = 0; n < inventoryCellsGroup.m_Cells.Count; n++) { inventoryCellsGroup.m_Cells[n].m_Renderer.enabled = true; inventoryCellsGroup.m_Cells[n].m_Renderer.material.color = InventoryBackpack.Get().m_OccupiedColor; } } } } } }
public void OnCloseBackpack() { InventoryCell[,] cells = this.m_Cells; int length = cells.GetLength(0); int length2 = cells.GetLength(1); for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { InventoryCell inventoryCell = cells[i, j]; inventoryCell.m_Renderer.enabled = false; } } }
public void Setup() { this.m_MatchingGroups.Clear(); Item carriedItem = Inventory3DManager.Get().m_CarriedItem; if (!carriedItem) { return; } if (carriedItem.m_Info.m_InventoryCellsGroup != null) { carriedItem.m_Info.m_InventoryCellsGroup.Remove(carriedItem); } int num = 0; int num2 = 0; this.CalcRequiredCells(carriedItem, ref num, ref num2); InventoryCell[,] cells = this.m_Cells; int length = cells.GetLength(0); int length2 = cells.GetLength(1); for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { InventoryCell inventoryCell = cells[i, j]; if (inventoryCell.m_IndexX + num <= (int)this.m_GridSize.x) { if (inventoryCell.m_IndexY + num2 <= (int)this.m_GridSize.y) { InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(); for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + num; k++) { for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + num2; l++) { inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]); } } if (inventoryCellsGroup.m_Cells.Count != 0) { inventoryCellsGroup.Setup(); this.m_MatchingGroups.Add(inventoryCellsGroup); } } } } } }
public TableViewCell GetCellForRowInTableView(TableView tableView, int row) { InventoryCell cell = tableView.GetReusableCell(_cellPrefab.reuseIdentifier) as InventoryCell; if (cell == null) { cell = (InventoryCell)GameObject.Instantiate(_cellPrefab); } InventoryItem data = _items [row]; cell.Name.text = data.name; cell.Amount.text = data.amount.ToString(); cell.Icon.sprite = LoadImage(data.name); cell.Btn.name = row.ToString(); // save index to button name return(cell); }
private void EquipSlot(ref InventoryCell equipmentObject, InventoryCell inventoryCell) { if (equipmentObject == null || equipmentObject.item == null) { equipmentObject = inventoryCell; } else { if (equipmentObject.item.id != inventoryCell.item.id) { var tmp = equipmentObject; equipmentObject = inventoryCell; inventory.AddCell(tmp); } } }
private void SlotOnUnequip(InventoryCell inventoryCell) { inventory.AddCell(inventoryCell); if (inventoryCell.item.ItemType == ItemObjectType.Weapon) { PlayerMainScript.MyPlayer.UnequipWeapon(); equipment.weapon = null; } else { PlayerMainScript.MyPlayer.UnequipTool(); equipment.tool = null; } Display(); }
void ChangeGameObjects(InventoryCell cell_one, InventoryCell cell_two) { Sprite sprite_copy_cell_one = cell_one.object_icon.GetComponent <UnityEngine.UI.Image>().sprite; cell_one.object_icon.GetComponent <UnityEngine.UI.Image>().sprite = cell_two.object_icon.GetComponent <UnityEngine.UI.Image>().sprite; cell_two.object_icon.GetComponent <UnityEngine.UI.Image>().sprite = sprite_copy_cell_one; string cell_one_name_copy_object = cell_one.object_icon.name; cell_one.object_icon.name = cell_two.object_icon.name; cell_two.object_icon.name = cell_one_name_copy_object; GameObject cell_one_object_copy = cell_one.object_save; cell_one.object_save = cell_two.object_save; cell_two.object_save = cell_one_object_copy; }
void Start() { _instance = this; bounds = CountBounds(); width = 1; height = 5; stepX = 1; stepY = 1; minX = bounds.min.x + 0.5f; minY = bounds.min.y + 0.5f; cells = new InventoryCell[cellObjects.Length]; for (int i = 0; i < cellObjects.Length; i++) { cells[i] = new InventoryCell(false, 0, i, cellObjects[i].transform.position); } }
public void Setup() { this.m_MatchingGroups.Clear(); Item carriedItem = Inventory3DManager.Get().m_CarriedItem; if (!carriedItem) { return; } if (this.m_Pocked == BackpackPocket.Storage && !Storage3D.Get().CanInsertItem(Inventory3DManager.Get().m_CarriedItem)) { return; } int num = 0; int num2 = 0; this.CalcRequiredCells(carriedItem, ref num, ref num2); InventoryCell[,] cells = this.m_Cells; int upperBound = cells.GetUpperBound(0); int upperBound2 = cells.GetUpperBound(1); for (int i = cells.GetLowerBound(0); i <= upperBound; i++) { for (int j = cells.GetLowerBound(1); j <= upperBound2; j++) { InventoryCell inventoryCell = cells[i, j]; if (inventoryCell.m_IndexX + num <= (int)this.m_GridSize.x && inventoryCell.m_IndexY + num2 <= (int)this.m_GridSize.y) { InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(this.m_Pocked); for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + num; k++) { for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + num2; l++) { inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]); } } if (inventoryCellsGroup.m_Cells.Count != 0) { inventoryCellsGroup.Setup(); this.m_MatchingGroups.Add(inventoryCellsGroup); } } } } }
public void OnEndDrag(PointerEventData data) { var currentCell = inventory.GetCurrentSelectedCell(); if (IsCellAvailable(currentCell) && inventory.MouseInDropRange()) { cell = currentCell; inventory.SetItem(cell.index, item); } else if (Input.GetMouseButtonUp(0)) { inventory.DropDraggingItem(); ClearDrag(); return; } PositionItem(inventory.cells, item, cell.index); ClearDrag(); }
public Item RemoveItemAt(int cellPosition, bool deleteItem = false) { if (cellPosition >= parentOfInventoryCells.childCount) { return(null); } if (cellPosition < 0) { return(null); } InventoryCell cell = parentOfInventoryCells.GetChild(cellPosition).GetComponent <InventoryCell>(); cell.item.GetComponent <Renderer>().enabled = true; Item returnItem = cell.item; cell.item = null; return(returnItem); }
public InventoryCell GetCellByName(string name) { InventoryCell[,] cells = this.m_Cells; int upperBound = cells.GetUpperBound(0); int upperBound2 = cells.GetUpperBound(1); for (int i = cells.GetLowerBound(0); i <= upperBound; i++) { for (int j = cells.GetLowerBound(1); j <= upperBound2; j++) { InventoryCell inventoryCell = cells[i, j]; if (inventoryCell.m_Object.name == name) { return(inventoryCell); } } } return(null); }
private void SlotOnEquip(InventoryCell inventoryCell) { if (inventoryCell.item.ItemType == ItemObjectType.Weapon) { EquipSlot(ref equipment.weapon, inventoryCell); _weaponSlots[0].Init(this, equipment.weapon); PlayerMainScript.MyPlayer.EquipWeapon(); } else { EquipSlot(ref equipment.tool, inventoryCell); _weaponSlots[1].Init(this, equipment.tool); PlayerMainScript.MyPlayer.EquipTool(); } inventory.RemoveItem(inventoryCell, inventoryCell.amount); Display(); }
void Start() { bankReference = FindObjectOfType<ItemReferenceBank>(); cells = new InventoryCell[sizeX, sizeY]; for(int i = 0; i < sizeX; i ++){ for(int j = 0; j < sizeY; j ++){ cells[i, j] = new InventoryCell(); } } }
private void setCellPosition (InventoryCell cell) { Vector2 pos = Vector2.zero; pos.x = MOST_LEFT_POSITION + ((cell.getIndex() % COLUMNS) * CELL_STEP); pos.y = MOST_TOP_POSITION - (Mathf.Abs(cell.getIndex() / COLUMNS) * CELL_STEP); cell.transform.localPosition = pos; }