From ca80647acfe20b082c8b2711c2df14f4626162a4 Mon Sep 17 00:00:00 2001 From: teascade Date: Tue, 16 May 2017 22:31:40 +0300 Subject: [PATCH] Add switching the places between two slots, allowing moving items --- Assets/Scripts/Controls/InventoryInterface.cs | 2 +- Assets/Scripts/Items/Drive.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Controls/InventoryInterface.cs b/Assets/Scripts/Controls/InventoryInterface.cs index 5cceeb0..28adc3d 100644 --- a/Assets/Scripts/Controls/InventoryInterface.cs +++ b/Assets/Scripts/Controls/InventoryInterface.cs @@ -205,7 +205,7 @@ namespace Cyber.Controls { for (int x = 0; x < ItemGridDimensions.x; x++) { // Find the item and mesh int i = x + y * (int) ItemGridDimensions.x; - Item Item = Inventory.Drive.GetItemAt(x + y * (int) ItemGridDimensions.y); + Item Item = Inventory.Drive.GetItemAt(x + y * (int) ItemGridDimensions.x); Mesh Mesh = null; if (Item != null) { Mesh = MeshDB.GetMesh(Item.ModelID); diff --git a/Assets/Scripts/Items/Drive.cs b/Assets/Scripts/Items/Drive.cs index 3b1d0ca..f2409fb 100644 --- a/Assets/Scripts/Items/Drive.cs +++ b/Assets/Scripts/Items/Drive.cs @@ -98,6 +98,25 @@ namespace Cyber.Items { return false; } + /// + /// + /// + /// + /// + public void SwitchSlots(int idx1, int idx2) { + Slot Slot1 = GetSlotAt(idx1); + Slot Slot2 = GetSlotAt(idx2); + SetSlotAt(idx1, Slot2); + SetSlotAt(idx2, Slot1); + } + + private void SetSlotAt(int idx, Slot slot) { + if (idx >= Slots.Length) { + IncreaseCapacity(idx - Slots.Length + 1); + } + Slots[idx] = slot; + } + /// /// Gets the item at the given index, or null if there is nothing. ///