void RefreshUIBox() { _queueRefresh = false; UIElements.Clear(); int cursor = 0; _weaponBoxes = new List <UI_WeaponEquipBox>(); int _index = 0; foreach (Weapon w in A3RData.SelectedPlayer.Character.WeaponList) { UI_WeaponEquipBox _weaponBox = new UI_WeaponEquipBox(Camera, A3RData, new Vector(Pos.X + 20, Pos.Y + cursor * (50 + 15) + 20), OnInventoryEvent); _weaponBox.HeldWeapon = w; _weaponBox.IsActive = true; _weaponBox.IsInventory = false; _weaponBox.WeaponIndex = _index; cursor++; _weaponBoxes.Add(_weaponBox); AddElement(_weaponBox); _index++; } AddElement(new UI_Line(Camera, new Vector(Pos.X + 20, Pos.Y + cursor * 65 + 20), new Vector(Pos.X + _width - 20, Pos.Y + cursor * 65 + 20))); AddElement(new UI_Text(Camera, Pos.X + 30, Pos.Y + cursor * 65 + 35, Color.White, SwinGame.FontNamed("winnerFont"), "Inventory")); cursor++; _index = 0; foreach (Weapon w in A3RData.SelectedPlayer.Character.Inventory) { UI_WeaponEquipBox _weaponBox = new UI_WeaponEquipBox(Camera, A3RData, new Vector(Pos.X + 20, Pos.Y + cursor * (50 + 15) + 20), OnInventoryEvent); _weaponBox.HeldWeapon = w; _weaponBox.IsActive = false; _weaponBox.IsInventory = true; _weaponBox.WeaponIndex = _index; cursor++; _weaponBoxes.Add(_weaponBox); AddElement(_weaponBox); _index++; } cursor++; UI_WeaponEquipBox _sellBox = new UI_WeaponEquipBox(Camera, A3RData, new Vector(Pos.X + 20, Pos.Y + cursor * (50 + 15) + 20), OnInventoryEvent); _sellBox.WeaponIndex = -1; _sellBox.IsSellBox = true; AddElement(_sellBox); }
public void OnInventoryEvent(UI_WeaponEquipBox sender) { if (sender.MoveSelected) { if (_selectedBoxes == 0) { _firstIndex = sender; } if (_selectedBoxes == 1) { _secondIndex = sender; } _selectedBoxes++; } else { _selectedBoxes--; if (_selectedBoxes == 0) { _firstIndex = null; } } Console.WriteLine("Boxes selected: " + _selectedBoxes); if (_selectedBoxes > 1) { SwinGame.PlaySoundEffect(SwinGame.SoundEffectNamed("mechConfirm")); Weapon temp; if (_firstIndex.IsSellBox || _secondIndex.IsSellBox) { if (_firstIndex.IsSellBox) { //first selected is sell box if (_secondIndex.IsInventory) { A3RData.SelectedPlayer.Money += (int)(A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex].Cost * 0.7f); A3RData.ShopWeapons.Add(A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex]); A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex] = null; _onPlayerSell?.Invoke(); } else { A3RData.SelectedPlayer.Money += (int)(A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex].Cost * 0.7f); A3RData.ShopWeapons.Add(A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex]); A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex] = null; _onPlayerSell?.Invoke(); } } else { if (_firstIndex.IsInventory) { //second selected is sell box A3RData.SelectedPlayer.Money += (int)(A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex].Cost * 0.7f); A3RData.ShopWeapons.Add(A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex]); A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex] = null; _onPlayerSell?.Invoke(); } else { //second selected is sell box A3RData.SelectedPlayer.Money += (int)(A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex].Cost * 0.7f); A3RData.ShopWeapons.Add(A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex]); A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex] = null; _onPlayerSell?.Invoke(); } } } else { if (_firstIndex.IsInventory) { if (_secondIndex.IsInventory) { //inventory to inventory temp = A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex] = A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex] = temp; } else { //inventory to weapon temp = A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.Inventory[_firstIndex.WeaponIndex] = A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex] = temp; } } else { if (_secondIndex.IsInventory) { //weapon to inventory temp = A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex] = A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.Inventory[_secondIndex.WeaponIndex] = temp; } else { //weapon to weapon temp = A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.WeaponList[_firstIndex.WeaponIndex] = A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex]; A3RData.SelectedPlayer.Character.WeaponList[_secondIndex.WeaponIndex] = temp; } } } Console.WriteLine("Clearing boxes"); DeselectAllBoxes(); _selectedBoxes = 0; RefreshEquipBox(); } }