private void SetInventoryOpen(bool setted) { if (!setted) { Pickup(toClone); foreach (Item i in craftingRecipe) { Pickup(i); } toClone = null; craftingRecipe = new CraftableItem[NUM_CRAFTABLES]; UpdateInventory(); } }
void Start() { _game = GameObject.Find(" GameController").GetComponent<GameController>(); _gun = GameObject.Find("Player").GetComponentInChildren<Weapon>(); // Init the inventories towerInventory = new TowerItem[WIDTH * HEIGHT]; craftInventory = new CraftableItem[WIDTH * HEIGHT]; weaponInventory = new WeaponItem[WIDTH * HEIGHT]; activeInv = INV_TOWER; activeInventory = towerInventory; /* * GUI Initialization */ // Init Rects for Inventory Items inventorySkin = Resources.Load("Fonts/InventorySkin", typeof(GUISkin)) as GUISkin; drawRects = new Rect[WIDTH * HEIGHT]; int totalWidth = WIDTH * GRIDWIDTH + (WIDTH - 1) * SPACE; int totalHeight = HEIGHT * GRIDHEIGHT + (HEIGHT - 1) * SPACE; int sx = Screen.width / 2 - totalWidth / 2 - GRIDWIDTH; int sy = Screen.height / 2 - totalHeight / 2 - (GRIDHEIGHT + SPACE); for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { drawRects[y * WIDTH + x] = new Rect(sx + x * (GRIDWIDTH + SPACE), sy + y * (GRIDHEIGHT + SPACE), GRIDWIDTH, GRIDHEIGHT); } } changeInventoryRect = new Rect(sx, sy - (GRIDHEIGHT * 2 + SPACE), GRIDWIDTH, GRIDHEIGHT * 2); // Crafting Rectangles craftingRects = new Rect[NUM_CRAFTABLES]; for (int i = 0; i < NUM_CRAFTABLES; i++) { craftingRects[i] = new Rect(sx + totalWidth + GRIDWIDTH, sy + (GRIDHEIGHT + SPACE) * i, GRIDWIDTH, GRIDHEIGHT); } cloneButtonRect = new Rect(sx + totalWidth + GRIDWIDTH, sy + (GRIDHEIGHT + SPACE) * HEIGHT, GRIDWIDTH, GRIDHEIGHT); // modeChangeButtonRect = new Rect(sx + totalWidth + GRIDWIDTH, sy - (GRIDHEIGHT + SPACE), GRIDWIDTH, GRIDHEIGHT); tooltipRect = new Rect(sx, sy + totalHeight + SPACE, TOOLTIPWIDTH, TOOLTIPHEIGHT); // Deactivate Messenger: So there aren't any messages _game.Messenger.enabled = false; float level = ((float)WaveController.WAVESTART_COST / Tank.MOBCOUNT_MEDIAN) * 1.5f; Pickup(new TowerItem(0, level)); Pickup(new TowerItem(0, level)); Pickup(new TowerItem(0, level)); Pickup(new TowerItem(0, level)); Pickup(new TowerItem(0, level)); Pickup(new TowerItem(0, level)); Pickup(new TowerItem(1, level)); Pickup(new TowerItem(1, level)); // Pickup(new TowerItem(1, 1)); // Pickup(new TowerItem(1, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new TowerItem(0, 1)); // Pickup(new CraftableItem(0, 1)); // Pickup(new CraftableItem(1, 1)); // Pickup(new CraftableItem(2, 1)); Pickup(new WeaponDPSItem(1)); Pickup(new WeaponStatItem(1)); _game.Messenger.enabled = true; //enable messenger again craftingRecipe = new CraftableItem[CraftableItem.PART_MAX]; Sort(towerInventory); Sort(craftInventory); Sort(weaponInventory); UpdateInventory(); }
/* * Inventory System */ void OnGUI() { if (_game.ActiveMenu == Menu.Inventory) { GUI.skin = inventorySkin; // Draw Mode Swap Button if (GUI.Button(changeInventoryRect, INVENTORYTYPES[activeInv])) { activeInv = (activeInv + 1) % NUM_TYPES; SetActiveInventory(activeInv); } // Draw Inventory for (int i = 0; i < WIDTH * HEIGHT; i++) { if (activeInventory[i] == null) { GUI.Button(drawRects[i], ""); continue; } if (GUI.Button(drawRects[i], new GUIContent(activeInventory[i].GetName(), activeInventory[i].GetTooltip()))) { if (Input.GetKey(KeyCode.LeftControl)) { // Destroy Item if (activeInv == INV_TOWER) { Destroy(((TowerItem)activeInventory[i]).GetTowerComponent().gameObject); } Remove(activeInventory[i]); } else { switch (activeInv) { case INV_CRAFT: CraftableItem c = ((CraftableItem)activeInventory[i]); if (craftingRecipe[c.CraftableType] == null) { // If there is no item CraftableType slot, then ADD craftingRecipe[c.CraftableType] = c; Remove(c); } else { // Else, SWAP the clicked with the one in the slot Pickup(craftingRecipe[c.CraftableType]); craftingRecipe[c.CraftableType] = c; Remove(c); } break; case INV_TOWER: break; case INV_WEAPON: WeaponItem w = ((WeaponItem)activeInventory[i]); WeaponItem prevEquipped = _gun.equippedWeapons[w.weaponType]; _gun.equippedWeapons[w.weaponType] = w; Remove(activeInventory, w); Pickup(activeInventory, prevEquipped); _gun.RecalculateStats(); break; } } } } if (activeInv == INV_WEAPON) { // Draw Equipped Weapons for (int i = 0; i < _gun.equippedWeapons.Length; i++) { if (_gun.equippedWeapons[i] == null) { GUI.Button(craftingRects[i], ""); continue; } GUI.Button(craftingRects[i], new GUIContent(_gun.equippedWeapons[i].GetName(), _gun.equippedWeapons[i].GetTooltip())); } } else { // Draw Crafting Recipe for (int i = 0; i < craftingRecipe.Length; i++) { if (craftingRecipe[i] == null) { GUI.Button(craftingRects[i], ""); continue; } if (GUI.Button(craftingRects[i], new GUIContent(craftingRecipe[i].GetName(), craftingRecipe[i].GetTooltip()))) { Pickup(craftingRecipe[i]); craftingRecipe[i] = null; } } } /* * Craft Button */ if (CraftComplete()) { if (GUI.Button(cloneButtonRect, new GUIContent("Build", CraftPreviewString()))) { Pickup(towerInventory, new TowerItem(ComponentGenerator.Get().GenerateTurret(craftingRecipe))); craftingRecipe = new CraftableItem[CraftableItem.PART_MAX]; } } else { // GUI.enabled = false; if (GUI.Button(cloneButtonRect, new GUIContent("Build", CraftPreviewString()))) { } // GUI.enabled = true; } GUI.Label(tooltipRect, GUI.tooltip); GUI.skin = null; } }