private void ExecuteCommandOpenCrateIconSelectorWindow() { var protoObjectCrate = (IProtoObjectCrate)this.worldObjectCrate.ProtoGameObject; // use the item in hand as an icon source (could be null) var protoItemInHand = ClientItemsManager.ItemInHand?.ProtoItem; protoObjectCrate.ClientSetIconSource(this.worldObjectCrate, protoItemInHand); return; // the old mechanic is no longer used var existingItems = this.worldObjectCrate.GetPrivateState <ObjectCratePrivateState>().ItemsContainer.Items .ToList(); var window = new WindowCrateIconSelector(this.publicState.IconSource, existingItems); window.EventWindowClosing += WindowClosingHandler; Api.Client.UI.LayoutRootChildren.Add(window); void WindowClosingHandler() { window.EventWindowClosing -= WindowClosingHandler; if (window.DialogResult != DialogResult.OK) { return; } var selectedIconSource = window.ViewModel.SelectedProtoEntity; var protoObjectCrate = (IProtoObjectCrate)this.worldObjectCrate.ProtoGameObject; protoObjectCrate.ClientSetIconSource(this.worldObjectCrate, selectedIconSource); } }
protected override void DisposeViewModel() { WindowCrateIconSelector.CloseWindowIfOpened(); base.DisposeViewModel(); }