Esempio n. 1
0
        public ViewModelWindowInventory(FrameworkElement controlSkeletonView = null)
        {
            if (IsDesignTime)
            {
                return;
            }

            this.character          = ClientCurrentCharacterHelper.Character;
            this.ContainerInventory = (IClientItemsContainer)this.character.SharedGetPlayerContainerInventory();
            this.ContainerEquipment = (IClientItemsContainer)this.character.SharedGetPlayerContainerEquipment();
            this.containerHand      = (IClientItemsContainer)this.character.SharedGetPlayerContainerHand();

            this.InventorySkeleton.CurrentCharacter = this.character;
            this.InventorySkeleton.Control          = controlSkeletonView;

            this.DefenseStats.CurrentCharacter = this.character;

            var publicState = ClientCurrentCharacterHelper.PublicState;

            this.isHeadEquipmentDisplayed = publicState.IsHeadEquipmentHiddenForSelfAndPartyMembers;

            var privateState = ClientCurrentCharacterHelper.PrivateState;

            this.protoOrigin = privateState.Origin;

            privateState.ClientSubscribe(
                _ => _.Origin,
                _ =>
            {
                this.protoOrigin = privateState.Origin;
                this.NotifyPropertyChanged(nameof(this.OriginTitle));
                this.NotifyPropertyChanged(nameof(this.OriginDescription));
                this.NotifyPropertyChanged(nameof(this.OriginIcon));
                this.NotifyPropertyChanged(nameof(this.OriginStatsDictionary));
            },
                this);
        }
        private static void SortItems(IClientItemsContainer container)
        {
            ConsolidateItemStacks(container);

            Api.Logger.Important("Sorting items in " + container);
            var allItems = container.Items.ToList();

            var sorted = allItems.OrderBy(item => GetProtoItemSortIndex(item.ProtoItem))
                         .ThenBy(item => item.ProtoItem.Id)
                         .ThenByDescending(item =>
            {
                if (item.ProtoItem is IProtoItemWithDurablity)
                {
                    return(item
                           .GetPrivateState <IItemWithDurabilityPrivateState>()
                           .DurabilityCurrent);
                }

                if (item.ProtoItem.IsStackable)
                {
                    return(item.Count);
                }

                return(0);
            })
                         .ToList();

            //Api.Logger.WriteDev("Sorted:"
            //                    + Environment.NewLine
            //                    + sorted.GetJoinedString(Environment.NewLine));

            Api.Client.Items.ReorderItems(container, sorted);

            Api.Client.Audio.PlayOneShot(SortContainerSoundResource);

            RequirementSortItemsContainer.Helper.ClientOnItemsContainerSorted();
        }
        public ViewModelWindowObjectVehicle(
            IDynamicWorldObject vehicle,
            FrameworkElement vehicleExtraControl,
            IViewModelWithActiveState vehicleExtraControlViewModel)
        {
            this.VehicleExtraControl          = vehicleExtraControl;
            this.VehicleExtraControlViewModel = vehicleExtraControlViewModel;
            if (vehicleExtraControl != null)
            {
                vehicleExtraControl.DataContext = vehicleExtraControlViewModel;
            }

            var currentCharacter = Api.Client.Characters.CurrentPlayerCharacter;

            this.ContainerPlayerInventory = (IClientItemsContainer)currentCharacter.SharedGetPlayerContainerInventory();

            this.ProtoVehicle        = (IProtoVehicle)vehicle.ProtoGameObject;
            this.vehiclePublicState  = vehicle.GetPublicState <VehiclePublicState>();
            this.vehiclePrivateState = vehicle.GetPrivateState <VehiclePrivateState>();

            var structurePointsMax = this.ProtoVehicle.SharedGetStructurePointsMax(vehicle);

            this.ViewModelStructurePoints = new ViewModelStructurePointsBarControl()
            {
                ObjectStructurePointsData = new ObjectStructurePointsData(vehicle, structurePointsMax)
            };

            this.ViewModelVehicleEnergy = new ViewModelVehicleEnergy(vehicle);

            this.cargoItemsContainer             = this.vehiclePrivateState.CargoItemsContainer as IClientItemsContainer;
            this.ViewModelItemsContainerExchange = new ViewModelItemsContainerExchange(this.cargoItemsContainer,
                                                                                       callbackTakeAllItemsSuccess:
                                                                                       null)
            {
                IsContainerTitleVisible = false
            };

            this.ViewModelItemsContainerExchange.IsActive = false;

            var isOwner = WorldObjectOwnersSystem.SharedIsOwner(
                ClientCurrentCharacterHelper.Character,
                vehicle);

            this.ViewModelOwnersEditor =
                new ViewModelWorldObjectOwnersEditor(this.vehiclePrivateState.Owners,
                                                     canEditOwners: isOwner ||
                                                     CreativeModeSystem.ClientIsInCreativeMode(),
                                                     callbackServerSetOwnersList:
                                                     ownersList => WorldObjectOwnersSystem.ClientSetOwners(
                                                         vehicle,
                                                         ownersList),
                                                     title: CoreStrings.ObjectOwnersList_Title2);

            this.RefreshCanRepair();

            this.IsVehicleTabActive = true;
            this.ViewModelItemsContainerExchange.IsActive = true;

            if (this.cargoItemsContainer != null)
            {
                this.cargoItemsContainer.ItemAdded        += this.CargoItemsContainerItemAddedHandler;
                this.cargoItemsContainer.ItemCountChanged += this.CargoItemsContainerItemCountChangedHandler;
            }
        }
 public bool IsAllowed(IClientItemsContainer clientItemsContainer)
 {
     return(this.allowedTargetContainers.Contains(clientItemsContainer));
 }
 public WrappedContainer(IClientItemsContainer container)
 {
     this.Container = container;
 }