Esempio n. 1
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("CleanupCellPhones");

            int removed = 0;

            foreach (Sim sim in LotManager.Actors)
            {
                PhoneCell truePhone = null;

                List <PhoneCell> remove = new List <PhoneCell>();
                foreach (PhoneCell phone in Inventories.InventoryDuoFindAll <PhoneCell, Phone>(sim.SimDescription))
                {
                    if (truePhone == null)
                    {
                        truePhone = phone;
                    }
                    else
                    {
                        remove.Add(phone);
                    }
                }

                foreach (PhoneCell phone in remove)
                {
                    try
                    {
                        phone.Dispose();
                        phone.Destroy();
                        removed++;
                    }
                    catch
                    { }
                }
            }

            if (removed > 0)
            {
                Overwatch.Log("Duplicate Phones Removed: " + removed);
            }
        }
Esempio n. 2
0
        private void CurrentViewModel_PhonePlusMinusClicked(object sender, KeyValuePair <object, bool> e)
        {
            var senderVm = (PhoneViewModel)e.Key;

            if (e.Value) //Добавление
            {
                if (PhoneStack.Children.Count < 5 && CurrentViewModel.PhoneViewModels.All(item => !string.IsNullOrEmpty(item.Phone.Number)))
                {
                    var newPhoneVm = new PhoneViewModel(new Phone());
                    newPhoneVm.PlusMinusClicked += CurrentViewModel.Phone_PlusMinusClicked;
                    CurrentViewModel.PhoneViewModels.Add(newPhoneVm);
                    var phoneCellView = new PhoneCell
                    {
                        BindingContext = newPhoneVm
                    };
                    PhoneStack.Children.Add(phoneCellView);
                }
            }
            else //Удаление
            {
                var todelete = PhoneStack.Children.FirstOrDefault(item => item.BindingContext == e.Key);
                if (todelete == null)
                {
                    return;
                }
                try
                {
                    var result = PhoneStack.Children.Remove(todelete);
                    if (result)
                    {
                        CurrentViewModel.PhoneViewModels.Remove(senderVm);
                    }
                }
                catch (Exception ex)
                {
                    // ignored
                }
            }
        }