Change equip from doubleclick to rightclick

This commit is contained in:
excitedneon 2017-05-15 01:02:40 +03:00
parent e87ae0a153
commit 744d421956
2 changed files with 10 additions and 9 deletions

View File

@ -98,7 +98,6 @@ namespace Cyber.Controls {
private List<Transform> ItemGridCells; private List<Transform> ItemGridCells;
private List<MeshFilter> ItemGridCellMeshes; private List<MeshFilter> ItemGridCellMeshes;
private int ItemGridSelectedIndex; private int ItemGridSelectedIndex;
private Item SelectedItem = null;
private Color IconInventoryColor; private Color IconInventoryColor;
private Color IconStatusColor; private Color IconStatusColor;
@ -139,9 +138,14 @@ namespace Cyber.Controls {
if (ItemGridCells.Contains(LookedAt.collider.transform)) { if (ItemGridCells.Contains(LookedAt.collider.transform)) {
// Interacting with the item list // Interacting with the item list
CurrentIndex = int.Parse(LookedAt.collider.name.Split(' ')[1]); CurrentIndex = int.Parse(LookedAt.collider.name.Split(' ')[1]);
if (Input.GetButtonDown("Activate")) { if (Input.GetButtonDown("Activate") || Input.GetButtonDown("Equip")) {
if (ItemGridSelectedIndex == CurrentIndex && SelectedItem != null) { ItemGridSelectedIndex = CurrentIndex;
}
if (Input.GetButtonDown("Equip")) {
// Selected index was already this => equip (double-clicked) // Selected index was already this => equip (double-clicked)
Item SelectedItem = Inventory.Drive.Interface.GetItemAt(ItemGridSelectedIndex % (int) ItemGridDimensions.x,
ItemGridSelectedIndex / (int) ItemGridDimensions.y);
if (SelectedItem != null) {
Item Equipped = Inventory.Equipped.GetItem(SelectedItem.Slot); Item Equipped = Inventory.Equipped.GetItem(SelectedItem.Slot);
if (Equipped != null && Equipped.ID == SelectedItem.ID) { if (Equipped != null && Equipped.ID == SelectedItem.ID) {
Inventory.Equipped.ClearSlot(SelectedItem.Slot); Inventory.Equipped.ClearSlot(SelectedItem.Slot);
@ -151,7 +155,6 @@ namespace Cyber.Controls {
Client.Send(PktType.InventoryAction, new InventoryActionPkt(InventoryAction.Equip, SelectedItem.ID)); Client.Send(PktType.InventoryAction, new InventoryActionPkt(InventoryAction.Equip, SelectedItem.ID));
} }
} }
ItemGridSelectedIndex = CurrentIndex;
} }
} else if (Mesh != null) { } else if (Mesh != null) {
float InvBrightness = 1.1f; float InvBrightness = 1.1f;
@ -221,9 +224,6 @@ namespace Cyber.Controls {
} }
if (ItemGridSelectedIndex == i) { if (ItemGridSelectedIndex == i) {
// Update the selected item
SelectedItem = Item;
// Set preview information // Set preview information
SetPreviewMesh(Mesh); SetPreviewMesh(Mesh);
TextTextureProperties NameProps = ItemNameText.TextProperties; TextTextureProperties NameProps = ItemNameText.TextProperties;

View File

@ -38,7 +38,8 @@ namespace Cyber.Items {
/// <param name="y">The y-coordinate</param> /// <param name="y">The y-coordinate</param>
/// <returns>The item or null</returns> /// <returns>The item or null</returns>
public Item GetItemAt(int x, int y) { public Item GetItemAt(int x, int y) {
if (ItemGrid[y, x] == -1) { if (y < 0 || x < 0 || y >= GetHeight() || x >= GetWidth() ||
ItemGrid[y, x] == -1) {
return null; return null;
} else { } else {
return Drive.GetItem(ItemGrid[y, x]); return Drive.GetItem(ItemGrid[y, x]);