public void OnRemoveListViewItem(object sender, DecorationPocketEventArgs e) { if (e.Index == selectedIndex) { selectedDecoration = null; selectedIndex = -1; } pocket.ListViewItems.RemoveAt(e.Index); UpdateDetails(); }
public void OnUpdateListViewItem(object sender, DecorationPocketEventArgs e) { ((Image)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[0]).Source = ItemDatabase.GetDecorationImageFromID(e.Decoration.ID); ((TextBlock)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[1]).Text = ItemDatabase.GetDecorationFromID(e.Decoration.ID).Name; DecorationUsages usage = pocket.Inventory.GetDecorationUsage(e.Index, pocket.PocketType); if (usage == DecorationUsages.SecretBase) { ((Image)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[2]).Source = ResourceDatabase.GetImageFromName("DecorationSecretBase"); } else if (usage == DecorationUsages.Bedroom) { ((Image)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[2]).Source = ResourceDatabase.GetImageFromName("DecorationBedroom"); } else { ((Image)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[2]).Source = null; } ((TextBlock)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[4]).Text = e.Decoration.Count.ToString(); int usageCount = pocket.Inventory.GetNumDecorationsWithIDInUse(e.Decoration.ID); ((TextBlock)((DockPanel)pocket.ListViewItems[e.Index].Content).Children[3]).Text = (usageCount > 0 && pocket.MaxStackSize == 0 ? usageCount.ToString() : ""); pocket.ListViewItems[e.Index].Tag = e.Decoration; }
public void OnAddListViewItem(object sender, DecorationPocketEventArgs e) { ListViewItem listViewItem = new ListViewItem(); listViewItem.SnapsToDevicePixels = true; listViewItem.UseLayoutRounding = true; DockPanel dockPanel = new DockPanel(); dockPanel.Width = 300; Image image = new Image(); image.Source = ItemDatabase.GetDecorationImageFromID(e.Decoration.ID); image.Stretch = Stretch.None; image.SnapsToDevicePixels = true; image.UseLayoutRounding = true; TextBlock itemName = new TextBlock(); itemName.VerticalAlignment = VerticalAlignment.Center; itemName.Text = ItemDatabase.GetDecorationFromID(e.Decoration.ID).Name; itemName.TextTrimming = TextTrimming.CharacterEllipsis; itemName.Margin = new Thickness(4, 0, 0, 0); Image usedImage = new Image(); usedImage.Stretch = Stretch.None; usedImage.SnapsToDevicePixels = true; usedImage.UseLayoutRounding = true; usedImage.HorizontalAlignment = HorizontalAlignment.Left; usedImage.Margin = new Thickness(6, 0, 0, 0); DecorationUsages usage = pocket.Inventory.GetDecorationUsage(e.Index, pocket.PocketType); if (usage == DecorationUsages.SecretBase) { usedImage.Source = ResourceDatabase.GetImageFromName("DecorationSecretBase"); } else if (usage == DecorationUsages.Bedroom) { usedImage.Source = ResourceDatabase.GetImageFromName("DecorationBedroom"); } TextBlock usedCount = new TextBlock(); usedCount.VerticalAlignment = VerticalAlignment.Center; usedCount.Margin = new Thickness(4, 0, 0, 0); int usageCount = pocket.Inventory.GetNumDecorationsWithIDInUse(e.Decoration.ID); usedCount.Text = (usageCount > 0 && pocket.MaxStackSize == 0 ? usageCount.ToString() : ""); TextBlock itemX = new TextBlock(); itemX.VerticalAlignment = VerticalAlignment.Center; itemX.HorizontalAlignment = HorizontalAlignment.Right; itemX.TextAlignment = TextAlignment.Right; itemX.Text = "x"; itemX.Width = Double.NaN; itemX.MinWidth = 10; TextBlock itemCount = new TextBlock(); itemCount.VerticalAlignment = VerticalAlignment.Center; itemCount.HorizontalAlignment = HorizontalAlignment.Right; itemCount.TextAlignment = TextAlignment.Right; itemCount.Width = 30; itemCount.Text = e.Decoration.Count.ToString(); listViewItem.Content = dockPanel; pocket.ListViewItems.Insert(e.Index, listViewItem); dockPanel.Children.Add(image); dockPanel.Children.Add(itemName); dockPanel.Children.Add(usedImage); dockPanel.Children.Add(usedCount); dockPanel.Children.Add(itemCount); dockPanel.Children.Add(itemX); if (pocket.MaxStackSize != 0) { itemCount.Visibility = Visibility.Hidden; itemX.Visibility = Visibility.Hidden; } else { usedCount.Visibility = Visibility.Hidden; } listViewItem.ContextMenuOpening += OnContextMenuOpening; listViewItem.ContextMenu = contextMenu; DockPanel.SetDock(image, Dock.Left); DockPanel.SetDock(itemCount, Dock.Right); listViewItem.Tag = e.Decoration; UpdateDetails(); }