private static void InitGameplayMode(ICharacter currentCharacter) { ClientCurrentCharacterContainersHelper.Init(currentCharacter); ClientItemsManager.Init(currentCharacter); ClientDroppedItemsNotifier.Init(currentCharacter); var layoutRootChildren = Api.Client.UI.LayoutRootChildren; layoutRootChildren.Add(new HUDLayoutControl()); layoutRootChildren.Add(new ChatPanel()); ClientContainersExchangeManager.Reset(); CraftingQueueControl.Instance?.Refresh(); var input = Api.Client.Scene.CreateSceneObject("Input components"); input.AddComponent <ClientComponentHotbarHelper>(); input.AddComponent <ClientComponentWindowStructureSelectListToogle>(); input.AddComponent <ClientComponentObjectInteractionHelper>(); // ReSharper disable once CanExtractXamlLocalizableStringCSharp gameplayInputContext = ClientInputContext .Start("Menu toggles") .HandleButtonDown( GameButton.InventoryMenu, () => { if (Menu.IsOpenedAny()) { // shortcut to close currently opened menus // (basically, it's alternative to pressing ESC in such case) Menu.CloseAll(); return; } Menu.Toggle <WindowInventory>(); }) .HandleButtonDown(GameButton.CraftingMenu, Menu.Toggle <WindowHandCrafting>) .HandleButtonDown(GameButton.MapMenu, Menu.Toggle <WindowWorldMap>) .HandleButtonDown(GameButton.SkillsMenu, Menu.Toggle <WindowSkills>) .HandleButtonDown(GameButton.TechnologiesMenu, Menu.Toggle <WindowTechnologies>) .HandleButtonDown(GameButton.SocialMenu, Menu.Toggle <WindowSocial>) .HandleButtonDown(GameButton.PoliticsMenu, Menu.Toggle <WindowPolitics>) .HandleButtonDown(GameButton.QuestsMenu, Menu.Toggle <WindowQuests>) .HandleButtonDown(GameButton.CompletionistMenu, Menu.Toggle <WindowCompletionist>) .HandleButtonDown(GameButton.OpenChat, () => { if (WindowsManager.OpenedWindowsCount == 0) { ChatPanel.Instance.Open(); } }); sceneObjectInputComponents = input; ClientComponentWorldCameraZoomManager.Instance.ZoomBounds = ZoomBoundsGameplayMode; }
public ViewModelWindowGeneratorBio( IStaticWorldObject objectGenerator, ObjectGeneratorBioPrivateState privateState) { this.objectGenerator = objectGenerator; this.protoGenerator = (ProtoObjectGeneratorBio)objectGenerator.ProtoGameObject; this.privateState = privateState; this.privateState.ClientSubscribe( _ => _.OrganicAmount, _ => this.NotifyPropertyChanged(nameof(this.OrganicAmount)), this); var character = ClientCurrentCharacterHelper.Character; ClientContainersExchangeManager.Register( this, this.InputItemsContainer, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); this.Refresh(); }
private static void Reset() { if (!isInitialized) { return; } isInitialized = false; Menu.CloseAll(); ClientComponentObjectPlacementHelper.DestroyInstanceIfExist(); if (HUDLayoutControl.Instance is not null) { Api.Client.UI.LayoutRootChildren.Remove(HUDLayoutControl.Instance); } if (ChatPanel.Instance is not null) { Api.Client.UI.LayoutRootChildren.Remove(ChatPanel.Instance); } ResetCallback?.Invoke(); ClientContainersExchangeManager.Reset(); ClientCurrentCharacterContainersHelper.Reset(); sceneObjectInputComponents?.Destroy(); sceneObjectInputComponents = null; gameplayInputContext?.Stop(); gameplayInputContext = null; }
public ViewModelItemsContainerExchange(IItemsContainer container, Action callbackTakeAllItemsSuccess) { this.callbackTakeAllItemsSuccess = callbackTakeAllItemsSuccess; this.Container = (IClientItemsContainer)container; var character = ClientCurrentCharacterHelper.Character; ClientContainersExchangeManager.Register( this, this.Container, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); ClientContainersExchangeManager.Register( this, character.SharedGetPlayerContainerHotbar(), allowedTargets: new[] { this.Container }); ClientContainersExchangeManager.Register( this, character.SharedGetPlayerContainerInventory(), allowedTargets: new[] { this.Container }); // ReSharper disable once CanExtractXamlLocalizableStringCSharp this.inputListener = ClientInputContext .Start("Container exchange") .HandleButtonDown(GameButton.ContainerTakeAll, this.ExecuteCommandTakeAll) .HandleButtonDown(GameButton.ContainerMoveItemsMatchDown, this.ExecuteCommandMatchDown) .HandleButtonDown(GameButton.ContainerMoveItemsMatchUp, this.ExecuteCommandMatchUp); }
public ViewModelFuelBurningState( FuelBurningState fuelBurningState) { this.FuelBurningState = fuelBurningState; this.ContainerFuel = (IClientItemsContainer)fuelBurningState?.ContainerFuel; this.FuelBurningState.ClientSubscribe( _ => _.FuelUseTimeRemainsSeconds, secondsToBurn => this.RefreshFuelUsage(), this); this.FuelBurningState.ClientSubscribe( _ => _.CurrentFuelItemType, newFuelItemType => this.RefreshFuelUsage(), this); this.RefreshFuelUsage(); var character = ClientCurrentCharacterHelper.Character; ClientContainersExchangeManager.Register(this, this.ContainerFuel, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); }
public ViewModelWindowStorageFridgeContainer(IItem itemStorage) : base(itemStorage) { this.privateState = itemStorage.GetPrivateState <ItemStorageFridgePrivateState>(); this.publicState = itemStorage.GetPublicState <ItemStorageFridgePublicState>(); var currentCharacter = Api.Client.Characters.CurrentPlayerCharacter; ClientContainersExchangeManager.Register( this, this.ItemsEnergyContainer, allowedTargets: new[] { currentCharacter.SharedGetPlayerContainerInventory(), currentCharacter.SharedGetPlayerContainerHotbar() }); this.isOn = this.publicState.IsOn; this.publicState.ClientSubscribe( _ => _.IsOn, _ => { this.isOn = this.publicState.IsOn; this.NotifyPropertyChanged("IsOn"); this.NotifyPropertyChanged("IsOff"); }, this); }
public ViewModelWindowCraftingStation( IReadOnlyCollection <Recipe> availableRecipes, int recipesCountTotal) { var currentCharacter = Api.Client.Characters.CurrentPlayerCharacter; this.ContainerInventory = (IClientItemsContainer)currentCharacter.SharedGetPlayerContainerInventory(); this.ViewModelCraftingMenu = new ViewModelCraftingMenu(availableRecipes, recipesCountTotal, validateItemsAvailabilityInPlayerInventory: true); this.ViewModelCraftingMenu.TrySelectRecipe(lastSelectedRecipe); ClientContainersExchangeManager.Register(this, this.ContainerInventory); ClientContainersExchangeManager.Register(this, currentCharacter.SharedGetPlayerContainerHotbar()); }
public ViewModelWindowObjectLight( IStaticWorldObject worldObject, ObjectLightPrivateState privateState, ObjectLightPublicState publicState) { this.worldObject = worldObject; this.protoObjectLight = (IProtoObjectLight)worldObject.ProtoStaticWorldObject; this.FuelCapacity = this.protoObjectLight.FuelCapacity; this.privateState = privateState; this.publicState = publicState; this.ContainerInput = (IClientItemsContainer)privateState.ContainerInput; var character = ClientCurrentCharacterHelper.Character; ClientContainersExchangeManager.Register(this, this.ContainerInput, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); var(icon, color) = this.protoObjectLight.FuelItemsContainerPrototype.ClientGetFuelIconAndColor(); this.FuelIcon = Client.UI.GetTextureBrush(icon); this.FuelColor = color; this.privateState.ClientSubscribe( _ => _.FuelAmount, _ => this.RefreshFuelAmount(), this); this.privateState.ClientSubscribe( _ => _.Mode, _ => this.RefreshMode(), this); publicState.ClientSubscribe( _ => _.IsLightActive, _ => this.RefreshIsLightActive(), this); this.RefreshFuelAmount(); this.RefreshMode(); this.RefreshIsLightActive(); }
protected sealed override void OnDispose() { this.ReleaseSubscriptions(); ClientContainersExchangeManager.Unregister(this); try { this.DisposeViewModel(); } finally { // please note - this is too dangerous as this way we can dispose something we don't want to dispose automatically! if (this.isAutoDisposeFields) { this.DisposeDisposableFields(); } } }
public ViewModelWindowTinkerTable( IStaticWorldObject tinkerTableObject, ObjectTinkerTable.PrivateState privateState) { this.tinkerTableObject = tinkerTableObject; this.containerInput = (IClientItemsContainer)privateState.ContainerInput; this.containerInput.ItemAdded += this.AnyContainerItemAddedHandler; this.containerInput.ItemRemoved += this.AnyContainerItemRemovedHandler; this.containerInput.ItemsReset += this.AnyContainerResetHandler; this.containerOutput = (IClientItemsContainer)privateState.ContainerOutput; this.containerOutput.ItemAdded += this.AnyContainerItemAddedHandler; this.containerOutput.ItemRemoved += this.AnyContainerItemRemovedHandler; this.containerOutput.ItemsReset += this.AnyContainerResetHandler; ClientComponentSkillsWatcher.SkillLevelChanged += this.CharacterSkillLevelChangedHandler; ClientCurrentCharacterFinalStatsHelper.FinalStatsCacheChanged += this.Refresh; // register containers exchange var character = ClientCurrentCharacterHelper.Character; ClientContainersExchangeManager.Register( this, this.containerOutput, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); ClientContainersExchangeManager.Register( this, this.containerInput, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); this.Refresh(); }
protected override void DisposeViewModel() { base.DisposeViewModel(); ClientContainersExchangeManager.Unregister(this); }
public ViewModelManufacturingState( IStaticWorldObject worldObjectManufacturer, ManufacturingState manufacturingState, ManufacturingConfig manufacturingConfig) { this.worldObjectManufacturer = worldObjectManufacturer; this.ManufacturingState = manufacturingState; this.ManufacturingConfig = manufacturingConfig; this.ContainerInput = (IClientItemsContainer)manufacturingState.ContainerInput; this.ContainerOutput = (IClientItemsContainer)manufacturingState.ContainerOutput; this.CommandBrowseRecipes = new ActionCommand(this.ExecuteCommandBrowseRecipes); this.CommandCloseRecipesBrowser = new ActionCommand(this.CloseRecipesBrowser); this.CommandSelectRecipeFromBrowser = new ActionCommandWithParameter(this.ExecuteCommandSelectRecipeFromBrowser); this.CommandApplyBestMatchingRecipe = new ActionCommand(this.ExecuteCommandApplyBestMatchingRecipe); this.VisibilityRecipesSelection = manufacturingConfig.IsAutoSelectRecipe ? Visibility.Collapsed : Visibility.Visible; this.SelectedRecipe = manufacturingState.SelectedRecipe; //this.BestMatchingRecipe = manufacturingState.BestMatchingRecipe; this.RefreshCraftingProgressPercents(); this.ManufacturingState.ClientSubscribe( _ => _.SelectedRecipe, recipe => this.SelectedRecipe = recipe, this); //this.ManufacturingState.ClientSubscribe( // _ => _.BestMatchingRecipe, // recipe => this.BestMatchingRecipe = recipe, // this); this.ManufacturingState.CraftingQueue.ClientSubscribe( _ => _.IsContainerOutputFull, _ => this.NotifyPropertyChanged(nameof(this.IsContainerOutputFull)), this); this.craftingQueue = this.ManufacturingState.CraftingQueue.QueueItems; this.craftingQueue.ClientAnyModification += this.CraftingQueueAnyModificationHandler; this.ManufacturingState.CraftingQueue.ClientSubscribe( _ => _.TimeRemainsToComplete, time => this.RefreshCraftingProgressPercents(), this); // register containers exchange var character = Client.Characters.CurrentPlayerCharacter; ClientContainersExchangeManager.Register( this, this.ManufacturingState.ContainerOutput, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); ClientContainersExchangeManager.Register( this, this.ManufacturingState.ContainerInput, allowedTargets: new[] { character.SharedGetPlayerContainerInventory(), character.SharedGetPlayerContainerHotbar() }); this.ContainerInput.StateHashChanged += this.ContainerInputStateChangedHandler; this.RefreshIsInputMatchSelectedRecipe(); this.RefreshBestMatchingRecipe(); }